Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.34k stars 287 forks source link

isOpen() returns true even if serial port is not available anymore to underlying OS #416

Closed vdg-glitch closed 2 years ago

vdg-glitch commented 2 years ago

Hi,

pulling out the USB cable (RS232 to USB cable) or equivalently detaching the RS232 physical port from QEMU emulating a Window 7 32 bit guest OS doesn't force SerialPort.isOpen() to return false. How to detect (without attempting to read or write any bytes) that the port is not valid anymore?

Thank you

NorbertSandor commented 2 years ago

Have you tried listening to 'port disconnected' event? See: http://fazecast.github.io/jSerialComm/javadoc/com/fazecast/jSerialComm/SerialPort.html#LISTENING_EVENT_PORT_DISCONNECTED

vdg-glitch commented 2 years ago

My project was using the 2.7.0 library version and that event was not part of it.

I upgraded it to 2.9.1, implemented the listener to LISTENING_EVENT_PORT_DISCONNECTED and it seems to work.

Will make some more experiments.

Thanks very much

hedgecrw commented 2 years ago

Thanks for the community help on this one!