具体代码如下

#!/usr/bin/python
# -*- coding:utf-8 -*- import sys
import usb.core
# find USB devices
dev = usb.core.find(find_all=True)
# loop through devices, printing vendor and product ids in decimal and hex
for cfg in dev:
sys.stdout.write('Decimal VendorID=' + str(cfg.idVendor) + ' & ProductID=' + str(cfg.idProduct) + '\n')
sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + '\n\n')

测试结果如下

键盘有插入时usb的情况

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
================== RESTART: C:/Users/libra/Desktop/1111.py ==================
Decimal VendorID=32902 & ProductID=35878
Hexadecimal VendorID=0x8086 & ProductID=0x8c26 Decimal VendorID=32902 & ProductID=35885
Hexadecimal VendorID=0x8086 & ProductID=0x8c2d Decimal VendorID=1133 & ProductID=49948
Hexadecimal VendorID=0x46d & ProductID=0xc31c Decimal VendorID=1266 & ProductID=46001
Hexadecimal VendorID=0x4f2 & ProductID=0xb3b1 Decimal VendorID=7247 & ProductID=81
Hexadecimal VendorID=0x1c4f & ProductID=0x51 Decimal VendorID=32903 & ProductID=32768
Hexadecimal VendorID=0x8087 & ProductID=0x8000 Decimal VendorID=32903 & ProductID=32776
Hexadecimal VendorID=0x8087 & ProductID=0x8008 Decimal VendorID=32902 & ProductID=35889
Hexadecimal VendorID=0x8086 & ProductID=0x8c31

键盘问插入时usb的情况

================== RESTART: C:/Users/libra/Desktop/1111.py ==================
Decimal VendorID=32902 & ProductID=35878
Hexadecimal VendorID=0x8086 & ProductID=0x8c26 Decimal VendorID=32902 & ProductID=35885
Hexadecimal VendorID=0x8086 & ProductID=0x8c2d Decimal VendorID=1266 & ProductID=46001
Hexadecimal VendorID=0x4f2 & ProductID=0xb3b1 Decimal VendorID=7247 & ProductID=81
Hexadecimal VendorID=0x1c4f & ProductID=0x51 Decimal VendorID=32903 & ProductID=32768
Hexadecimal VendorID=0x8087 & ProductID=0x8000 Decimal VendorID=32903 & ProductID=32776
Hexadecimal VendorID=0x8087 & ProductID=0x8008 Decimal VendorID=32902 & ProductID=35889
Hexadecimal VendorID=0x8086 & ProductID=0x8c31

利用pyusb来查询当前所以usb设备的更多相关文章

  1. 利用mass storage class 做免驱动usb设备.

    当需要使用usb bulk传输,想让设备像串口通讯那样和PC主机通信, 通常需要自己做一个PC端的驱动,比较麻烦. 为避免在pc上编写usb设备驱动的麻烦,可以将设备做成mass storage 类的 ...

  2. C#:基于WMI查询USB设备信息 及 Android设备厂商VID列表

    /* ---------------------------------------------------------- 文件名称:WMIUsbQuery.cs 作者:秦建辉 MSN:splashc ...

  3. C#:基于WMI查询USB设备

    来源:http://blog.csdn.net/jhqin/article/details/6734673 /* ------------------------------------------- ...

  4. windodws pyusb hub端口对应连接的usb设备

    源码: 1 #!/usr/bin/python 2 import sys 3 import usb.core 4 # find USB devices 5 dev = usb.core.find(fi ...

  5. Ubuntu/Windows下利用“HIDAPI”库函数实现与Hid类USB设备通信

    一.背景: 最近在做的一个项目需要使用USB传递数据,对USB理解不是很深,USB的系统驱动编写则更是天方 夜谭,因此将设备配置成HID类设备成为了首选.其最大的好处在于,LINUX/Windows系 ...

  6. Linux下usb设备驱动详解

    USB驱动分为两块,一块是USB的bus驱动,这个东西,Linux内核已经做好了,我们可以不管,我们只需要了解它的功能.形象的说,USB的bus驱动相当于铺出一条路来,让所有的信息都可以通过这条USB ...

  7. 《Linux总线、设备与驱动》USB设备发现机制

    说明:本分析基于mstar801平台Linux2.6.35.11内核,其他内核版本仅供参考. 一.程序在内核中的位置 1.usb host做为pci总线下的一个设备存在(嵌入式系统中有可能也会直接挂在 ...

  8. 嵌入式Linux驱动学习之路(二十)USB设备驱动

    USB在接入系统的时候,以0的设备ID和主机通信,然后由主机为其分配新的ID. 在主机端,D+和D-都是下拉接地的.而设备端的D-接上拉时,表明此设备为高速设备:12M/s. D+接上拉时则是全速设备 ...

  9. C#:USB设备枚举 --转自CSDN作者:Splash

    (一)DeviceIoControl的PInvoke /* ---------------------------------------------------------- 文件名称:Device ...

随机推荐

  1. JPanel添加键盘监听事件

    因为在自己的游戏需求中谢了要用键盘控制飞机的移动,所以用到键盘监听事件,但是使用了JPanel之后添加了键盘监听事件,按相应的方向键飞机并没有反应.但是如果是为JFrame的内容面板加则会有反应. 为 ...

  2. MFC程序显示控制台输出

    有的时候,我们用c写的一些东西,可能需要MFC作为UI输入参数进行测试,但是程序里有大量的printf操作,这就需要MFC程序启动的时候同时打开 一个控制台,用于标准输出 查询网络,大致方法有以下两种 ...

  3. Python 里面什么时候用一个=,什么时候用两个=

    赋值用=                                                                   i != j != k   >>>> ...

  4. stopPropagation()阻止事件的冒泡传递

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  5. 字符串全部转换为大写用str.toUpperCase()方法

    var message="Hello world!"; var x=message.toUpperCase();

  6. IDC:IDC 清单

    ylbtech-IDC:IDC 清单 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部     6.返回顶部   作者:ylbtech出处:http://ylbte ...

  7. [ZZ]面向对象编程,再见!

    面向对象编程,再见!- 机器学习算法与自然语言处理 https://mp.weixin.qq.com/s/icXBlVOOYLvDnER7cEeCeg https://medium.com/@csca ...

  8. jQuery 事件的命名空间简单了解

    原文地址:http://www.jb51.net/article/43626.htm   用 jQuery 绑定和解绑事件监听器都是非常简单的,怎样精确地解绑其中一个监听器?我们需要了解一下事件的命名 ...

  9. windows修改远程桌面端口3389

    regedit 按照路径打开,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-T ...

  10. 一次mysql数据关于union+concat用法的记录

    SELECT CONCAT('SELECT COUNT(*) FROM ',table_name,' union all') FROM information_schema.tables WHERE ...