execuc / u2if

USB to interfaces implementing MicroPython "machine" module functionalities on a computer.
Other
152 stars 26 forks source link

Multiple retries may be necessary #6

Open lesamouraipourpre opened 3 years ago

lesamouraipourpre commented 3 years ago

While testing U2IF I've noticed that it sometimes takes more than one try to connect to the device:

>>> dev = machine.Device()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/helper.py", line 9, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
  File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/u2if.py", line 22, in __init__
    raise ValueError("No board found")
ValueError: No board found
>>> dev = machine.Device()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/helper.py", line 9, in __call__
    cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
  File "/mnt/projects/u2if/.env/lib/python3.7/site-packages/source/machine/u2if.py", line 22, in __init__
    raise ValueError("No board found")
ValueError: No board found
>>> dev = machine.Device()
>>> dev.firmware_version
[0, 5, 0]
>>> dev.vid
51966
>>> dev.pid
16389

In the example above it took 3 attempts to connect to a RP2040 Pico. Given that the hid library seems to only return null/None with no apparent errors thrown would it be possible to add some kind of connection retry mechanism?