Buongiorno,

ho un problema con un programma Java che mi sta facendo disperare. Ho bisogno di visualizzare su schermo i dati che invio attraverso una porta seriale, accumulando quello che scrivo in COM1 (per esempio) fino a che non dò un segnale di invio. Per adesso, sono riuscito a fare questo programma:


codice:
import java.io.*;
import java.util.*;
import gnu.io.*;


public class Lettura 
{
    static CommPortIdentifier id_porta;
    static Enumeration	      lista_porte;
    InputStream		      ingresso;               // 10
    SerialPort		      porta_seriale;
    Thread		      readThread;
    BufferedReader            is;
    String                    risposta;  

    public static void main(String[] args) 
    {
       boolean		      porta_trovata = false;
       String		      porta_default = "COM1";
                                                             // 20
 	if (args.length > 0) {
	    porta_default = args[0];
	} 
   
	lista_porte = CommPortIdentifier.getPortIdentifiers();

	while (lista_porte.hasMoreElements()) 
        {
	    id_porta = (CommPortIdentifier) lista_porte.nextElement();
	    if (id_porta.getPortType() == CommPortIdentifier.PORT_SERIAL)      // 30
            {
		if (id_porta.getName().equals(porta_default)) 
                {
		    System.out.println("Porta trovata: "+porta_default);
		    porta_trovata = true;
                    System.out.println("Nuovo elemento Lettura"); 
		    Lettura reader = new Lettura();                        // 37
		} 
	    } 
	}                                                                  // 40
	if (!porta_trovata) {
	    System.out.println("Porta " + porta_default + " non trovata.");
            System.exit(0);
	} 
 	
    }

    public Lettura()
    {
       try                                                   // 50
       {
          porta_seriale = (SerialPort) id_porta.open("LetturaApp",200);
          System.out.println("Porta seriale aperta.");
       }
       catch (PortInUseException pe) {}

       try
       {
          is = new BufferedReader(new InputStreamReader(porta_seriale.getInputStream()));
          System.out.println("Nuovo elemento BufferedReader.");                 // 60
       }
       catch (IOException ioe) {}

       porta_seriale.notifyOnDataAvailable(true);
       System.out.println("Dati disponibili per porta seriale.");
 
       try
       {
          porta_seriale.setSerialPortParams(115200, SerialPort.DATABITS_8,
                                            SerialPort.STOPBITS_1,              // 70
                                            SerialPort.PARITY_NONE);
          System.out.println("Porta seriale configurata.");
       }
       catch (UnsupportedCommOperationException ue) {}

       
    
       try 
       {
          String linea = "";
	  while ((linea = is.readLine()) != null) 
           {
              risposta = linea;          
           } 

           System.out.print(" " + risposta);
       } 
       catch (IOException e) {}
       

       System.exit(0); 

    }

    
}
Ma ogni volta che cerco di lanciarlo, mi spampa le stringhe di controllo... e poi finisce subito. Come devo fare per fargli attendere di aver inserito i dati, e poi stamparli quando premo Invio?

Per favore, aiutatemi. Non so più che pesci pigliare, ed è una cosa estremamente importante.

Grazie mille