Skip to content

URL with integer serial number doesn't match device #209

Open
@larsch

Description

@larsch

pyftdi finds my device:

pyftdi.ftdi.Ftdi.show_devices()

Result:

Available interfaces:
  ftdi://vid:pid:0025/1   (my device)

But can't open it:

bitbang = pyftdi.ftdi.Ftdi()
bitbang.open_bitbang_from_url("ftdi://vid:pid:0025/1")

Result:

Traceback (most recent call last):
  File "bitbang.py", line 25, in <module>
    bitbang.open_bitbang_from_url("ftdi://vid:pid:0025/1")
  File "c:\temp\pyftdi\pyftdi\ftdi.py", line 799, in open_bitbang_from_url
    devdesc, interface = self.get_identifiers(url)
  File "c:\temp\pyftdi\pyftdi\ftdi.py", line 421, in get_identifiers
    cls.DEFAULT_VENDOR)
  File "c:\temp\pyftdi\pyftdi\usbtools.py", line 349, in parse_url
    urlstr) from None
pyftdi.usbtools.UsbToolsError: No USB device matches URL ftdi://vid:pid:0025/1

Reason is that UsbTools.enumerate_candidates attempts to parse the serial number as an integer and uses it as an index into the list of candidates (which has only 1 element). The third specifier (the serial number) is only considered a serial number if it does not parse as an integer.

pyftdi/pyftdi/usbtools.py

Lines 422 to 427 in c77136f

devidx = to_int(locators[0])
if devidx > 255:
raise ValueError()
idx = devidx
if idx:
idx = devidx-1

I don't know why you attempt to parse as an integer, so it's hard for me to fix.

I need this line to run to match device with the specific serial number.

sernum = locators[0]

I can open the device with open_bitbang just fine, but all the GPIO etc classes require URL to be used.

bitbang.open_bitbang(VID, PID, serial="0025")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions