javax.comm major confusion

I am testing out serial io (relatively new to java).

Here is my code, an eventhandler registered for a seriaPort.

When I revieve a byte, Entering switch gets displayed the incoming character

gets displayed, but Leaving Function never get displayed..

what is going on? I thought that the read was blocking? Am I re entering the function

on every key?

Is the available call blocking?

publicvoid serialEvent(SerialPortEvent event){

byte[] readBuffer =newbyte[20];

System.out.println("Entering Switch");

switch (event.getEventType()){

case SerialPortEvent.BI:

case SerialPortEvent.OE:

case SerialPortEvent.FE:

case SerialPortEvent.PE:

case SerialPortEvent.CD:

case SerialPortEvent.CTS:

case SerialPortEvent.DSR:

case SerialPortEvent.RI:

case SerialPortEvent.OUTPUT_BUFFER_EMPTY:

break;

case SerialPortEvent.DATA_AVAILABLE:

try{

while( inputStream.available() > 0){

int numBytes = inputStream.read(readBuffer);

System.out.print(new String(readBuffer));

outputStream.write(readBuffer);

}

}catch (IOException e){

}

break;

}

System.out.println("Leaving Function");

Message was edited by:

mgarrett

[2355 byte] By [mgarretta] at [2007-11-27 0:21:17]
# 1
By the way, this works on my Dallas TINI embedded java processor!!
mgarretta at 2007-7-11 22:15:01 > top of Java-index,Core,Core APIs...
# 2
If I step through the code it works, if I put a 500 mSec sleep in front of the println,it still fails. So, the function seems to be returning, but the screen is not getting updated.(The eclipse terminal).
mgarretta at 2007-7-11 22:15:01 > top of Java-index,Core,Core APIs...
# 3
I suggest that you don't test serial port apps from within an IDE.
ChuckBinga at 2007-7-11 22:15:01 > top of Java-index,Core,Core APIs...
# 4
Are you getting an exception? Does it ever leave the while loop? You most likely are re-entering the function per each event, but that shouldn't mean anything as far as "Leaving Function" being displayed.
kmangolda at 2007-7-11 22:15:01 > top of Java-index,Core,Core APIs...
# 5

> while( inputStream.available() > 0){

> int numBytes = inputStream.read(readBuffer);

> System.out.print(new String(readBuffer));

> outputStream.write(readBuffer);

System.out.print(new String(readBuffer,0,numBytes));

outputStream.write(readBuffer,0,numBytes);

> }

> } catch (IOException e) {

> }

If you don't put something into that catch block you will never know what's really going on in this code.

And this has nothing to do with Java Serialization.

ejpa at 2007-7-11 22:15:01 > top of Java-index,Core,Core APIs...