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分钟或者永不超时,防止手机进 ...
随机推荐
- ssh实现无密码登陆
参考教程:https://linux.cn/article-5444-1.html 1.假设你有一台主机A(ip:111.111.111.111),用户名为server123,想无密码登陆到主机B(1 ...
- Designing Data-Intensive Applications笔记
<Designing Data-Intensive Applications>书看完很久了,前段时间陈皓来公司技术分享也推荐了这本书.读起来酣畅淋漓,写篇系统总结的意愿强烈,无耐内容属实太 ...
- javascript之DOM(四其他类型)
一.Text类型 文本节点由Text类型表示,指的是可以以字面意思解释的纯文本内容,其中包含HTML代码. nodeType=3 nodeName=#text nodeValue=文本内容 paren ...
- 《linux就该这么学》课堂笔记20 LNMP架构部署动态网站环境
源码包安装程序 使用源码包来安装服务程序具有两个优势. 源码包的可移植性非常好,几乎可以在任何Linux系统中安装使用,而RPM软件包是针对特定系统和架构编写的指令集,必须严格地符合执行环境才能顺利安 ...
- 二十、Python与Mysql交互
先安装一个python与MySQL交互的包:MySQL-python $ gunzip MySQL-python-1.2.2.tar.gz $ tar -xvf MySQL-python-1.2.2. ...
- CentOS7下firewall-cmd防火墙使用
一. firewalld的基本使用启动: systemctl start firewalld查状态:systemctl status firewalld 停止: systemctl disable f ...
- CSS伪类选择器:is、not
本文介绍一下Css伪类:is和:not,并解释一下is.not.matches.any之前的关系 :not The :not() CSS pseudo-class represents element ...
- centos安装安全狗提示Need system command 'locate' to install safedog for linux的解决方法
今天为客户的centos服务器安装安全狗时提示Need system command 'locate' to install safedog for linux.Installation aborte ...
- NOIP 2008 火柴棒等式
洛谷 P1149 火柴棒等式 洛谷传送门 JDOJ 1540: [NOIP2008]火柴棒等式 T2 JDOJ传送门 Description 给你n根火柴棍,你可以拼出多少个形如"A+B=C ...
- 【数位DP】【P4317】花神的数论题
[数位DP][P4317]花神的数论题 Description 给定 \(n\),求 \(n\) 以内所有正整数二进制下 \(1\) 的个数的乘积,答案对 \(10^7 + 7\) 取模 Limita ...