Talking to USB HID
I need to send to and read from a USB device. So far, the hid driver seems to be the choice.
This is what I need to send and receive:
USHORT Buffer[9];
I have the file descriptor from:
if ((fd=open("dev/usb/hiddev0", O_RDONLY)) < 0)
{ perror("hiddev open");
exit(1);
}
I can get the report information from:
struct hiddev_report_info
{ unsigned report_type;
unsigned report_id;
unsigned num_fields;
}
struct hiddev_usage_ref
{ unsigned report_type:
unsigned report_id;
unsigned field_index;
unsigned usage_index;
unsigned usage_code:
_s32 value:
}
struct hiddev_usage_ref usage_ref;
struct hiddev_report_info rep_info;
--------
calling ioctl(fd, HIDIOCGREPORTINFO, &rep_info) and reading the struct
gives me rep_info.report_type = 1 (or 2 or 3)
rep_info.id = 0
rep_info.num_fields = 1
How do I fill in the structures rep_info and usage_ref to handle the nine element buffer? I assume I use:
ioctl(fd, HIDIOCSUSAGE, &usage_ref) and
ioctl(fd, HIDIOCSREPORT, &rep_info)
to send the buffer contents to the device, and
ioctl(fd, HIDIOCGREPORT, rep_info)
to read the device????????????
|