Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

FileStream is working well enough for me, though mine is a very simple USB implementation.

I use CreateFile to initially set up the device,but then do all the reading and writing to the device through the FileStream object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top