3

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?

Jason S
  • 184,598
  • 164
  • 608
  • 970
  • Since running into this issue, I switched to [PureJavaComm](http://www.sparetimelabs.com/purejavacomm/purejavacomm.php) and have been using it for several years without any problems. I have abandoned use of RXTX; it's no longer well-maintained. [NRJavaSerial](https://github.com/NeuronRobotics/nrjavaserial) is a maintained fork of RXTX -- haven't tried it in the last few years though. – Jason S Feb 23 '16 at 14:29

2 Answers2

0

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.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
0

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