views:

1411

answers:

3

I'm using the RxTx library over usbserial on a Linux distro. The RxTx lib seems to behave quite differently (in a bad way) than how it works over serial.

One of my biggest problems is that the RxTx SerialPortEvent.OUTPUT_BUFFER_EMPTY does not work on linux over usbserial.

How do I know when I should write to the stream? Any indicators I might have missed?

So far my experience with writing and reading concurrently have not been great. Does anyone know if I should lock the DATA_AVAILABLE handler from being invoked while I'm writing on the stream? Or RxTx accepts concurrent read/writes?

Thanks in advance

+1  A: 

Hi Chris,

Using RxTx over usb-to-serial you can't set notifyOnOutput to true otherwise it locks up completely.

I've learned this the hard way. This problem is documented on a few web sites over the internet.

I'm running it on Linux and I believe that this is a Linux only issue, although I can't confirm that.

As for the link you've given me... I've seen the SimpleReader and SimpleWriter examples, but these don't represent a real world application. It is not multi-threaded, assumes a read has the full data it needs instead of buffering reads, etc.

Thanks,

Jeach!

Jeach
I deleted my answer because it looked like a better one was given.
Chris
+2  A: 

(perhaps slightly off-topic, but here goes)

I'm not familiar with that particular library, but I can assure you from dire experience (I work in the security systems (as in: hardware security devices) business, where RS-232 is heavily used) that not all USB-serial converters are born equal. Many such devices so not properly emulate all RS-232 lines, and many don't even handle any comms without flow control. Before blaming the library, try to confirm that the hardware actually does what it's supposed to do.

Without wanting to endorse a particular product or brand, the best (as in: least buggy) USB-serial converter I have come across in years is the USA-19HS.

Mihai Limbășan
Keyspan got bought out by Tripp-Lite who doesn't seem to believe in permalinks. >:( Here's the new html link: http://www.tripplite.com/en/products/model.cfm?txtModelID=3914
Jason S
p.s. we have the same model here at my company. It seems to work fine although tops out at 2x speed (230400bps). I tend to like the FTDI-based parts that get up to 3Mbps (have lately been using the UB232)
Jason S
As I've posted in my other RxTx question, you were right Jason S. It was the USB device that was causing 'some' problems.
Jeach
A: 

I can confirm that it does seem to be a library and linux only issue. I had the same problem before I stopped calling notifyOnOutputEmpty(true). And I'm using rxtx RXTX-2.2pre1.

When I connect the device (or really the simulator) to a real com port and open port /dev/ttyS0 in my program it works.

When I instead connect the device (real device or simulator) to /dev/ttyUSB0 it does not work! I can send data and it's received on the other end but I receive nothing back..

I've tried on the same usb port under WinXP/virtualbox and my program then works.

When I communicate between two usb to serial devices on /dev/ttyUSB0 and /dev/ttyUSB1 with a serial terminal program like cutecom it works under Ubuntu. So it's not a hardware problem. It must be something with the combination java rxtx and usb to serial devices on Linux.

Thanks Jeach for the solution!

Ben

Ben