Fonction de retour String.

Akrouti Ezzeddin Messages postés 63 Statut Membre -  
 Utilisateur anonyme -
Bonjour,
Voila une fonction de type de retour String mais elle n'affiche rien, et ça me complique ça fait une heure. Quelqu'un me dit ou est l'erreur?

package client;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Enumeration;
import javax.comm.*;
public class Commande 
{
		/**
		 * @param args
		 * @throws NoSuchPortException
		 * @throws PortInUseException
		 * @throws IOException
		 * @throws UnsupportedCommOperationException
		 * @throws UnsupportedEncodingException
		 * @throws InterruptedException
		 */
	public String executerAT(String cmd) throws UnsupportedCommOperationException, UnsupportedEncodingException, IOException ,PortInUseException
	{
			Enumeration<CommPortIdentifier> enumP = CommPortIdentifier.getPortIdentifiers();
			BufferedReader serial_in=null;
			PrintStream serial_out=null;
			String msg="";
				try
				{
				CommPortIdentifier tmp = enumP.nextElement();
				System.out.println(tmp.getName());
				SerialPort serial = (SerialPort) tmp.open("Me",2000);
				serial.setSerialPortParams(460800, SerialPort.DATABITS_8,SerialPort.STOPBITS_1,  SerialPort.PARITY_NONE);
				serial_in=new BufferedReader(new InputStreamReader(serial.getInputStream()));
				serial_out=new PrintStream(serial.getOutputStream(),true,"ISO-8859-1");
				serial_out.print(cmd);
				serial_out.print("\r");
				msg=msg+serial_in.readLine()+"\n";
				msg=msg+serial_in.readLine()+"\n";
				msg=msg+serial_in.readLine()+"\n";
				}catch(PortInUseException e)
				{
				e.printStackTrace();
				System.exit(0);
				}
			return msg;
		}
	public static void main(String[] args) throws NoSuchPortException, PortInUseException, IOException, UnsupportedCommOperationException, InterruptedException
	{
		Commande t=new Commande();
		t.executerAT("AT");
	}
	}


Merci d'avance.

2 réponses

Akrouti Ezzeddin Messages postés 63 Statut Membre
 
ooooooooooh mes amis je suis besoin de vos idées.
0
Utilisateur anonyme
 
Salut,

La méthode executerAT("...")
retourne msg mais tu ne l'exploites pas

Modifie ta méthode main(...
      { 
         Commande t=new Commande(); 
         String msgRetour = t.executerAT("AT"); 
         System.out.println("msg: " + msgRetour); 
      }


pour savoir s'il y a un retour effectif...

Cordialement,

Dan
Plus on apprend... plus on se rend compte qu'on ne connaît pas grand-chose.
0