views:

715

answers:

1

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.

My application has several threads and one of my biggest problems is that out of nowhere, I seem to be getting one to two extra bytes on my stream. I can't figure out where they come from or why. This problem seems to occur a lot more frequently when I write to the RxTx stream using another thread.

So I was wonder if I should process the read on the current RxTx thread or should I process the read on another thread when I get the DATA_AVAILABLE event.

I'm hoping someone might have good or bad reasons for doing it one way or the other.

+1  A: 

This is just a guess, but it may give you a clue.

Is it possible that the send and receive shares a buffer, or that when you send, the bytes are also received on the input somehow - I have seen this before on some embedded systems.

You may find the best thing to do is initially keep both send and receive on the same thread. Another thing may be to make sure the output drains before trying a read.

Hopefully this may give you some clue.

Nick R