views:

412

answers:

2

I'm using rxtx for serial I/O handling in Java with an FTDI2232H that provides a USB comm port. It works great, with one exception: if I unplug the USB cable, so that the COM port disappears at runtime, it spews exceptions left and right:

java.io.IOException: No error in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.read(RXTXPort.java:1427)
at gnu.io.RXTXPort$SerialInputStream.read(RXTXPort.java:1339)

and when I re-plug the cable in again, it does not recover.

Is there any way to get rxtx to work properly with USB comm port connection/disconnection? (I've tried to post to the rxtx mailing list but for some strange reason I cannot send messages even though I am subscribed to the list. I've emailed the list admin and have gotten no response.)

If not, is there another serial I/O framework that does?

A: 

By the sound of it, I do not know if this is possible in Java, but there is a windows message that gets broadcasted - WM_DEVICECHANGE message, it is likely you need to intercept this message and if it's a device eject, gracefully shut down the rxtx code. Here's an example code to check for insertion/removal of CD in CDROM drive (It is not in Java).

Edit: Have added another link here that might be of interest to you.

Hope this helps, Best regards, Tom.

tommieb75
A: 

well. we use WM_DEVICECHANGE and coded in C++ and prepared DLL and then access it via JNI from JAva application.. so we get notification of connection and disconnection

yashas ballal