Salve, ho un problema: devo implementare una funzione per la lettura da porta seriale. Girovagando per la rete ho trovato una guida e da essa ho preso spunto per implementare la mia funzione:
static void lettura(String port)
{
try
{
CommPortIdentifier id_porta= CommPortIdentifier.getPortIdentifier(port);
CommPort porta=id_porta.open("LeggiSuSeriale",200);
SerialPort porta_seriale=(SerialPort)porta;
porta_seriale.setSerialPortParams(19200,SerialPort .DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARIT Y_NONE);
BufferedReader is = null;
String temp=null;
try
{
is = new BufferedReader(new InputStreamReader(porta.getInputStream()));
temp=is.readLine();
System.out.println("Ho letto dalla periferica: "+temp);
}
catch (IOException e)
{
System.err.println("Can't open input stream: write-only");
is = null;
}
if (is != null) is.close();
if (porta != null) porta.close();
}
catch(Exception e)
{
System.out.println("Errore durante la comunicazione con la porta: "+e);
}
}
public static void main(String[] args)
{
lettura("COM2");
}
di compilare compila, il problema è che quando va in esecuzione entra nel catch "Can't open input stream: write-only"...
Che vuol dire? e soprattutto dove sto sbagliando? grazie ^^.
Attendo una vostra risp, spero al + presto..grazie.
Ciao