mike-obrien.net Curriculum Vitae Blog Labs
Tuesday, October 10, 2006

I recently had the opportunity to work with a 2d area scanner (aka Bar Code Reader) in a .NET application. Previously our client used proprietary software that just plain stunk so we decided to write our own software. One very cool thing I discovered while working on this project was that many USB devices (Like bar code scanners, joysticks, game pads, mice, keyboards, etc) sport a Human Interface Device (HID) interface. This interface communicates using the standard HID protocol defined by the USB Implementers Forum. The cool thing about this is that one standard device driver can be written and used for all USB HID devices on a particular platform. Normally you would have to write your own device driver or use an existing one to communicate with a USB device, ouch! USB HID eliminates that requirement. Windows ships with a standard USB HID device driver and automatically makes the HID interface available when a USB HID device is plugged into the system. Nothing to install, no device driver to write, yay! Windows also has a fairly easy to use API (Although a little quirky) for communicating with HID devices. This site, run by Jan Axelson, has a lot of good information on communicating with USB HID devices. His book, USB Complete, is also an invaluable resource, I would definitely recommend it if you will be doing HID development on any platform.

I have an HID .NET library available here if you want to skip most of the gory details and get right down to business. I have used this library in production and have not had any issues, please let me know if you have any feedback. Using this library, while encapsulating most of the underlying details, will require you to understand the format of data contained in the payload of the reports sent to and from the device. HID’s communicate using "reports" which are analogous to packets in network terminology. The reports themselves are a standard USB HID data structure although the payload of these reports will be specific to the device or device type. Usually the payload data format can be found in the device SDK and/or by simply analyzing the payload data the device sends.

The following library, developed for the HHP IT4600/IT4800 area scanner, uses the aforementioned HID library.

IT4XXXScanner.zip (1.98 MB)
Thursday, December 07, 2006 10:31:26 PM (GMT Standard Time, UTC+00:00)
Mike,

I wanted to express my appreciation for your USB HID Device Library. I've only tinkered with it a bit, but it looks perfectly suited for what I'm working on -- which is trying to interface with a USB HID device in .NET. Good fit, eh? :) I've just started using it and I'm still experimenting with it, and so far it looks like it'll work great for my purposes! :) I will probably have some questions for you later about it if you don't mind fielding those...

Also, could you comment on something I observed with this library? One of the first things I did with the library was to enumerate some devices. After I did that, it appeared as though the list which was returned contained lots of duplication. (To be precise, the list always contained N x N items, where N was the number of HID devices on my system.) So I downloaded the source code for the library and took a look at what it was doing, and I think I've figured out what the problem is. I suspect that this behavior is unintended, but I won't go into all the details here & now. If you'd like for me to share what I changed so you can consider it for a "bug fix", let me know!

Again, thanks for writing that nifty HID library! I'll surely contact you again.

Much thanks, Paul
Paul Miller
Friday, December 08, 2006 2:54:56 AM (GMT Standard Time, UTC+00:00)
Paul,

I'm glad you could use it! It was a lot of work to research HID and code against the HID API so I hope the library can save people some time and let them focus on their app, not all the HID plumbing. I really wish the .NET team would include a class under System.IO for HID, it would really be a nice feature.

I would love to hear any feedback or questions you may have. Thanks for catching the bug as well, feel free to expound on it. I'm not really using the enumeration feature in the app I wrote the library for so that part hasent really been put to the test in production. Let me know the details.

Thanks again!

m
Thursday, January 25, 2007 10:06:33 PM (GMT Standard Time, UTC+00:00)
Nice job... Just found this and tested it out with the Nintendo Wii controller, seems to be working.

I had been modifying an HID library I found on "The HID Page", http://www.lvr.com/hidpage.htm, since it had terrible encapsulation. I was having some trouble and looked around some more and found your lib. It's essentially everything I was trying to do, eheh.

Thanks,
Curtis
Thursday, January 25, 2007 11:46:05 PM (GMT Standard Time, UTC+00:00)
Awesome! Glad it worked for you!
Comments are closed.