[libhid-discuss] reading from a barcode scanner that acts like a keyboard

Charles Lepple clepple at ghz.cc
Wed Nov 8 18:24:32 CET 2006


Brice Rebsamen wrote:
> Thank you Charles for these valuable information, thanks a lot. I have a
> deeper understanding now. Still need help though.
>
>>      Endpoint Descriptor:
>>        bLength                 7
>>        bDescriptorType         5
>>        bEndpointAddress     0x81  EP 1 IN
>>       bmAttributes            3
>>          Transfer Type            Interrupt
>>          Synch Type               None
>>          Usage Type               Data
>>        wMaxPacketSize     0x0008  1x 8 bytes
>>        bInterval              10
>>
>> bInterval suggests that you poll the device every 10 milliseconds.
>> Sometimes, you need to send a SET_IDLE request to start the data
>> flowing:
>> http://www.ghz.cc/~clepple/libhid/doc/html/hid__exchange_8c.html#
>> c96f8781c3ce92199eda3d18c98406e3
>> Then, you can use hid_interrupt_read() to read reports. Unfortunately,
> this function does not
>> integrate well with the rest of libhid, so you will need to calculate
>> byte
> offsets by hand
>> as I have done above.
>
> What am I supposed to receive from hid_interrupt_read?
> 8 bytes I thought, but then they are always the same one. I tried with 65
> bytes

Why 65? The wMaxPacketSize parameter says 8.

The shift-like keys have one bit per key, but the rest of the keys are in
an array (USB keyboards normally can only report a maximum of 3-5
non-shift keys being pressed simultaneously).

> just in case, but I get mostly the same bytes too, mostly zeros.
> Can you detail a bit more? What do you mean by calculate byte offset? Is
> it
> that I should receive 65 bytes and then interpret it bit per bit to
> retrieve
> control keys, padding, leds, keycodes..?

That's the right idea, but it's a total of 8 bits.

Please check the HID spec - it explains this fairly well.

-- 
Charles Lepple
clepple at ghz.cc




More information about the libhid-discuss mailing list