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分钟或者永不超时,防止手机进 ...
随机推荐
- eclipse IDE 32位汉化方法及常用软件汉化包寻找办法
今天听说小组开发人员遇到安装eclipse不能汉化问题.了解到其他同事用的都是64位操作系统,这个同事用的32位系统.通常情况下常用软件都有各路大神发的成熟汉化包,不会出现无法安装汉化包的情况. 先找 ...
- SpringBoot 定时任务篇
一. 基于注解@Scheduled默认为单线程,开启多个任务时,任务的执行时机会受上一个任务执行时间的影响. 1.创建定时器 使用SpringBoot基于注解来创建定时任务非常简单,只需几行代码便可完 ...
- vuex的简单总结使用
State负责存储整个应用的状态数据,一般需要在使用的时候在跟节点注入store对象,后期就可以使用this.$store.state直接获取状态 辅助函数的使用 1.mapState state的m ...
- javascript中 encodeURIComponent() 与 encodeURI() 的区别
前言:js 中仅有的几个全局函数中,有两个全局函数可以用来编码url 字符串. 一.encodeURIComponent() 将转义用于分隔 URI 各个部分的标点符号 ,也就是可以编码 " ...
- 【数位DP】【P4317】花神的数论题
[数位DP][P4317]花神的数论题 Description 给定 \(n\),求 \(n\) 以内所有正整数二进制下 \(1\) 的个数的乘积,答案对 \(10^7 + 7\) 取模 Limita ...
- javaScript与css、html常见的兼容
最近几天总是遇到兼容问题,就整理了一下javaScript和html.css出现的常见兼容.有不全面或不对的欢迎大家指正.也希望这条博客可以帮到一些刚学习的前端的朋友. 一.javaScript出现的 ...
- zabbix php-fpm监控
#!/bin/bash################################### Zabbix monitoring script## php-fpm:# - anything avail ...
- java报错:The reference to entity "characterEncoding" must end with the ';' delimiter.
java关于报错:The reference to entity "characterEncoding" must end with the ';' delimiter. Java ...
- linux 系统时间 EST CST
早上本来要做一些实验的,基于时间的.date 查看时间,发现时间不对.用 pool.ntp.org 去同步发现时间还是一样的,并且没有报错.如是开启另外一台时间对的linux服务器进行对比.发现一个是 ...
- 在GitHub中创建目录
需求:假定我们需要在 Answer 目录下创建一个目录 [注]GitHub无法单独创建一个空目录,但是可以在创建一个文件的同时创建它的所属目录 1.点击进入所需的目录 Answer 2.点击“Crea ...