具体代码如下

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

测试结果如下

键盘有插入时usb的情况

  1. Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
  2. Type "copyright", "credits" or "license()" for more information.
  3. >>>
  4. ================== RESTART: C:/Users/libra/Desktop/1111.py ==================
  5. Decimal VendorID=32902 & ProductID=35878
  6. Hexadecimal VendorID=0x8086 & ProductID=0x8c26
  7.  
  8. Decimal VendorID=32902 & ProductID=35885
  9. Hexadecimal VendorID=0x8086 & ProductID=0x8c2d
  10.  
  11. Decimal VendorID=1133 & ProductID=49948
  12. Hexadecimal VendorID=0x46d & ProductID=0xc31c
  13.  
  14. Decimal VendorID=1266 & ProductID=46001
  15. Hexadecimal VendorID=0x4f2 & ProductID=0xb3b1
  16.  
  17. Decimal VendorID=7247 & ProductID=81
  18. Hexadecimal VendorID=0x1c4f & ProductID=0x51
  19.  
  20. Decimal VendorID=32903 & ProductID=32768
  21. Hexadecimal VendorID=0x8087 & ProductID=0x8000
  22.  
  23. Decimal VendorID=32903 & ProductID=32776
  24. Hexadecimal VendorID=0x8087 & ProductID=0x8008
  25.  
  26. Decimal VendorID=32902 & ProductID=35889
  27. Hexadecimal VendorID=0x8086 & ProductID=0x8c31

键盘问插入时usb的情况

  1. ================== RESTART: C:/Users/libra/Desktop/1111.py ==================
  2. Decimal VendorID=32902 & ProductID=35878
  3. Hexadecimal VendorID=0x8086 & ProductID=0x8c26
  4.  
  5. Decimal VendorID=32902 & ProductID=35885
  6. Hexadecimal VendorID=0x8086 & ProductID=0x8c2d
  7.  
  8. Decimal VendorID=1266 & ProductID=46001
  9. Hexadecimal VendorID=0x4f2 & ProductID=0xb3b1
  10.  
  11. Decimal VendorID=7247 & ProductID=81
  12. Hexadecimal VendorID=0x1c4f & ProductID=0x51
  13.  
  14. Decimal VendorID=32903 & ProductID=32768
  15. Hexadecimal VendorID=0x8087 & ProductID=0x8000
  16.  
  17. Decimal VendorID=32903 & ProductID=32776
  18. Hexadecimal VendorID=0x8087 & ProductID=0x8008
  19.  
  20. Decimal VendorID=32902 & ProductID=35889
  21. 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. Hadoop错误集:Journal Storage Directory not formatted

    类型一: 当你从异常信息中看到JournalNode not formatted,如果在异常中看到三个节点都提示需要格式化JournalNode. 如果你是新建集群,你可以重新格式化NameNode, ...

  2. 计时器setTimeout()

    setTimeout()计时器,在载入后延迟指定时间后,去执行一次表达式,仅执行一次. 语法: setTimeout(代码,延迟时间); 参数说明: 1. 要调用的函数或要执行的代码串. 2. 延时时 ...

  3. 使用Softmax回归将神经网络输出转成概率分布

    神经网络解决多分类问题最常用的方法是设置n个输出节点,其中n为类别的个数.对于每一个样例,神经网络可以得到一个n维数组作为输出结果.数组中的每一个维度(也就是每一个输出节点)对应一个类别,通过前向传播 ...

  4. 廖雪峰Java1-2程序基础-9数组

    数组初识 1.数组的特点: 数组所有元素初始化默认值,int默认值为0 数组创建后大小不可改变 数组索引从0开始 数组是引用类型 使用索引下标访问数组元素,索引超出范围会报错 2.数组的定义: 类型[ ...

  5. 关于ros里ppp拨号隧道比如pptp,l2tp,sstp等等,造成多条路由,ospf的时候需要汇总为一条宣告的解决方案

    官方解决方案: https://wiki.mikrotik.com/wiki/OSPF_and_PPPoE_Setup 实际解决步骤: So to get rid of /32 routes * on ...

  6. Jmeter(十八)Logic Controllers 之 Random Controller and Random order Controller

    Random Controller就比较简单了,完全随机!毫无章法. 毫无任何规律的运行. 还有一个Random order Controller,随机顺序控制器就像一个简单的控制器,它将最多执行一次 ...

  7. ajax的跨域解决方案(java+ajax)

    简单的建立一个后台项目 新建servlet: 内容如下: package a; import java.io.IOException; import java.io.PrintWriter; impo ...

  8. OpenJudge 兔子与樱花

    [题解] 求任意两点间的最短路径.此题数据量较小,用Floyd算法,时间复杂度为O(n^3). 参考https://blog.csdn.net/qq_34594236/article/details/ ...

  9. WordPress版微信小程序2.0版本发布

    利用业余时间对WordPress版微信小程序进行的升级,增加了一些功能,程序性能上做了一些优化.经过此次的版本升级,WordPress版微信小程序所需的基本功能已经具备. 开放源码地址:https:/ ...

  10. 图像_pytesseract

    所需模块 ①安装PIL:pip install Pillow(之前的博客中有写过) ②安装pytesser3:pip install pytesser3 ③安装pytesseract:pip inst ...