阅读:2003回复:0
如何控制USB HID 设备
发送命令:Byte 0: 0x02
Byte 1: 0x13 ==========windows成功代码参考=============== CHAR OutputReport[2]; OutputReport[0]=0x02; if (check3==1){//表示锁定 OutputReport[1]=0x14; }else{ OutputReport[1]=0x13; } DWORD BytesWritten = 0; ULONG Result; Result = WriteFile \ (DeviceHandle, \ OutputReport, \ Capabilities.OutputReportByteLength, \ &BytesWritten, \ NULL); =========linux代码如何写,下面是我未完成的,不知道怎么写了书(参考代码: http://www.frogmouth.net/hid-doco/examples/hiddev-misc/write-events.c ) ==== #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <asm/types.h> #include <sys/signal.h> #include <linux/hiddev.h> int main (int argc, char **argv) { int fd = -1; int rd; int w; unsigned int i, alv, yalv; struct hiddev_devinfo device_info; struct hiddev_report_info rep_info; struct hiddev_field_info field_info; struct hiddev_usage_ref usage_ref; struct hiddev_event ev[64]; fd_set fdset; int report_type; int appl; int version; if ((fd = open("/dev/usb/hiddev0", O_RDONLY)) < 0) { printf("hiddev open error \n"); exit(1); }else{ printf("hiddev open ok \n"); } printf("HID_REPORT_TYPE_OUTPUT %d \n",HID_REPORT_TYPE_OUTPUT); usage_ref.report_type = HID_REPORT_TYPE_OUTPUT; usage_ref.report_id = 2; usage_ref.field_index = 1; usage_ref.usage_index = 0; /* which LED 0 is num lock, 1 is caps lock, 2 is scroll lock */ usage_ref.usage_code = 27; /* no one cares? */ usage_ref.value = 1; /* binary on (1) or off (0) */ w=ioctl(fd, HIDIOCSUSAGE, &usage_ref); printf("w=%d \n",w); rep_info.report_type = HID_REPORT_TYPE_OUTPUT; rep_info.report_id = 0x02; rep_info.num_fields = 0x13; w=ioctl(fd, HIDIOCSREPORT, &rep_info); printf("w=%d \n",w); close(fd); exit(0); } |
|