[purejavacomm] PJC and RXTX behaviour when USB unplugged

  • From: QtuTrains <Howard@xxxxxxxxxxxxx>
  • To: purejavacomm@xxxxxxxxxxxxx
  • Date: Sun, 10 Nov 2013 13:30:37 +1300

A recent discussion on the RXTX group prompted me to see what happens when the 
USB dongle is unplugged while the port is in use:

On 9/11/2013, at 23:25 , Dr. Douglas Lyon <lyon@xxxxxxxxxxx> wrote:

> Not only does Java crash on a mac with the usb serial cable unplugging,
> but on 10.6.8 all rosetta programs crash, hard.
> This symptom is new with 10.6.8 and did not appear in 10.6.7.

I have just tried this on Mac OS X 10.8.5 (where there is no rosetta).

My App (correctly) received an IllegalStateException on either or both input or 
output threads.
If I catch the exception and close the port all appears well.


1. Plug in dongle and find /dev/tty.PL2303-00004214
2. Start App, select interface, start comms, remote device now talking
3. Unplug USB cable from Mac
4. App catches exception, closes port.
5. Select stop interface to tidy up. The App is still running and responds to 
the GUI
6. Plug dongle back in
7. Select start interface
8. Comms running again. 

Actually the port is correctly transmitting again (the target hardware receives 
messages correctly) but not receiving.
The purejavacomm reader thread is running:

"tty.PL2303-00004214" daemon prio=5 tid=140655927140352 nid=0x16dfdc000 
runnable [6140309504]
   java.lang.Thread.State: RUNNABLE
        at com.sun.jna.Function.invokeInt(Native Method)
        at com.sun.jna.Function.invoke(Function.java:344)
        at com.sun.jna.Function.invoke(Function.java:276)
        at com.sun.jna.Library$Handler.invoke(Library.java:216)
        at $Proxy0.select(Unknown Source)
        at jtermios.macosx.JTermiosImpl.select(JTermiosImpl.java:326)
        at jtermios.JTermios.select(JTermios.java:438)
        at purejavacomm.PureJavaSerialPort$3.run(PureJavaSerialPort.java:1203)
        at java.lang.Thread.run(Thread.java:722)

But the app never receives any more data. Even after stopping and restarting 
it. An OS reboot appears necessary.
But at least the app does not crash.

The device driver I am using is osx-pl2303.kext referenced from 

OK, I was confused between whether I was using PJC or RXTX at the time, so the 
above is actually a report of what happens on PJC.

I have just tried again using RXTX and it behaved even better! After plugging 
the dongle back in I could open the port and get working bi-directional comms - 
no system reboot required.

This suggests that there might be a bug in PJC that leaves the port unusable 
after a disconnection.

Any ideas?

Howard Amos

Other related posts: