mike-obrien.net Curriculum Vitae Blog Labs
Monday, January 29, 2007

There is a new version of the Hid Library in the labs. It has been converted to .NET 2.0 and includes a bug fix. This bug fix involved how the vendor and product id were cast in the structure consumed by the Hid API. So some devices like Logitec's gamepads would not be recognized by their product and vendor id's. Now that issue is resolved. N-joy!

USB Hid Device Library

.NET | C# | USB HID | VB.NET
Tuesday, January 30, 2007 1:25:39 PM (GMT Standard Time, UTC+00:00)
This is fantastic, exactly what I need. Thanks for making it available. I was looking at this library again just a few days ago, and thinking about converting it myself to .NET 2.0, but I see you've already done it!

What is the licensing regarding use of this library? I haven't really tried to use it yet, but I'm hoping to be able to use it without any source modifications.
Jeremy
Tuesday, January 30, 2007 4:23:38 PM (GMT Standard Time, UTC+00:00)
Awesome! Glad it's what you need. Yeah, I have been lazy about converting existing projects over to 2.0... ;-)

I havent applied any licensing to the projects in the labs. Use it however you like. But if you get filthy rich off of it remember to kick a little something my way. :)
Tuesday, January 30, 2007 10:22:51 PM (GMT Standard Time, UTC+00:00)
Cheers,

I'm mainly going to have a play with it at this stage. I have some VB5 software I might try and bring into the 21st century, so I'm not planning to make any money :-)
Jeremy
Saturday, February 03, 2007 2:44:18 AM (GMT Standard Time, UTC+00:00)
Your HID library is terrific - just what is needed for standard HID support! One question: I have been playing around with it a bit and noticed that virtual memory usage increases the longer the HID library is utilized. Have you run into any memory leakage problems with it?

Amy
Amy
Saturday, February 03, 2007 6:00:18 AM (GMT Standard Time, UTC+00:00)
Thank you! :)

I have not but I'll certainly take a look into it. Thanks for catching that!
Saturday, February 03, 2007 9:36:26 PM (GMT Standard Time, UTC+00:00)
FYI: I've noticed that setting the MonitorDeviceEvents property to False seems to reduce the amount of virtual memory being used up...
Amy
Friday, March 09, 2007 10:40:00 PM (GMT Standard Time, UTC+00:00)
I have a composite device here with 3 interfaces. I seem to be receiving 3 identical reports each time I get a report. Are the two facts related?

One of these interfaces is a mouse, and another is a keyboard, neither of which I want to connect to. Where's the best place to be filtering these out?

I'm guessing I should call HIDDevices.Enumerate() which gets me the list of all 3 interfaces, then troll through to find the ones which match the usagepage and usage I am looking for?
Jeremy
Wednesday, March 14, 2007 8:37:32 PM (GMT Standard Time, UTC+00:00)
Amy,

The memory leak has been fixed, thanks again for catching that! You can download the latest version here:

http://labs.mike-obrien.net/view.aspx?projectid=hidlibrary

Jeremy,

I havent run into that before, what is the make and model of the device. Also, just to make sure I'm understanding, you opening only *one* device path but are recieving 3 identical messages from that *one* path? If you are only opening one, have you tried opening the other 2 to see what you get? I havent actually got into looking at the usage reports so I would have to check that out. I believe its just an Hid API call.
Wednesday, March 28, 2007 10:36:25 PM (GMT Standard Time, UTC+00:00)
Hi is there an example on how I can use this in c#? I only know the basics, and can't use VBnet
steve
Thursday, March 29, 2007 3:19:56 PM (GMT Standard Time, UTC+00:00)
Steve,

I have updated the HID Library page in the labs to include a C# example.

hth,

m
Tuesday, April 03, 2007 2:16:32 AM (GMT Standard Time, UTC+00:00)
My previous problem was when trying to fudge your IT4XXX app to read data from the device.

I have a composite USB HID device, with 3 interfaces. I've gone back to scratch, and retrieve your source code. I open the HidLibrary solution, then only change the vendor and product IDs to match my device, and run it, 4 copies of each device path show up in the list box:

VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_00#8&7df418a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_01#8&1fa2cdcf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_02#8&37665a14&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_00#8&7df418a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_01#8&1fa2cdcf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_02#8&37665a14&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_00#8&7df418a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_01#8&1fa2cdcf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_02#8&37665a14&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_00#8&7df418a&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_01#8&1fa2cdcf&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}
VendorID=0x1926, ProductID=0x0001, Version=256, DevicePath=\\?\hid#vid_1926&pid_0001&mi_02#8&37665a14&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}

Do you know why this is happening?
Jeremy
Monday, May 28, 2007 7:17:00 PM (GMT Standard Time, UTC+00:00)
Check things like the output length. Usually devices come up multiple times but with different output lengths among other things. For example my MX5000 keyboard has lengths 7 (for beep, setting the time etc), 20 and 46 (for the LCD display) among others that have 0 output length (presumably input?)

Anyway, back to my question.

I used to use version 1.1.2 of HIDLibrary on 32bit XP Pro SP2. Now I use Vista Ultimate x64 and HidDevices.Enumerate() never returns a single device (always just an empty array).

I have seen other libraries not support 64bit in a similar way by using Int32 rather than IntPtr etc.

I'm not sure if it isnt working because I'm on Vista or because it is 64bit. Is there any chance of getting this library to work on Vista and/or 64bit?
George
Thursday, May 31, 2007 3:21:56 AM (GMT Standard Time, UTC+00:00)
Mike,
I'm using your library to access a USB Rocket Launcher from ThinkGeek, and I'm having timing issues. I need to poll and read the status of the device (which is only the first two bytes of whats returned). It seems that when I issue a read(), it is often sluggish, and sometimes takes over a second to respond, whereas other usb libraries I've tried had no problem(so its not the device). I need to poll about every 90 milliseconds. Any ideas?
Saturday, June 02, 2007 10:31:25 PM (GMT Standard Time, UTC+00:00)
Hi,

This libray is really great ....

However, when the software is trying to read (eg : InData = HidDevice.Read();) it crushes only ... I was wondering if it wouldn't be better to make it read whenever it has to instead .... ?

Or am I use it the wrong way ?
Eric
Monday, June 04, 2007 11:00:43 AM (GMT Standard Time, UTC+00:00)
Well, it seems I am missing something... The library seems very nice, but is there somewhere a doc with the functions and procedures available in it ? For example, on the lab page, it is written that functions to catch the plugged and unplugged events have been added, but how use them ?

(Sorry for my english)

Robert (France)
Robert
Thursday, June 21, 2007 11:17:34 AM (GMT Standard Time, UTC+00:00)
Mike

Just wanted to say thanks for making this code available. The HID driver for my Velleman card did not work under Vista but your pre-compiled library worked fine first time.

I've also downloaded your source and eventually to my great satisfaction got it to compile in VS2005 (my learning curve - not your code) so I can now debug right down at the lowest level.

Andrew Graham
Friday, July 06, 2007 12:30:26 PM (GMT Standard Time, UTC+00:00)
George/Mike,

I saw your entry on the Mike Obrien blog regarding the enumerate function returning an empty array. I am having a similar problem except I have deployed my web pages to an Win2K Server web server and it will not recognize any of my devices on the client machine which is XP Pro. It works great when I run from my localhost. Did you ever come up with a resolution? Is the HidLibrary calling windows APIs that only work for XP?

Thanks in advance for any thoughts you might have that could help me!!

Regards,
Kurt Staeudle
Kurt Staeudle
Sunday, July 08, 2007 9:39:08 AM (GMT Standard Time, UTC+00:00)
Still nothing, I assume the underlying library is different. I have not tried marshalling it myself or using it from C though.
George
Monday, July 09, 2007 12:58:42 PM (GMT Standard Time, UTC+00:00)
Thanks for your response George,

After working on this further I have found that I am able to populate webforms on a client machine only when I swipe from a device that is plugged in to the web server machine. The operating system issues are no longer a factor for me.

It is beginning to look like my web app will need to run all on one machine (i.e. the web server and the client are the same machine), unless I can figure a way to recognize a card swiper device attached to a client machine from my server-side code.

Does anyone know if the Device Path can be modified to look for a remote HID device?

Regards,
Kurt
Kurt Staeudle
Monday, September 03, 2007 12:01:52 AM (GMT Standard Time, UTC+00:00)
Hey guys, sorry for the silence! For some reason I'm not recieving email notification of comments. I'll try to make some time to look at your questions and post some comments.

m
Monday, September 17, 2007 6:18:38 PM (GMT Standard Time, UTC+00:00)
Hi Mike/George/Kurt,

I had this problem too up until two hours ago when I compiled to x86 systems to try it on my girlfriend's computer, and I got some stupid idea to try to run it on my Vista x64 system, and it worked!

So my advice to you is to try to compile it specifically for x86 systems and try if it works for you too under Vista x64.

Good luck and feel free to mail me if you have any problems!
Monday, September 24, 2007 6:32:57 AM (GMT Standard Time, UTC+00:00)
Is there a source code of the .dll in C#? What about any documentation of the methods we can call and their arguments?
Cyril
Monday, September 24, 2007 12:22:22 PM (GMT Standard Time, UTC+00:00)
Cyril,

Source is in VB.NET and can be found on the Labs page in the link above. No documentation, just a few examples on the Labs page. The IT4xxx implementation is a pretty good place to start.

m
Monday, September 24, 2007 3:08:11 PM (GMT Standard Time, UTC+00:00)
Ok. Thanks mob. Can anyone who has more info say anything about the methods we can call and their arguments?
Cyril
Friday, September 28, 2007 10:05:51 PM (GMT Standard Time, UTC+00:00)
Jonas, I have tried both 32 and 64 bit Vista and both enumerate to nothing when it works on XP.

I can't get anything to be found by using hid.dll and setupapi.dll directly either, but the same binary works on an XP machine fine.

The HID GUID appears the same on both the Vista and XP machines, though GUIDs in Vista's Device Manager to not match this GUID (those GUIDs find nothing either). Presumably this is all down to Vista's new driver model.

I haven't been able to find any resources whatsoever about communicating with HID on Vista. Does anyone know of any?

George
George
Friday, November 09, 2007 9:59:05 AM (GMT Standard Time, UTC+00:00)
Thanks for the great library, Mike!

In response to a few prior posts, I just wanted to say the following...

I downloaded this some time ago, with the intent to play around with it, and see what I could do with it. Since then, I've ported all the code to C#, made a few changes to the WinApi calls -- most of which allow the code to run under Vista x64 (and probably XP x64, although I've not tested it there) -- made a few optimizations to improve performance & enhancements to offer a few more features, and successfully used this to interface with a few HID input devices I have around my place: XBOX 360 controller, Wii remote, and a 3DConnexion SpaceNavigator (fun controller!). (I'm currently using this under Vista x86 without any problems.) The code is a bit messy, since it's still a WIP, but if anyone is interested I could clean it up and post a link to it at some point.

I did want to tell you, Mike, that your code really has provided a great springboard for me to take this in some other directions. Thanks a bunch!

Paul
Paul Miller
Friday, November 09, 2007 12:15:24 PM (GMT Standard Time, UTC+00:00)
I got it working on XP 32/64 and Vista 32/64 a few days ago (also in C#, I just started from scratch). So far I have not seen any other implementation online other than mine that works in 64bit Vista so well done Paul :)

In order to make hidlibrary work on these platforms you must change

SP_DEVICE_INTERFACE_DATA
Friend Reserved As Integer
to
Friend Reserved As IntPtr
as it is defined to be a ULONG_PTR

and also change the implementation of GetDevicePath, though you have done this completely differently to me so I am not entirely sure how it needs changing in hidlibrary.
The cbSize member of the SP_DEVICE_INTERFACE_DETAIL_DATA struct you pass into SetupDiGetDeviceInterfaceDetail must be 5 on 32bit and 8 on 64bit. I have not yet found an elegant solution for this.

I posted some code while asking for help that may be useful: http://www.codingforums.com/showthread.php?t=127218
George
Comments are closed.