WPF USB设备采集开源工具介绍
最近项目需要需要试试采集电脑USB 设备信息 找到了 开源 示例 代码非常好 公共库也很友好 可能知名度太低 才4star
https://github.com/vurdalakov/usbdevices.git
示例图
代码结构
UsbDevicesDotNet是公共库
UsbDevicesViewer是WPF界面
别的是控制台测试
获取电脑所有USB设备信息
List<UsbDevice> UsbDevices = UsbDevice.GetDevices(new Guid(UsbDeviceWinApi.GUID_DEVINTERFACE_USB_DEVICE)).ToList()
设备事件
private Win32UsbControllerDevices win32UsbControllerDevices = new Win32UsbControllerDevices();
private DeviceManagementNotifications deviceManagementNotifications = new DeviceManagementNotifications(); private void EnableDeviceWatcher(Boolean enable)
{
if (enable)
{
this.win32UsbControllerDevices.DeviceConnected += OnWin32UsbControllerDevicesDeviceConnected;
this.win32UsbControllerDevices.DeviceDisconnected += OnWin32UsbControllerDevicesDeviceDisconnected;
//this.win32UsbControllerDevices.DeviceModified += OnWin32UsbControllerDevicesDeviceModified; this.win32UsbControllerDevices.StartWatcher(); this.deviceManagementNotifications.DeviceConnected += OnDeviceManagementNotificationsDeviceConnected;
this.deviceManagementNotifications.DeviceDisconnected += OnDeviceManagementNotificationsDeviceDisconnected; this.deviceManagementNotifications.Start(new Guid(UsbDeviceWinApi.GUID_DEVINTERFACE_USB_DEVICE));
}
else
{
this.deviceManagementNotifications.Stop(); //this.deviceManagementNotifications.DeviceConnected -= OnDeviceManagementNotificationsDeviceConnected;
//this.deviceManagementNotifications.DeviceDisconnected -= OnDeviceManagementNotificationsDeviceDisconnected; this.win32UsbControllerDevices.StopWatcher(); this.win32UsbControllerDevices.DeviceConnected -= OnWin32UsbControllerDevicesDeviceConnected;
this.win32UsbControllerDevices.DeviceDisconnected -= OnWin32UsbControllerDevicesDeviceDisconnected;
//this.win32UsbControllerDevices.DeviceModified -= OnWin32UsbControllerDevicesDeviceModified;
}
} /// <summary>
/// 设备插入事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnWin32UsbControllerDevicesDeviceConnected(object sender, Win32UsbControllerDeviceEventArgs e)
{
var _thisDevice = e.Device;
} /// <summary>
/// 设备拔出事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnWin32UsbControllerDevicesDeviceDisconnected(Object sender, Win32UsbControllerDeviceEventArgs e)
{
var _thisDevice = e.Device;
} /// <summary>
/// 设备管理器广播插入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnDeviceManagementNotificationsDeviceConnected(Object sender, DeviceManagementNotificationsEventArgs e)
{
var _DeviceClass = e.DeviceClass;
var _DevicePath = e.DevicePath;
}
/// <summary>
/// 设备管理器广播拔出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnDeviceManagementNotificationsDeviceDisconnected(Object sender, DeviceManagementNotificationsEventArgs e)
{
var _DeviceClass = e.DeviceClass;
var _DevicePath = e.DevicePath;
}
控制台示例
static void Main(string[] args)
{
UsbDevice[] usbDevices = UsbDevice.GetDevices(); Console.WriteLine("{0} USB devices:\n", usbDevices.Length); foreach (UsbDevice usbDevice in usbDevices)
{
Console.WriteLine("VID_{0}&PID_{1}", usbDevice.Vid, usbDevice.Pid);
Console.WriteLine("Hub:Port = {0}:{1}", usbDevice.Hub, usbDevice.Port);
Console.WriteLine("Device ID = {0}", usbDevice.DeviceId); foreach (var deviceInterface in usbDevice.Interfaces)
{
Console.WriteLine("Interface ID = {0}", deviceInterface.InterfaceId);
} Console.WriteLine("LocationInformation = {0}", usbDevice.GetRegistryPropertyValue(UsbDeviceWinApi.DeviceRegistryPropertyKeys.SPDRP_LOCATION_INFORMATION)); foreach (String locationPath in usbDevice.GetRegistryPropertyValue(UsbDeviceWinApi.DeviceRegistryPropertyKeys.SPDRP_LOCATION_PATHS) as String[])
{
Console.WriteLine("LocationPaths = {0}", locationPath);
} if (!String.IsNullOrEmpty(usbDevice.BusReportedDeviceDescription))
{
Console.WriteLine("DeviceDescription = {0}", usbDevice.BusReportedDeviceDescription);
} Console.WriteLine(); }
Console.ReadLine();
}
没有找到该示例的文档 全靠看demo 如果谁有文档还望 也给我一份
WPF USB设备采集开源工具介绍的更多相关文章
- 【转帖】四种BI 开源工具介绍-SpagoBI,openI,JasperSoft,Pentaho
四种BI 开源工具介绍-SpagoBI,openI,JasperSoft,Pentaho 1 BI系统的简述 从技术角度来说 BI 包含了 ETL.DW.OLAP.DM等多环节.简单的说就是把交易系统 ...
- USB 设备的PID-Product ID,VID-Vendor ID
根据USB规范的规定,所有的USB设备都有供应商ID(VID)和产品识别码(PID),主机通过不同的VID和PID来区别不同的设备,VID 和PID都是两个字节长,其中,供应商ID(VID)由供应商向 ...
- USB系列之一:列出你的USB设备
USB现在已经成为PC机必不可少的接口之一,几乎所有的设备都可以接在USB设备上,USB键盘.鼠标.打印机.摄像头,还有常用的U盘等等,从本篇文章开始,将集中篇幅介绍一下在DOS中使用USB设备的方法 ...
- 利用谷歌开源工具cAdvisor 结合influxdb存储+Grafana前端展示进行Docker容器的监控
一.Docker 监控方式 1.利用docker 的 docker stats API 命令: docker stats [容器ID/容器名称] [root@docker ~]# docker sta ...
- 《连载 | 物联网框架ServerSuperIO教程》- 14.配制工具介绍,以及设备驱动、视图驱动、服务实例的挂载
注:ServerSuperIO二次开发套件授权码申请---截止到:2016-12-09 1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架Server ...
- Linux单设备多路USB串口的实现方法介绍
某设备需要提供多路USB串口的功能给主机端使用,比如一路用作业务1通信功能,一路用作业务2通信功能,一路用作debug抓log用途,诸如此类.如下图所示. 要实现上述设备功能,可以参考如下步骤. 1) ...
- 13个优秀的开源UML工具介绍
本文将为您介绍12个优秀的UML工具: 1. StarUML StarUML(简称SU),是一种创建UML类图,是一种生成类图和其他类型的统一建模语言(UML)图表的工具.StarUML是一个开源项目 ...
- vmware 桌面虚拟化 horizon view 介绍(使用微软的RDP协议或vmware 专有的PCoIP协议,连接到虚拟桌面,并且可以使用本地的USB设备、本地存储)
虚拟化(一):虚拟化及vmware产品介绍 虚拟化(二):虚拟化及vmware workstation产品使用 虚拟化(三):vsphere套件的安装注意及使用 虚拟化(四):vsphere高可用功能 ...
- Monkey 命令收集相关 --追加Monkey自动化测试开源工具
.1.环境配置 MONKEY测试使用的是ADB命令,因此只需要配置ADB环境即可. 2.测试准备与执行 在Monkey测试前,必须进行以下准备 Ø 手机屏幕超时设置为30分钟或者永不超时,防止手机进 ...
随机推荐
- Oracle的功能性sql
--创建表空间 CREATE TABLESPACE FSNEW DATAFILE 'E:\oracle\oracledata\oradata\FSNEW' SIZE 30G EXTENT MANAGE ...
- 160--Intersection Of Two Linked List
public class IntersectionOfTwoLinkedList { /* 解法一:暴力遍历求交点. 时间复杂度:O(m*n) 空间复杂度:O(1) */ public ListNod ...
- Python之虚拟环境
场景:本地开发环境使用不同版本的包进行不同项目开发 总结:Linux通过配置环境变量来进行虚拟环境的切换,而Windows要通过虚拟环境目录下的Scripts的activate和deactivate进 ...
- json转dataframe格式
方法1:利用pandas自带的read_json直接解析字符串 方法2:利用json的loads和pandas的json_normalize进行解析 方法3:利用json的loads和pandas的D ...
- nginx访问jupyter
现在jupyter已通过k8s安装完成,并通过nodeport暴露出来. 如果不能直接访问这个nodeport(像我在的公司)或是希望能组织好jupyter实例, 那应该如何调通呢? 这里包括两个技术 ...
- vue - 基础(3)
1.数据的双向绑定 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...
- centos安装安全狗提示Need system command 'locate' to install safedog for linux的解决方法
今天为客户的centos服务器安装安全狗时提示Need system command 'locate' to install safedog for linux.Installation aborte ...
- 【电脑】xshell报:需要Xmanager软件来处理X11转发请求
https://www.netsarang.com/zh/xmanager/ 下载了就好了 我的图片出不来,下了就好了.
- Ant Design Pro 鉴权/ 权限管理
https://pro.ant.design/docs/authority-management-cn ant-design-pro 1.0.0 V4 最近需要项目需要用扫码登录,因此就使用antd ...
- vue文件夹上传组件选哪个好?
一. 功能性需求与非功能性需求 要求操作便利,一次选择多个文件和文件夹进行上传:支持PC端全平台操作系统,Windows,Linux,Mac 支持文件和文件夹的批量下载,断点续传.刷新页面后继续传输. ...