C#下操作USB设备的方法
想必大家对LibUSB不陌生,没错,它就是很有名的开源usb驱动,其提供的API可以很方便的操作linux或者WIN下的USB设备,非常的方便!但是libusb是基于c语言的,那么在C#下是不是就不能使用libusb呢?当然不是了,你完全可以把libusb提供的dll封装成自己的C#库,但是这个工作量是非常大的而且调试的过程中肯定会有些意想不到的事情发生,那么在C#下该如何使用libusb呢,下面介绍C#下的强大的开源USB类库就登场了:LibUSBDotNet,没错就是.NET下的libusb,这也是个开源项目,已经把libusb封装成了一个完整的类库,可以去下面链接下载:
http://download.csdn.net/detail/cumtwys/7713473(CSDN不要分)
或者
http://sourceforge.net/projects/libusbdotnet/(官方)
它是sourceforge上的一个开源项目,下载WIN下的EXE安装即可,里面包含了很多的范例,还有说明文档(CHM格式的,超级方便的)。
下面简单介绍一下该如何使用LibUSBDotNet。
1、首先你需要创建一个C#的应用程序(控制台、窗体都可以)
2、将LibUsbDotNet安装目录下Src目录下LibWinUsb拷贝一份到你的工程根目录下
3、不需要多说了吧,在你的解决方案上右击,添加现有项目,将LibWinUsb目录下的项目包含进来
4、在你的项目上右击,添加引用,选择LibUSBDotNet项目,如下图:
5、在你的CS文件开头,添加引用:
6、下面提供一个读取数据的范例(摘自CHM说明文档)
7、怎么样简单吧,方便吧,并且安装目录下有个驱动文件自动生成器,非常的好用就是InfWizard.exe,这是个驱动生成向导,对于开发自己的USB设备需要写WIN驱动的时候完全可以考虑使用LIBUSB来做驱动,那么使用这个工具你的工作量会在一分钟之内搞定,太强大了……
from: http://blog.csdn.net/cumtwys/article/details/38371419
更多推荐
所有评论(0)