开发者

Using .NET classes to communicate with a USB HID

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开发者_Python百科 use the Stream Class or StreamWriter and StreamReader but I don't know.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜