[Rxtx] RXTX serial port read() returns -1 unexpectedly and then blocks forever on close()

Ryan Boder ryan.boder at gmail.com
Wed Mar 2 18:46:48 MST 2011


It is USB and seems very reliable with the C# test program in my previous
email.


On Wed, Mar 2, 2011 at 6:58 PM, Bruce Griffith <Bruce.Griffith at se-eng.com>wrote:

> How reliable is your serial port – is it USB or Bluetooth?
>
>
>
> Bruce Griffith
>
> 303-532-4778
>
>
>
> *From:* rxtx-bounces at qbang.org [mailto:rxtx-bounces at qbang.org] *On Behalf
> Of *Ryan Boder
> *Sent:* Tuesday, 01 March 2011 10:53 PM
> *To:* rxtx at qbang.org
> *Subject:* Re: [Rxtx] RXTX serial port read() returns -1 unexpectedly and
> then blocks forever on close()
>
>
>
> Hi,
>
> I haven't seen any response to my question below. Is this not the right
> place to ask? If not, where would be a better place to ask? Any suggestions?
>
> Thanks,
> Ryan
>
> On Mon, Feb 28, 2011 at 12:34 AM, Ryan Boder <ryan.boder at gmail.com> wrote:
>
> I mis-spoke, I don't have my own thread calling read, I am calling read in
> the event handler after receiving a SerialPortEvent.DATA_AVAILABLE event.
> Everything else I said should be accurate though.
>
> Ryan
>
>
>
> On Mon, Feb 28, 2011 at 12:28 AM, Ryan Boder <ryan.boder at gmail.com> wrote:
>
> Hi,
>
> I have a receive thread that does nothing but call read() on the serial
> port input stream. It works fine for a while but after running for a long
> time it eventually returns -1 which means EOF. This is my first problem, as
> the device I'm talking to runs forever, I don't know why it would return -1.
> I am calling disableReceiveThreshold() and disableReceiveTimeout() at
> initialization which according to the documentation means read will return
> as soon as any data is available and it will block forever when data is not
> available, so -1 should never be returned from read, right?
>
> I have been unable to figure out why read returns -1 after a long while but
> I have found that if I kill my application and restart it everything works
> fine again. Therefore I tried to work around the problem by having my code
> close the port and reopen it when read returns -1. My second problem is that
> in this case when I call close() on the port it blocks forever. I did find
> this old bug
>
> http://bugzilla.qbang.org/show_bug.cgi?id=53
>
> which describes close() hanging on OSX, but it says that bug was fixed with
> a patch in May 2006. Anyway I am on Window 7, not OSX. Does anyone have any
> idea why read might be returning -1 in the first place? If I can avoid that
> I don't care about close() hanging because I would never close the port. If
> not, does anyone know why close() might block forever and how I can prevent
> this? I'm using RXTX version 2.1-7.
>
> Thanks,
> --
> Ryan
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qbang.org/pipermail/rxtx/attachments/20110302/a09d1b9a/attachment-0534.htm>


More information about the Rxtx mailing list