oggi ho avuto il tempo per scrivere una classe Java che è in grado di ricevere e spedire numeri al 16F628 , direi molto interessante se pendo che tale applicazione può funzionare anche in un'applicazione client - Server.. ecco la parte centrale del software:
try
{
portId=CommPortIdentifier.getPortIdentifier("COM1" );
serialPort=(SerialPort)portId.open("RS232",2000); // ogni due secondi controlla se ci sono errori nella trasmissione dei dati
serialPort.setFlowControlMode(SerialPort.FLOWCONTR OL_RTSCTS_IN); //Controllo dei segnali Request to send Clear to send
System.out.println("porta aperta");
outputStream=serialPort.getOutputStream();// si prende il canale di output allo stesso modo potrebbe prendere quello di input
outSer = new DataOutputStream(outputStream);
serialPort.addEventListener(this);
serialPort.notifyOnDataAvailable(true); // quando ci sono dati in arrivo
serialInput=serialPort.getInputStream();
serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
}
catch(Exception e)
{
System.out.println("ERRORE");
}
}
//__________________________________________________ ___________
public void actionPerformed(ActionEvent e)
{
String b;
int data_out = 0;
if(e.getSource() == ch) serialPort.close();
{
}
if (e.getSource() == a)
{
b = t.getText();
m.append(b);
m.append("\n");
data_out = Integer.parseInt(b);
try
{
outSer.writeByte(data_out);
outSer.flush();
}
catch(Exception ev)
{
System.out.println("ERRORE "+ev);
}
}
}
//__________________________________________________ ___________
public void serialEvent(SerialPortEvent event)
{
if(event.getEventType()== SerialPortEvent.DATA_AVAILABLE)
{
try
{
while(serialInput.available()>0)
{
B[0]=(char)serialInput.read();
String s=new String(

;
m.append(s);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}