Skip to content

Commit 77c529e

Browse files
committed
tools/mpremote: Use available ports instead of auto-connect list.
Using just the list of available ports, instead of a hard-coded list of possible ports, means that all ports will be available for auto connection. And the order that they will be attempted in will match what's printed by "mpremote connect list" (and will be the same as before, trying ACMx before USBx). Auto-connect will also now work on Mac, and will allow all COM ports on Windows. Signed-off-by: Damien George <[email protected]>
1 parent b0b8ebc commit 77c529e

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

tools/mpremote/mpremote/main.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@
2525

2626
_PROG = "mpremote"
2727

28-
_AUTO_CONNECT_SEARCH_LIST = [
29-
"/dev/ttyACM0",
30-
"/dev/ttyACM1",
31-
"/dev/ttyACM2",
32-
"/dev/ttyACM3",
33-
"/dev/ttyUSB0",
34-
"/dev/ttyUSB1",
35-
"/dev/ttyUSB2",
36-
"/dev/ttyUSB3",
37-
"COM0",
38-
"COM1",
39-
"COM2",
40-
"COM3",
41-
]
42-
4328
_BUILTIN_COMMAND_EXPANSIONS = {
4429
# Device connection shortcuts.
4530
"a0": "connect /dev/ttyACM0",
@@ -187,14 +172,12 @@ def do_connect(args):
187172
return None
188173
elif dev == "auto":
189174
# Auto-detect and auto-connect to the first available device.
190-
ports = serial.tools.list_ports.comports()
191-
for dev in _AUTO_CONNECT_SEARCH_LIST:
192-
if any(p.device == dev for p in ports):
193-
try:
194-
return pyboard.PyboardExtended(dev, baudrate=115200)
195-
except pyboard.PyboardError as er:
196-
if not er.args[0].startswith("failed to access"):
197-
raise er
175+
for p in sorted(serial.tools.list_ports.comports()):
176+
try:
177+
return pyboard.PyboardExtended(p.device, baudrate=115200)
178+
except pyboard.PyboardError as er:
179+
if not er.args[0].startswith("failed to access"):
180+
raise er
198181
raise pyboard.PyboardError("no device found")
199182
elif dev.startswith("id:"):
200183
# Search for a device with the given serial number.

0 commit comments

Comments
 (0)