views:

2142

answers:

5

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).

Is there a native .Net solution to do this?

+6  A: 

The #usblib USB Library for .NET

moobaa
Looks like it depends on libusb. Is there anyway to do this without that kind of dependency ?
David Thibault
A: 

Most USB chipsets come with drivers. Silicon Labs has one.

Nick
This way I have a dependency on the driver itself? Is there a generic solution that will work on all machines?
David Thibault
You will have a dependency on both the dll and a hardware dependency on the chipset used. However, this is the quickest way to get up and running with USB communication if you have control over both the software and the hardware.
Nick
+9  A: 

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.

Jon Limjap
+1  A: 

There is a generic toolkit WinDriver for writing USB Drivers in user mode that support #.NET as well

Ilya
+3  A: 

I've tried using SharpUSBLib and it screwed up my computer (needed a system restore). Happened to a friend of mine 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).

Sofox
Awesome, thanks!
David Thibault