26

Is there an API in .NET (C#) for using USB HID (human interface) devices?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jco
  • 1,335
  • 3
  • 17
  • 29
  • Duplate question: http://stackoverflow.com/questions/68749/working-with-usb-devices-in-net – Morten Frederiksen Mar 20 '12 at 18:07
  • 1
    Not totally a duplicate -- this question deals with HID (which I'm assuming means "driverless" HID), so the answers to the other question don't all apply to this one. – HanClinto Oct 03 '12 at 17:58
  • No - HID actually means all existing or yet not invented devices that humans may interact with or not interact soo much. Let it be a temp sensor or a button or a colorimeter. Some data in, some out (low amounts) – Robetto Apr 20 '16 at 13:05
  • Yep. https://github.com/MelbourneDeveloper/Hid.Net . It supports .Net Core, Framework, Android, and UWP. – Christian Findlay Aug 15 '18 at 06:54

8 Answers8

11

HidLibrary wraps up all the P/Invoke calls for you. But no, it doesn't look there are any nice framework APIs for dealing with USB devices.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jake Almer
  • 668
  • 8
  • 15
  • 4
    +1 for HidLibrary; I was starting to go down the road of rolling my own C# wrapper lib for the kernal32 and hid.dlls. HidLibrary has already done the hard work (mostly) and provides a clean, simple API at that. Got me up and running amazingly fast (like, minutes). And you can install it with nuget, which is nice. There are other c# hid.dll wrapper libs out there, but nothing quite so clean that I've seen. – ptrandem Nov 17 '12 at 00:16
  • 1
    That library is no longer supported. – tarabyte May 15 '14 at 17:04
  • HidLibrary is Windows only. Device.Net supports Hid and USB on Android, Windows, and UWP. https://github.com/MelbourneDeveloper/Device.Net – Christian Findlay Jan 18 '19 at 08:47
4

Here's mine little library for dealing with HID devices.

It might be useful, especially when you are trying to communicate using raw HID reports. I've also included a simple demonstration of how to use it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
3

There's nothing direct or high-level. There are some things you can do through the managed WMI API, but I've personally found a lot of WMI interaction with hardware to be cryptic at best and requiring a lot of trial-and-error to get it to do what you want.

Someone on The Code Project has developed a .NET component for USB HID you can try out that's probably going to fit the bill better than WMI.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tim Trout
  • 1,062
  • 12
  • 20
2

I would suggest you follow this example instead. It was invaluable in getting me up and running with HiD dev in C#.

Zachary Yates
  • 12,966
  • 7
  • 55
  • 87
Dark Star1
  • 6,986
  • 16
  • 73
  • 121
1

I suggest you start here: http://wiimotelib.codeplex.com/

unclepaul84
  • 1,404
  • 8
  • 15
1

Take a look at this library on Google Code:

C# USB HID driver

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paccc
  • 1,211
  • 13
  • 15
1

Try looking at this: Simple HID Library. The main page has a list of other open source libraries.

Morten Frederiksen
  • 5,114
  • 1
  • 40
  • 72
0

I was also searching for it. I'm using the code I found here: http://janaxelson.com/hidpage.htm