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){

}

}

[2449 byte] By [musiigea] at [2007-11-27 10:49:00]
# 1

so you see from this: System.out.print(data);

but not from this: parent.setData(data);

So are we supposed to guess what parent.setData(data); does?

bsampieria at 2007-7-29 11:16:24 > top of Java-index,Desktop,Core GUI APIs...
# 2

I stated clear in my question that parent.setData(data);

sends data to the GUI

musiigea at 2007-7-29 11:16:24 > top of Java-index,Desktop,Core GUI APIs...
# 3

> I stated clear in my question that

> parent.setData(data);

sends data to the

> GUI

Yes, and that means nothing considering you also said:

> My problem is that the byte sent back is shown in the compiler

> but not in the GUI.

So you don't think that maybe this parent.setData() method doesn't have some problem? Cuz if you see something print out via System.out right before that is called, then there must be the same data being passed to setData().

bsampieria at 2007-7-29 11:16:24 > top of Java-index,Desktop,Core GUI APIs...
# 4

You do realize, also, that you are only reading 1 byte whenever a "data available" event occurs (InputStream.read() will not make your byte buffer bigger). I believe you should be reading as many bytes as available.

Very possibly, your issue has to do with threading and updating a Swing UI in the same thread, which is not good.

There are lots of info on Swing and Threads in the Java Tutorials on this site.

bsampieria at 2007-7-29 11:16:24 > top of Java-index,Desktop,Core GUI APIs...
# 5

Am sure that am reading enough bytes because the micro pc that sends the bytes sends a byte at a time

musiigea at 2007-7-29 11:16:24 > top of Java-index,Desktop,Core GUI APIs...