当前位置: 技术问答>linux和unix
如何控制USB HID 设备
来源: 互联网 发布时间:2015-10-27
本文导语: 发送命令:Byte 0: 0x02 Byte 1: 0x13 ==========windows成功代码参考=============== CHAR OutputReport[2]; OutputReport[0]=0x02; if (check3==1){//表示锁定 OutputReport[1]=0x14; }else{ ...
发送命令: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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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))
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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
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))