summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-06-13 23:55:15 +1000
committerDamien George <damien@micropython.org>2021-06-15 13:52:31 +1000
commit77c529e8be7302a8436152ead6dacf050c03d601 (patch)
tree983c39e016b3051e37e9b5e92a0886a10408280e
parentb0b8ebc4f6e337e18c79367ccc5f379dfa8681d9 (diff)
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 <damien@micropython.org>
-rw-r--r--tools/mpremote/mpremote/main.py29
1 files changed, 6 insertions, 23 deletions
diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py
index 1ce00305e..121eec3bf 100644
--- a/tools/mpremote/mpremote/main.py
+++ b/tools/mpremote/mpremote/main.py
@@ -25,21 +25,6 @@ from .console import Console, ConsolePosix
_PROG = "mpremote"
-_AUTO_CONNECT_SEARCH_LIST = [
- "/dev/ttyACM0",
- "/dev/ttyACM1",
- "/dev/ttyACM2",
- "/dev/ttyACM3",
- "/dev/ttyUSB0",
- "/dev/ttyUSB1",
- "/dev/ttyUSB2",
- "/dev/ttyUSB3",
- "COM0",
- "COM1",
- "COM2",
- "COM3",
-]
-
_BUILTIN_COMMAND_EXPANSIONS = {
# Device connection shortcuts.
"a0": "connect /dev/ttyACM0",
@@ -187,14 +172,12 @@ def do_connect(args):
return None
elif dev == "auto":
# Auto-detect and auto-connect to the first available device.
- ports = serial.tools.list_ports.comports()
- for dev in _AUTO_CONNECT_SEARCH_LIST:
- if any(p.device == dev for p in ports):
- try:
- return pyboard.PyboardExtended(dev, baudrate=115200)
- except pyboard.PyboardError as er:
- if not er.args[0].startswith("failed to access"):
- raise er
+ for p in sorted(serial.tools.list_ports.comports()):
+ try:
+ return pyboard.PyboardExtended(p.device, baudrate=115200)
+ 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.