Discussion:
[libhid-discuss] Trying to get reports from hid device - unsuccessful
Vladimir Bashkirtsev
2011-05-03 08:42:38 UTC
Permalink
Hello,

I have some questions and cannot find answers. Hope that you will be
able to help.

I have a USB scale which appears as HID device. On plugin it claimed by
hidraw driver and appears as /dev/hidraw4 . Scales repeatedly send 6
bytes blocks containing current status. I would like to read these 6
bytes, decode them and then feed relevant representation to /dev/uinput
so it would act similar to barcode scanners which act as keyboards. So I
am going to make a daemon which will do it. However something tells me
that most appropriate way to access HID will be libhid instead of
hidraw. I tried to use it and run into problems and need some guidance.

1. As I understand libhid does not support asynchronous transfer? ie I
cannot register a callback function which will be triggered each time as
data appears on interface?
2. I have compiled test_libhid.c and I can detach the device from hidraw
and can dump its tree:

TRACE: hid_dump_tree(): iterating the parse tree for USB device
003/005[0]...
parse tree of HIDInterface 003/005[0]:
path: 0x008d0020.0x008d0030.0x008d0027.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x008d0050.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0032.0x008d0070.0x00000000; type: 0x80
path: 0x008d0020.0x008d0032.0x008d0050.0x00000000; type: 0x80
path: 0x008d0020.0x008d0032.0x008d0041; type: 0x80
path: 0x008d0020.0x008d0032.0x008d0040; type: 0x80
path: 0x008d0020.0x008d0031.0x008d0080; type: 0x90
path: 0x008d0020.0x008d0031.0x008d0081; type: 0x90
path: 0x008d0020.0x008d0031.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x008d00ff; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d003a.0x00000000; type: 0x90
path: 0x008d0020.0x008d0030.0x008d0040; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0
path: 0x008d0020.0x008d0030.0x00000000; type: 0xb0

As I understand I need to read reports from path of type 0x80. So I do:

unsigned char const PATHLEN = 4;
int const PATH_OUT[4] = { 0x008d0020, 0x008d0032, 0x008d0070,
0x00000000 };

unsigned char const RECV_PACKET_LEN = 6;
char packet[RECV_PACKET_LEN];
ret = hid_get_input_report(hid, PATH_OUT, PATHLEN, packet,
RECV_PACKET_LEN);
if (ret != HID_RET_SUCCESS) {
fprintf(stderr, "hid_get_input_report failed with return code
%d\n", ret);
}

and it comes back with

TRACE: hid_get_input_report(): looking up report ID...
TRACE: hid_prepare_parse_path(): preparing search path of depth 4 for
parse tree of USB device 003/005[0]...
TRACE: hid_prepare_parse_path(): search path prepared for parse tree
of USB device 003/005[0].
NOTICE: hid_find_object(): found requested item.
TRACE: hid_get_input_report(): retrieving report ID 0x03 (length: 6)
from USB device 003/005[0]...
WARNING: hid_get_input_report(): failed to retrieve report from USB
device 003/005[0]:error sending control message: Broken pipe.
hid_get_input_report failed with return code 20

And it is the same for all paths of type 0x80. What I do wrong? Perhaps
answer is simple but I have tried everything and cannot get scales to
report as expected.

Regards,
Vladimir

Loading...