views:

331

answers:

2

Are there any USB developers out there who use .NET?

I know one way of communicating with USB HID device is creating wrappers to the Windows API's like CreateFile, WriteFile and ReadFile. But I am wondering does anyone know if you can use any of the .NET classes to do the same thing. I am certain that I will still have to use some of the API's for operations like detecting which devices are on the bus and requesting the dectriptors but I am looking for a .NET method of sending/receiving reports? I am thinking, for example, that I could use the Stream Class or StreamWriter and StreamReader but I don't know.

+1  A: 

The System.IO.FileStream class is a highly suitable replacement. Its constructor calls CreateFile(), its Read method calls ReadFile(), its Write method calls WriteFile(). You should have little trouble matching the FileAcces, FileMode and FileShare enums to the corresponding CreateFile() arguments. You will however have to P/Invoke the SetupAPI functions.

Hans Passant
The path to the device returned by the SetupAPI functions looks like this "\\\\?\\hid#vid_0461 I get an error saying illegal characters in path.
Jordan S
Ouch, yes, the ? character doesn't pass a check on the path by the FileIOPermission class. Bit of a bug there, although it would be hard to do otherwise. P/Invoking CreateFile is your lot, you can still use FileStream through the FileStream(SafeFileHandle, FileAccess) constructor.
Hans Passant
I tried this for a bit but didn't have much luck. There are still a lot of HID API's that I needed to make wrappers for anyways so I just bit the bullet and gave up on FileStream...
Jordan S
A: 

Probably have more luck using a library that wraps all the P/Invoke calls for you. One I've looked at is HidLibrary.

karnqu