zoukankan      html  css  js  c++  java
  • 利用pyusb来查询当前所以usb设备

    具体代码如下

    #!/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) + ' ') sys.stdout.write('Hexadecimal VendorID=' + hex(cfg.idVendor) + ' & ProductID=' + hex(cfg.idProduct) + ' ')

    测试结果如下

    键盘有插入时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
  • 相关阅读:
    品味性能之道<六>:图形化SQL分析工具
    品味性能之道<五>:SQL分析工具
    品味性能之道<四>:管理重于技术
    品味性能之道<三>:方法论
    品味性能之道<二>:性能工程师可以具备的专业素养
    品味性能之道<一>:性能测试思维与误区
    网络协议学习笔记
    Java内存泄露监控工具:JVM监控工具介绍
    Loadrunner脚本回放无法准确定位欲删除元素
    C++ 虚函数
  • 原文地址:https://www.cnblogs.com/libra13179/p/7446875.html
Copyright © 2011-2022 走看看