Как получить строку iSerianNumber? - PullRequest
0 голосов
/ 30 апреля 2019

Я хочу найти SerialNumber в моем последовательном USB-модуле. Итак, я набираю код, но я увидел ошибку; ValueError: Устройство не имеет langid

Я меняю код "usb.core.find (idVendor = ..., idProduct = ...) Но та же ошибка.

My 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
...