Open F3zz1k opened 2 years ago
from https://github.com/TedKus/useftdi/blob/main/useftdi/useftdi_core.py we built a function to list and return the url. the trouble is that windows won't let python know if a new usb device showed up (i think). we found it easier to just restart. Hope this helps. Ted
def get_available_ftdi_urls(): """ get_available_ftdi_urls()
Prints all availible FTDI interfaces currently connected to the machine.
Returns: List: List of Tuples for each ftdi connection found. Tuples are
returned as (url, description) pairs.
"""
io_buffer = StringIO()
with redirect_stdout(io_buffer):
Ftdi.show_devices() # normally prints to stdout and returns None
response = io_buffer.getvalue()
# parse out list of connected devices
response = response.lstrip('Available interfaces:').strip()
connections = []
for connection in response.split('\n'):
if connection == '':
continue
url, desc = connection.split()
desc = desc.replace('(', '').replace(')', '')
connections.append((url, desc))
if not connections:
raise IOError("No FTDI devices found. Check USB connections..."
" Restart python to try again.")
return connections
If show_devices() is run before a device is plugged in then pyftdi will not detect any newly connected devices even if show_devices() is run again. If show_devices() is run after a device is plugged in and then run again after said device is unplugged then it will crash with the following traceback:
code to reproduce error: