码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2020-01-02 18:48:54      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:分析   nbsp   printing   charm   lan   hex   packages   print   就是   

源码:

 1 #!/usr/bin/python
 2     import sys
 3     import usb.core
 4     # find USB devices
 5     dev = usb.core.find(find_all=True)
 6     # loop through devices, printing vendor and product ids in decimal and hex
 7     for cfg in dev:
 8         if cfg.idVendor == 0x2207:
 9             print(str(cfg.serial_number))        # 之前就是这里报错
10             print(str(cfg.port_number))
11             sys.stdout.write(Decimal VendorID= + str(cfg.idVendor) + & ProductID= + str(cfg.idProduct) + \n)
12             sys.stdout.write(Hexadecimal VendorID= + hex(cfg.idVendor) + & ProductID= + hex(cfg.idProduct) + \n\n)

遇到的问题:

通过pyusb打印出usb设备的所有属性,发现关于serial_number的属性发生了异常,异常如下:
‘Traceback (most recent call last):
File "D:\\Program Files\\JetBrains\\PyCharm 2019.3.1\\plugins\\python\\helpers\\pydev\\_pydevd_bundle\\pydevd_resolver.py", line 178, in _getPyDictionary
attr = getattr(var, n)
File "D:\\Program Files\\Python37\\lib\\site-packages\\usb\\core.py", line 830, in serial_number
self._serial_number = util.get_string(self, self.iSerialNumber)
File "D:\\Program Files\\Python37\\lib\\site-packages\\usb\\util.py", line 314, in get_string
raise ValueError("The device has no langid")
ValueError: The device has no langid

 

解决办法:

通过zadig软件安装libusb-win32,libusbk

 

问题分析:

https://stackoverflow.com/questions/58131082/simple-communication-usb-with-python-pyusb-on-windows-10
https://sourceforge.net/p/pyusb/mailman/pyusb-users/?viewmonth=201608

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

标签:分析   nbsp   printing   charm   lan   hex   packages   print   就是   

原文地址:https://www.cnblogs.com/jiangyibo/p/12134378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!