I'm trying to work with some USB HID device.
I have proprietary software (from the device's vendor) which can interact with the device. But I need to write my own one. With help of a sniffer tool I've catched traffic between the host and the device. This tool is BusDog. Then I was able to reproduce the same traffic via WriteFile with device's handle which I get from CreateFile (for path got from setupapi.dll APIs). But the device doesn't react on my commands ("requests" as they're called in USB/HID world). 开发者_C百科Then I took another tool - HHD Device Monitoring Studio. This tool shows not only "interrupt transfer" but also all kinds of transfers. I can see the following log:
008852: Class-Specific Request (DOWN), 20.12.2010 18:58:10.242 +0.031 Destination: Interface, Index 0 Reserved Bits: 34 Request: 0x9 Value: 0x30d Send 0x8 bytes to the device 0D 01 01 00 00 00 00 00 ........ 008853: Control Transfer (UP), 20.12.2010 18:58:10.242 +0.0. Status: 0x00000000 Pipe Handle: 0x8638c5c8 0D 01 01 00 00 00 00 00 ........ Setup Packet 21 09 0D 03 00 00 08 00 !....... Recipient: Interface Request Type: Class Direction: Host->Device Request: 0x9 (Unknown) Value: 0x30d Index: 0x0 Length: 0x8
My question is how to reimplement this kind transfer in my own code? And how to parse this stuff to parameters of appropriate function (is the DeviceIoControl?)
p.s. I'm using C#, but actually it doesn't matter much, I can understand C/C++.
Have a look at the HIDClass Support Routines (http://msdn.microsoft.com/en-us/library/ff538865%28v=vs.85%29.aspx) which wrap up all the relevant HID ioctls for you... it might be something like a feature report (HidD_SetFeature).
I detail this kind of thing in a detailed overview in this answer. But I'll summarize some of the main points.
First off, you have to find out the Vendor and Product IDs for the device. (These are unique.) The process of communicating with the device is simple. Enumerate the attached devices, pick the one that matches the IDs you are looking for, then use a library like libusb to read/write from/to the device. There is a detailed example at the very bottom of the above stack answer I linked to.
精彩评论