fix(usbtools): Handle Missing LangID in UsbTools.get_string() #415
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aValueError. This impacts critical functions including: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.