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分钟或者永不超时,防止手机进 ...
随机推荐
- CentOS 8 安装
截止目前为止CentOS的最新版本为CentOS 8版本,接下来就介绍CentOS Linux 8.0.1905的安装过程 1. 安装CentOS 8 成功引导系统会显示如上图的界面: # 界面说明 ...
- 【JavaScript】内部与外部引入方式
1.内部引入方式: script的type属性默认为"text/javascript",可以不写 <script type="text/javascript&quo ...
- Fiddler抓包设置
介绍 Fiddler 在 PC 端和移动端,模拟器抓取数据包 Fiddler抓取PC端数据包: 这里 Fiddler 抓取网页客户端的数据包时,其原理就是在 客户端/浏览器 和 服务器端 之间,加上了 ...
- C++ 梳理:跑通简单程序
C++ 结合了三个编程流派: 过程式编程:C 特性,结构化语言,强调过程 面向对象编程:C++ 对于 C 语言的补充,一切皆对象,强调数据 泛型编程(generic programming):由 C+ ...
- 用 Splashtop Wired XDisplay HD 让 ipad做电脑扩展屏幕__亲测有效
参考: [1]https://blog.csdn.net/Tang_Chuanlin/article/details/86433152
- 201671030113 李星宇 实验十四 团队项目评审&课程学习总结
项目 内容 所属课程 [所属课程(https://www.cnblogs.com/nwnu-daizh/) 作业要求 作业要求 课程学习目标 (1)掌握软件项目评审会流程:(2)反思总结课程学习内容 ...
- 2019牛客国庆day3-G &CF1238E
牛客G: 给定大小为N的数组a[],给定M组关系,让你重排a[],使得sum{M队关系的绝对值之差}最小.首先将a排序,然后依次把a填入数组. 假设i在二进制下有x个1,用dp[i]更新dp[i|(1 ...
- 15-cmake语法-math
math 数学表达式 math(EXPR <output variable> <math expression>) 例子: math(EXPR VAR "${VAR} ...
- jdk,jre,jvm,openJdk
1,jdk install: java_home: point to the installation directory of JDK, which is used by some java dev ...
- SPA项目开发之登录注册
CMD安装所需要的pom依赖 npm install element-ui -S npm install axios -S npm install qs -S npm install vue-axio ...