Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of USB devices with numeric serial strings #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

enkiusz
Copy link

@enkiusz enkiusz commented Oct 1, 2022

I have a FT232RL device which has the string '4' as the USB serial number. This confuses usbtools.py as the code first tries to parse the locator as a devidx instead of a serial. The PR modifies this code path so that it checks if the locator is a sernum first.

➜  ~ sudo lsusb -d 0403:6001 -vv

Bus 003 Device 033: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x0403 Future Technology Devices International, Ltd
  idProduct          0x6001 FT232 Serial (UART) IC
  bcdDevice            6.00
  iManufacturer           1 SIBIT
  iProduct                2 SIBIT USB<>RS232 TTL CONVERTER
  iSerial                 3 4
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass    255 Vendor Specific Subclass
      bInterfaceProtocol    255 Vendor Specific Protocol
      iInterface              2 SIBIT USB<>RS232 TTL CONVERTER
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)


➜  ~ ftdi_urls.py 
Available interfaces:
  ftdi://ftdi:232:4/1   (SIBIT USB<>RS232 TTL CONVERTER)

➜  ~ ftconf.py ftdi://ftdi:232:4/1 -v
Traceback (most recent call last):
  File "/home/enki/.local/bin/ftconf.py", line 193, in <module>
    main()
  File "/home/enki/.local/bin/ftconf.py", line 125, in main
    eeprom.open(args.device, size=args.size, model=args.eeprom)
  File "/home/enki/.local/lib/python3.10/site-packages/pyftdi/eeprom.py", line 150, in open
    self._ftdi.open_from_url(device)
  File "/home/enki/.local/lib/python3.10/site-packages/pyftdi/ftdi.py", line 493, in open_from_url
    devdesc, interface = self.get_identifiers(url)
  File "/home/enki/.local/lib/python3.10/site-packages/pyftdi/ftdi.py", line 395, in get_identifiers
    return UsbTools.parse_url(url,
  File "/home/enki/.local/lib/python3.10/site-packages/pyftdi/usbtools.py", line 328, in parse_url
    raise UsbToolsError('No USB device matches URL %s' %
pyftdi.usbtools.UsbToolsError: No USB device matches URL ftdi://ftdi:232:4/1
➜  ~ 

After:

➜  pyftdi git:(master) ✗ ftdi_urls.py 
Available interfaces:
  ftdi://ftdi:232:4/1   (SIBIT USB<>RS232 TTL CONVERTER)

➜  pyftdi git:(master) ✗ ftconf.py ftdi://ftdi:232:4/1 -v
vendor_id: 0x0403
product_id: 0x6001
type: 0x0600
self_powered: False
remote_wakeup: True
power_max: 100
has_serial: True
suspend_pull_down: True
out_isochronous: False
in_isochronous: False
manufacturer: SIBIT
product: SIBIT USB<>RS232 TTL CONVERTER
serial: 4
channel_a_driver: VCP
high_current: True
external_oscillator: 0
invert_TXD: False
invert_RXD: False
invert_RTS: False
invert_CTS: False
invert_DTR: False
invert_DSR: False
invert_DCD: False
invert_RI: False
cbus_func_0: TXLED
cbus_func_1: RXLED
cbus_func_2: GPIO
cbus_func_3: GPIO
cbus_func_4: SLEEP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant