To read data from USB HID device I use the following code:
Code:
struct hiddev_report_info rinfo;
struct hiddev_field_info finfo;
struct hiddev_usage_ref uref;
int i, j, ret, count;
while (1){
rinfo.report_type = HID_REPORT_TYPE_INPUT;
rinfo.report_id = HID_REPORT_ID_FIRST;
ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
// Get Reports
while (ret >= 0&&rinfo.num_fields>0&&rinfo.num_fields<64){
// Get Fields
for (i = 0; i < rinfo.num_fields; i++){
finfo.report_type = rinfo.report_type;
finfo.report_id = rinfo.report_id;
finfo.field_index = i;
ioctl(fd, HIDIOCGFIELDINFO, &finfo);
// Get usages
for (j = 0; j < count+1; j++){
uref.report_type = finfo.report_type;
uref.report_id = finfo.report_id;
uref.field_index = i;
uref.usage_index = j;
ioctl(fd, HIDIOCGUCODE, &uref);
ioctl(fd, HIDIOCGUSAGE, &uref);
printf("0x%X ",uref.value);
// First output usage: grab it.
if(uref.report_type == HID_REPORT_TYPE_OUTPUT && j==0) {
memcpy(&uref_out, &uref, sizeof(uref));
}
}
for (; j < finfo.maxusage; j++){
uref.report_type = finfo.report_type;
uref.report_id = finfo.report_id;
uref.field_index = i;
uref.usage_index = j;
ioctl(fd, HIDIOCGUCODE, &uref);
ioctl(fd, HIDIOCGUSAGE, &uref);
}
}
printf("\n");
rinfo.report_id = HID_REPORT_ID_NEXT;
ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
}
usleep(1000000);
}
}
As a result, I receive only the last report from series report.
If I use
Code:
ret = ioctl(fd, HIDIOCGREPORT &rinfo);
instead of
Code:
ret = ioctl(fd, HIDIOCGREPORTINFO, &rinfo);
than nothing readable is received at all.
Any attempt to use smth else instead of
Code:
rinfo.report_id = HID_REPORT_ID_FIRST;
don't lead to any result.
The device receives Reports without any problems. Reports are sent with
Code:
ret = ioctl(fd, HIDIOSGREPORT &rinfo);
Could you please advice what could be wrong?