源码:

 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

后续

 1 

最新文章

  1. HDU 3669 Cross the Wall
  2. android应用保活机制
  3. vs 2013 Express 无法启动程序xxx.exe,系统找不到指定文件
  4. 出色的 JavaScript API 设计秘诀
  5. 14.spark RDD解密
  6. 只能在执行 Render() 的过程中调用 RegisterForEventValidation(RegisterForEventValidation can only be called during Render();
  7. 【HDOJ】4347 The Closest M Points
  8. STM32系统时钟
  9. AcroExch.Rect 单位、属性问题
  10. Find命令简介
  11. Eclipse自动补全功能轻松设置 || 不需要修改编辑任何文件
  12. Spring总结_02_Spring概述
  13. Python登录页面及
  14. java3 - 流程控制
  15. Uiautomator--出现报错“urllib3.exceptions.ProtocolError:<'Connection aborted.',error<10054,''>>”的解决方式!
  16. Raneto中文搜索支持
  17. Matlab学以致用--模拟os任务装载情况
  18. Flask中无法在其他函数中查询Sqlachemy的解决办法
  19. Monotonic Array LT896
  20. MyBati__mapper 中取值(#{} 或${}) 以及 parameterType为(基本类型 或复杂类型)

热门文章

  1. 解决Idea.exe无法启动问题(idea2017.3版本)
  2. BeanFactory和ApplicationContext有什么区别?
  3. Spring Cloud 解决了哪些问题?
  4. 学习GlusterFS(四)
  5. Numpy对数组按索引查询
  6. React-简单通用的抛物线动画
  7. node-webkit文档翻译#package.json
  8. pdm的说明
  9. mybatis-day1入门案例
  10. Python操作数据库类 Oracle、Sqlserver、PostgreSQL