[libhid-discuss] libhid problems with interrupt_read/write

Thomas Maclean tmaclean at sandbox.ca
Sun Apr 8 19:13:28 UTC 2007


After much fiddling around, it seems that the secret is to retry when I
have a read timeout. The weird thing is that I was effectively re-trying
but over a longer timespan.  It seemed that after the first read timeout,
all subsequent reads would also fail.  I rewrote my fill (buffer) routine
to  immediately retry the read if the read fails the first time, and this
seems to improve the situation greatly. It has two effects: 1) sometimes I
do get data the second time; 2) even if I don't get data on the second
try, subsequent attemts to read seem to work.

I didn't get a chance to see if usb_clear_halt() would also fix the
situation, mostly because I rather like the current behaviour.

Thanks for your help (though I have more questions coming!).

-tom m.




On Fri, 6 Apr 2007, Charles Lepple wrote:

> Thomas Maclean wrote:
> >
> > Ugh.  Sorry.  I had been using some online doxygen docs for hid.h and it
> > hadn't occured to me that it could change.  Lesson learned.
>
> yeah, if I ever find the idiot who posted them... :-)
>
> http://www.ghz.cc/~clepple/libhid/doc/html/hid_8h.html#ce983c54fd45ac9913faa7d0cb730090
>
> It's up to date now.
>
> > I am pretty sure I'm linking against the same distribution of libhid
> > because I only have that one version (installed in /usr/local/lib ).
> >
> > Wow ... in my world (embedded telecom systems) 100 msec is a long time!
> > I'll try increasing the timeout a bit.  My CPU is reasonably fast (1 GHz)
> > - no rocket, but not some embedded 33 MHz processor.
>
> The raw data rate for low-speed USB is 1.5 Mbit/sec, but the actual
> throughput is much lower.
>
> > I tried printing the usb_strerror() when I get error returns from my hid
> > calls, but mostly the returned string says something along the lines of
> > the device was busy or anavailable.
> >
> > I was looking for ways to 'clear' the error on the pipe (i.e. after I get
> > a timeout, all subsequent reads fail.)  I thought I had something
> > to clear the error by performing a zero-byte read, but I don't think this
> > does anything.  The odd thing I noticed when doing this is that when I
> > try to read 8 bytes and I get a timeout, the warning tells me I got zero
> > bytes.  When I subsequently perfrom a zero-byte read, the warning tells me
> > that I requested 0 bytes, but it sent 8 (though the read buffer seems
> > empty).
>
> Odd, maybe I need to check the code there, but in the actual HID spec, I
> don't think that zero-byte reads are ever used.
>
> I'm not sure that this is really the proper way to fix things, but there
> is this libusb function:
>
> http://libusb.sourceforge.net/doc/function.usbclearhalt.html
>
> --
> Charles Lepple
> clepple at ghz.cc
>



More information about the libhid-discuss mailing list