我想在我的USB串行模块中找到SerialNumber。 因此,我正在键入代码,但是我看到了错误; ValueError:设备没有限制
我将代码更改为“ usb.core.find(idVendor = ...,idProduct = ...),但相同的错误。
我的Python版本:3.6.7 和PyUSB版本:1.0.2
def find_device():
# find
devices = usb.core.find(find_all=True)
# if no devices
if devices is None:
print("No Init. Check your Hardware Interfaces")
exit(-1);
# else
LTE = ()
GPS = ()
Dust = ()
for dev in devices:
for cfg in dev:
for intf in cfg:
if intf.bInterfaceClass == 224:
print("===> Found LTE.")
print("VID, PID = 0x%x, 0x%x" % (dev.idVendor, dev.idProduct))
LTE = ('0x%x' % dev.idVendor, '0x%x' % dev.idProduct)
if intf.bInterfaceClass == 255:
if intf.iInterface == 2:
print("==> Found USB Bridge.")
print("VID, PID = 0x%x, 0x%x" % (dev.idVendor, dev.idProduct))
print("Serial Number = %s" % usb.util.get_string(dev, dev.iSerialNumber))
如果运行代码,则控制台返回Traceback。
Traceback (most recent call last):
File "/home/odroid/lx/python/testCode/find_device.py", line 37, in <module>
find_device()
File "/home/odroid/lx/python/testCode/find_device.py", line 29, in find_device
print("Serial Number = %s" % usb.util.get_string(dev, dev.iSerialNumber, '0195'))
File "/home/odroid/lx/python/venv/lib/python3.6/site-packages/usb/util.py", line 314, in get_string
raise ValueError("The device has no langid")
ValueError: The device has no langid