diff options
| author | Michael Mogenson <michael.mogenson@gmail.com> | 2022-11-22 18:35:15 -0500 |
|---|---|---|
| committer | Michael Mogenson <michael.mogenson@gmail.com> | 2022-11-25 17:20:14 -0500 |
| commit | 921f397acb205c4f2d2ce2d09a7873c3f29b5009 (patch) | |
| tree | 1cb435340c937b1bea8b142198298d7a20974815 /tools | |
| parent | 3c1a2a942a3264da7861891eb9852cdd2a889666 (diff) | |
tools/mpremote: Only auto connect to serial device with USB VID/PID.
On MacOS and Windows there are a few default serial devices that are
returned by `serial.tools.list_ports.comports()`. For example on MacOS:
```
{'description': 'n/a',
'device': '/dev/cu.Bluetooth-Incoming-Port',
'hwid': 'n/a',
'interface': None,
'location': None,
'manufacturer': None,
'name': 'cu.Bluetooth-Incoming-Port',
'pid': None,
'product': None,
'serial_number': None,
'vid': None}
{'description': 'n/a',
'device': '/dev/cu.wlan-debug',
'hwid': 'n/a',
'interface': None,
'location': None,
'manufacturer': None,
'name': 'cu.wlan-debug',
'pid': None,
'product': None,
'serial_number': None,
'vid': None}
```
Users of mpremote most likely do not want to connect to these ports. It
would be desirable if mpremote did not select this ports when using the
auto connect behavior. These serial ports do not have USB VID or PID
values and serial ports for Micropython boards with FTDI/serial-to-USB
adapter or native USB CDC/ACM support do.
Check for the presence of a USB VID / PID int value when selecting a
serial port to auto connect to. All serial ports will still be listed by
the `list` command and can still be selected by name when connecting.
Signed-off-by: Michael Mogenson <michael.mogenson@gmail.com>
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/mpremote/README.md | 2 | ||||
| -rw-r--r-- | tools/mpremote/mpremote/commands.py | 15 |
2 files changed, 9 insertions, 8 deletions
diff --git a/tools/mpremote/README.md b/tools/mpremote/README.md index 7f58788fb..4eb1b86fb 100644 --- a/tools/mpremote/README.md +++ b/tools/mpremote/README.md @@ -7,7 +7,7 @@ The simplest way to use this tool is: mpremote -This will automatically connect to the device and provide an interactive REPL. +This will automatically connect to a USB serial port and provide an interactive REPL. The full list of supported commands are: diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 3bd8732bd..d05a27d9f 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -32,14 +32,15 @@ def do_connect(state, args=None): # Don't do implicit REPL command. state.did_action() elif dev == "auto": - # Auto-detect and auto-connect to the first available device. + # Auto-detect and auto-connect to the first available USB serial port. for p in sorted(serial.tools.list_ports.comports()): - try: - state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200) - return - except pyboard.PyboardError as er: - if not er.args[0].startswith("failed to access"): - raise er + if p.vid is not None and p.pid is not None: + try: + state.pyb = pyboard.PyboardExtended(p.device, baudrate=115200) + return + except pyboard.PyboardError as er: + if not er.args[0].startswith("failed to access"): + raise er raise pyboard.PyboardError("no device found") elif dev.startswith("id:"): # Search for a device with the given serial number. |
