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分钟或者永不超时,防止手机进 ...
随机推荐
- Shell 编程 正则表达式
本篇主要写一些shell脚本正则表达式的使用基础. 概述 正则表达式分为基础正则表达式(Regular Expression)与扩展正则表达式(Extended Regular Expression) ...
- Java--8--新特性--串并行流与ForkJoin框架
并行流就是把一个内容分成多个数据块,并用不同的线程分别处理每个数据块的流.穿行流则相反,并行流的底层其实就是ForkJoin框架的一个实现. 那么先了解一下ForkJoin框架吧. Fork/Join ...
- Linux使用pt-archiver工具自动备份MySQL
操作系统: CentOS 6.9 脚本语言: shell https://github.com/iscongyang/Practical/blob/master/shell-scripts/pt-ar ...
- Jupyter Notebook 更换主题(背景、字体)
通过命令行窗口或 Anaconda Prompt 窗口 1.安装 Jupyter 主题 pip install jupyterthemes 2.更新 Jupyter 主题 (可选) pip insta ...
- generator 1(2019年牛客多校第五场B题+十进制矩阵快速幂)
目录 题目链接 思路 代码 题目链接 传送门 思路 十进制矩阵快速幂. 代码 #include <set> #include <map> #include <deque& ...
- org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next tok
org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next tokenfound character ‘@’ th ...
- unity texture贴图纹理
文章内一些内容引用自作者:Aimar_Johnny http://blog.csdn.net/lzhq1982/article/details/75045358 导入png图片,默认显示如下 Text ...
- android 判断是否真正连接到internet(通过检测网址,需要时间)
if (InetAddress.getByName("www.xy.com").isReachable(timeout)) { } else { }
- 03-docker入门-创建 docker 镜像
方法1:从运行的容器创建方法2:编写 DockFile 文件创建 方法1: 打包镜像 docker commit -m "Test a change" 610 ubuntu:tes ...
- selenium webdriver使用的一些小技巧(持续更新中)
1.开始结束时间只支持控件选择,不支持填写,怎么办? 如下图: 解决方案: 用javaScipt把开始结束时间的reaonly属性去除,然后再输入,举例如下 /** * 输入开始日期 ...