CODE
case SerialPortEvent.DATA_AVAILABLE:
byte[] readBuffer = new byte[20];
try {
while (inputStream.available() > 0) {
int numBytes = inputStream.read(readBuffer);
}
System.out.print(new String(readBuffer));
txtOutput.append(new String(readBuffer));
} catch (IOException e) {}
You are trying to read 20 bytes even if there are only 5 bytes on the stream
your inputStream.read() will get stuck until effectively 20 bytes are available to read.
Even worst if 25 bytes are available... you will read the first 20 ones and then get stuck trying to read 20 other bytes
without having printing them (stuck in your while loop) and erasing in readBuffer the 20 last ones you have read
better to do it that way
CODE
case SerialPortEvent.DATA_AVAILABLE:
try {
int nb = inputStream.available();
while (nb > 0) {
byte[] readBuffer = new byte[nb];
inputStream.read(readBuffer);
String str = new String(readBuffer);
System.out.print(str);
txtOutput.append(str);
nb = inputStream.available();
}
} catch (IOException e) {}
By the way, why creating a Thread that does nothing ?
This post has been edited by pbl: 26 Jun, 2008 - 07:36 PM