介绍
小编给大家分享一下c#怎么使用LibUsbDotNet实现USB通信,希望大家阅读完这篇文章后大所收获、下面让我们一起去探讨吧!
1。下载并安装LibUsbDotNet安装文件。
2。运行过滤向导,安装一个装置过滤器。安装需要通信的usb设备。
3。建一个简单的控制台项目,进行测试,下图为打印需要通信设备的信息。
相关代码:
引用
; 使用LibUsbDotNet.Main; 使用LibUsbDotNet.Info;
PrintUsbInfo
公共静态孔隙PrintUsbInfo () { UsbDevice UsbDevice=零; UsbRegDeviceList allDevices=UsbDevice.AllDevices; Console.WriteLine (“{0} devices", allDevices.Count); foreach (UsbRegistry UsbRegistry allDevices) { Console.WriteLine(“有设备:{0}\ r \ n", usbRegistry.FullName); 如果(usbRegistry。打开(usbDevice)) { Console.WriteLine(“设备信息\ r \ n - - - - - - - - - - - - - - - - - -“); Console.WriteLine (“{0}”, usbDevice.Info.ToString ()); Console.WriteLine (“VID和;PID: {0} {1}“usbDevice.Info.Descriptor。VendorID usbDevice.Info.Descriptor.ProductID); Console.WriteLine (“\ r \ n \ r \ nDevice配置- - - - - - - - - - - - - - - - - - - - - -“); foreach (UsbConfigInfo UsbConfigInfo usbDevice.Configs) { Console.WriteLine (“{0}”, usbConfigInfo.ToString ()); Console.WriteLine (“\ \ nDevice接口列表\ r \ n - - - - - - - - - - - - - - - - - - -产生绯闻;); ReadOnlyCollectioninterfaceList=usbConfigInfo.InterfaceInfoList; foreach (UsbInterfaceInfo UsbInterfaceInfo interfaceList) { Console.WriteLine (“{0}”, usbInterfaceInfo.ToString ()); Console.WriteLine (“\ \ nDevice端点列表\ r \ n - - - - - - - - - - - - - - - - - - - - - -“); ReadOnlyCollection endpointList=usbInterfaceInfo.EndpointInfoList; foreach (UsbEndpointInfo UsbEndpointInfo endpointList) { Console.WriteLine (“{0}”, usbEndpointInfo.ToString ()); } } } usbDevice.Close (); } Console.WriteLine (“\ r \ n - - - - - -设备信息结束- - - - - - \ r \ n"); } }
调用
公共静态void Main (string [] args) { PrintUsbInfo ();//等待用户输入。 Console.ReadKey (); }
看完了这篇文章,相信你对c#怎么使用LibUsbDotNet实现USB通信有了一定的了解,想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!