NeuronRobotics / nrjavaserial

A Java Serial Port system. This is a fork of the RXTX project that uses in jar loading of the native code.
Other
345 stars 143 forks source link

read method behavior win/linux #53

Closed gchauvet closed 8 years ago

gchauvet commented 8 years ago

Hello,

I notice a different behavior between Windows (>= xp) and Linux :

int value = input.read();
while ((value & 0xFF) != ENQ) {
  System.out.println("Waiting....");
  value = input.read();
}

Under Windows, I can read message "Waiting" until ENQ code was reached. Under Linux, my code is stuck on the first input.read() call. In my real usecase, I use this loop to reach a lapse of time before throwing a TimeoutException.

Is it possible to have the same behavior between Windows & Linux ?

andyrozman commented 8 years ago

It all depends on how you set your port. I get always -1 when there is no data available... (on linux). You can control if you have blocking or non-blocking. Google "rxtx java blocking"

gchauvet commented 8 years ago

okay, this is possible :+1:

port.enableReceiveTimeout(200);

Solve my "issue"

Thank you !

MrDOS commented 8 years ago

See #27, and my comment there. You're right, the out-of-box behaviour is unintuitive, but I suspect it's actually the Windows behaviour that's wrong. Either way, better documentation is needed. Thank you for the feedback.