Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15531337
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: 嵌入式

2009-07-28 22:03:51

浅析windows下hid.lib库驱动IN,OUT数据组成和linux下移植注意事项

  使用hid.lib与hid设备进行通信时,在每次发送数据之前都要在头部添加内容为0的1个字节数据report_id报告id,
对于output report该数据供hid.lib解析,hid.lib库驱动会将该1个字节的report_id报告id数据添加到usb_control_msg
发送的value低8位中cpu_to_le16(((report->type + 1) << 8) | report->id);即:0x200,并不会将第1个字节
report_id报告id数据作为实际待发数据,实际数据从第2个字节开始,interrupt in接收也一样,从hid物理设备接收到的数据,
hid.lib库驱动先提取report_id报告id,然后打到in数据的最开始头部,发送给调用ReadFile的vc程序,
在interrupt in输入接收到的raw数据前面hid.lib驱动会自动追加内容为0的1个字节数据report_id报告id,
使用usb hound截获到的数据有如下规律[luther.gliethttp].
20.0表示CTL或者OUT输出,实际发送给hid物理设备的数据log
20.1表示IN输入,实际从hid物理设备读取到的数据log
22和18表示hid.lib库驱动OUT和IN数据,所以上面加上小数点的log才是与hid物理设备进行的raw数据[luther.gliethttp].
  所以linux下使用libusb进行移植时,需要注意libusb实现IN,OUT数据传输时,参考的是
带有小数点的log数据,比如20.0和20.1,而不是参考22和18等hid.lib库驱动添加了第1个字节数据的report_id报告id的log[luther.gliethttp].

使用hid.lib与hid设备进行通信时,usb hound抓获的部分log数据如下:[luther.gliethttp]
  20.0  CTL    21 09 00 02  00 00 08 00                                                                                SET REPORT               1.1.0        
  20.0  DO     51 47 53 0d  2a e0 0f 19                                                                                QGS.*...                 1.2.0        
  22    DO     00 51 47 53  0d 2a e0 0f  19                                                                            .QGS.*...                2.1.0        
  20.1  DI     28 32 31 38  2e 33 20 35                                                                                (218.3 5                 3.1.0        
  22    DI     00 28 32 31  38 2e 33 20  35                                                                            .(218.3 5                4.1.0        
  20.1  DI     30 2e 30 20  32 32 39 2e                                                                                0.0 229.                 5.1.0        
  22    DI     00 30 2e 30  20 32 32 39  2e                                                                            .0.0 229.                6.1.0        
  20.1  DI     37 20 35 30  2e 30 20 30                                                                                7 50.0 0                 7.1.0        
  22    DI     00 37 20 35  30 2e 30 20  30                                                                            .7 50.0 0                8.1.0        
  20.1  DI     30 30 2e 37  20 30 30 37                                                                                00.7 007                 9.1.0        
  22    DI     00 30 30 2e  37 20 30 30  37                                                                            .00.7 007               10.1.0        
  20.1  DI     20 33 36 38  2e 35 20 33                                                                                 368.5 3                11.1.0        
  22    DI     00 20 33 36  38 2e 35 20  33                                                                            . 368.5 3               12.1.0        
  20.1  DI     36 38 2e 37  20 30 38 32                                                                                68.7 082                13.1.0        
  22    DI     00 36 38 2e  37 20 30 38  32                                                                            .68.7 082               14.1.0        
  20.1  DI     2e 37 20 2d  2d 2d 2e 2d                                                                                .7 ---.-                15.1.0        
  22    DI     00 2e 37 20  2d 2d 2d 2e  2d                                                                            ..7 ---.-               16.1.0        
  20.1  DI     20 30 31 38  2e 30 20 31                                                                                 018.0 1                17.1.0        
  22    DI     00 20 30 31  38 2e 30 20  31                                                                            . 018.0 1               18.1.0        
  20.1  DI     30 30 30 30  30 30 30 30                                                                                00000000                19.1.0        
  22    DI     00 30 30 30  30 30 30 30  30                                                                            .00000000               20.1.0        
  20.1  DI     30 30 31 0d  20 30 38 32                                                                                001. 082                21.1.0        
  22    DI     00 30 30 31  0d 20 30 38  32                                                                            .001. 082               22.1.0


usb hound去除CTL信息的log图[luther.gliethttp]这里的log是hid.lib库驱动对应的流动数据,并不是实际发送到hid物理设备的数据,将所有log的第1个字节report_id报告id数值0x00去除掉就是在hid物理设备上实际流动的数据了[luther.gliethttp]

usb hound截获的Caps Lock按键按下之后usb数据流动信息[luther.gliethttp]



可以参考:windows主机端与自定义USB HID设备通信详解
以下内容摘自:http://blog.163.com/wodeafei/blog/static/883385200811354817711/
HidD_GetHidGuid                     hid.dll         Obtain the GUID for the HID class
SetupDiGetClassDevs                 setupapi.dll    Return device info set containing all of the devices in a specified class.
SetupDiEnumDeviceInterfaces         setupapi.dll    Return information about a device in the device information set.
SetupDiGetDeviceInterfaceDetail     setupapi.dll    Return a device pathname.
SetupDiDestroyDeviceInfoList        setupapi.dll    Free resources used by SetupDiGetClassDevs.
CreateFile                          kernel32.dll    Open communications with a device.
HidD_GetAttributes                  hid.dll         Return a Vendor ID, Product ID, and Version Number.
HidD_GetPreparsedData               hid.dll         Return a handle to a buffer with information about the device's capabilities.
HidP_GetCaps                        hid.dll         Return a structure describing the device's capabilities.
HidD_FreePreparsedData              hid.dll         Free resources used by HidD_GetPreparsedData.
WriteFile                                           kernel32.dll Send an Output report to the device.
ReadFile                                            kernel32.dll Read an Input report from the device.
HidD_SetFeature                     hid.dll         Send a Feature report to the device.
HidD_GetFeature                     hid.dll         Read a Feature report from the device.
CloseHandle                         kernel32.dll    Free resources used by CreateFile.

从NTDDK\INC拷贝下列头文件
devioctl.h
usbdi.h
usbioctl.h
usb100.h
hidsdi.h
hidusage.h
hidpi.h
从NTDDK\libchk\i386拷贝hid.lib
在PROJECT SETTING中添加hid.lib setupapi.lib
阅读(7319) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~