GUI
Hey guys
I have the method below that reads from the serial port when ever there is a serial port event. I also have another method that just writes to the serial port. In the code below, the 2 lines System.out.print(data)
and parent.setData(data)
marked by +++++ and *****,System.out.print(data)prints the data read from the serial port to my compiler andparent.setData(data)sends it to my GUI.
When I send a byte to the micro processor via the serial port, the micro processor sends it back to the serial port. My problem is that the byte sent back is shown in the compiler but not in the GUI. The GUI shows the bytes sent back to the serial port after all the bytes to be sent are sent.
I hope that U can understand my problem and help me with what goes wrong?
publicvoid serialEvent(SerialPortEvent event){
switch(event.getEventType()){
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
break;
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer =newbyte[1];
try{
while (inputStream.available() > 0){
int numBytes = inputStream.read(readBuffer);
data =new String(readBuffer);
System.out.print(data);//+++++
parent.setData(data);//*****
nothing(numBytes);
}
}catch (IOException e){
e.printStackTrace();
}
break;
}
try{
inputStream.close();
}catch (IOException e){
}
}

