pyftdi icon indicating copy to clipboard operation
pyftdi copied to clipboard

fix(usbtools): Handle Missing LangID in UsbTools.get_string()

Open sebm95 opened this issue 7 months ago • 1 comments

Issue: When multiple FTDI devices are connected, such as a custom FTDI-based board alongside an ESP32 debugger, the debugger can cause USB enumeration failures due to missing or inaccessible language IDs (LangIDs). Specifically, when these LangIDs are missing, calling UsbTools.get_string() raises a ValueError. This impacts critical functions including:

Ftdi.list_devices()

Ftdi.open_from_url()

serialext.serial_for_url()

and any other method relying on USB device enumeration.

Fix: This PR modifies UsbTools.get_string() to gracefully handle cases where LangIDs are missing. Instead of raising an exception, it catches the ValueError and returns an empty string. This prevents enumeration-related crashes and significantly improves compatibility with setups containing mixed FTDI devices, such as those involving ESP debuggers.

Additional Notes:

On Linux environments or Docker setups, proper udev rules might mitigate the issue. However, this fix enhances compatibility across Windows and macOS as well.

Impact:

Prevents crashes during USB enumeration.

Ensures smoother operation when ESP debuggers or similar devices with incomplete USB descriptors are connected.

Enhances overall robustness of pyftdi in diverse hardware environments.

Related Issues:

Potentially resolves issues reported in #358 and #311.

sebm95 avatar May 27 '25 11:05 sebm95

Cross checking: it addresses a situation where with multiple FTDI devices are connected and at least one has no access permission, the enumeration fails for all of them, right?

What about on attempting to open (not only listing) the FTDI device that has no permission with this patch? What error is actually reported in this case?

eblot avatar Aug 14 '25 14:08 eblot