Using .Net (C#), how can you work with USB devices?
How can you detect USB events (connections/disconnections) and how do you communicate with devices (read/write).
I tried several of these suggestions with no luck. I ended up writing a working solution using Java and the hid4java library. As a console app I can shell out to it from C# using Process.Start()
, passing parameters as well as reading responses. This provides basic HID I/O but without connect/disconnect events. For that I'd need to rewrite it to run as a daemon/service and use named pipes or some other server/client transport. For now, it's enough to get the job done since the hi4java library "just works".
There is a generic toolkit WinDriver for writing USB Drivers in user mode that support #.NET as well
I've tried using SharpUSBLib and it screwed up my computer (needed a system restore). Happened to a coworker on the same project too.
I've found an alternative in LibUSBDotNet: http://sourceforge.net/projects/libusbdotnet Havn't used it much yet but seems good and recently updated (unlike Sharp).
EDIT: As of mid-February 2017, LibUSBDotNet was updated about 2 weeks ago. Meanwhile SharpUSBLib has not been updated since 2004.
I'd recommend LibUSBDotNet, the library I have been using for 2 years. If you have to work with an USB device (send requests, process responses), this library was the best solution I could find.
Pros:
Cons:
There is no native (e.g., System libraries) solution for this. That's the reason why SharpUSBLib exists as mentioned by moobaa.
If you wish to roll your own handler for USB devices, you can check out the SerialPort class of System.IO.Ports.
The #usblib USB Library for .NET