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

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

Open
larsch opened this issue Jun 30, 2020 · 1 comment · May be fixed by #210
Open

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

larsch opened this issue Jun 30, 2020 · 1 comment · May be fixed by #210

Comments

@larsch
Copy link

larsch commented Jun 30, 2020

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")
@eblot
Copy link
Owner

eblot commented Jun 30, 2020

This is a somewhat legacy but still used feature:

Devices that do not have a serial number - there are many of them - used to be accessed with a index, and the third field in the URL is either used as a index or a serial number. If the S/N is an integer, it is used an index, if not it is used as an integer - as FTDI generated S/N always contains some non-digit characters.

I agree this is an issue with S/N made of digit only characters.

How to fix this w/o breaking backward compatibility is not going to be easy. I'm open to suggestions.

@larsch larsch linked a pull request Jun 30, 2020 that will close this issue
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 a pull request may close this issue.

2 participants