From d6c00bc259aa0d0460b101832c1ecb5d4209f7d9 Mon Sep 17 00:00:00 2001 From: mdaeron Date: Mon, 29 Aug 2022 14:27:04 +0200 Subject: [PATCH 1/4] tools/mpremote: Add autoconnect_regexp config to filter auto ports. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Daëron --- docs/reference/mpremote.rst | 11 +++++++++++ tools/mpremote/mpremote/main.py | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst index a48df9953f503..e912a443fe6f8 100644 --- a/docs/reference/mpremote.rst +++ b/docs/reference/mpremote.rst @@ -179,6 +179,15 @@ the execution of the tool, if such commands are not explicitly given. Automatic connection will search for the first available serial device. If no action is specified then the REPL will be entered. +It is possible to filter the serial devices eligible for auto connection by defining +``autoconnect_regexp`` in ``.config/mpremote/config.py``: + +.. code-block:: python3 + + # regular expression used to filter ports eligible for auto connect: + autoconnect_regexp = '/dev/cu.usb' # for macOS + + Once connected to a device, ``mpremote`` will automatically soft-reset the device if needed. This clears the Python heap and restarts the interpreter, making sure that subsequent Python code executes in a fresh environment. Auto @@ -229,6 +238,8 @@ Any user configuration, including user-defined shortcuts, can be placed in the f """,], "test": ["mount", ".", "exec", "import test"], } + + autoconnect_regexp = '/dev/cu.usb' # for macOS Examples diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index bd98da88248c1..b05edc0157836 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -239,7 +239,11 @@ def do_connect(args): return None elif dev == "auto": # Auto-detect and auto-connect to the first available device. - for p in sorted(serial.tools.list_ports.comports()): + try: + autoconnect_regexp = load_user_config().__dict__['autoconnect_regexp'] + except KeyError: + autoconnect_regexp = '' + for p in sorted(serial.tools.list_ports.grep(autoconnect_regexp)): try: return pyboard.PyboardExtended(p.device, baudrate=115200) except pyboard.PyboardError as er: From 65cfd8beba034859540c17604ef8a30a4b3f36d8 Mon Sep 17 00:00:00 2001 From: mdaeron Date: Mon, 29 Aug 2022 18:38:57 +0200 Subject: [PATCH 2/4] tools/mpremote: Add autoconnect_regexp config to filter auto ports. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Daëron --- tools/mpremote/mpremote/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index b05edc0157836..06c97c1c50da4 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -240,9 +240,9 @@ def do_connect(args): elif dev == "auto": # Auto-detect and auto-connect to the first available device. try: - autoconnect_regexp = load_user_config().__dict__['autoconnect_regexp'] + autoconnect_regexp = load_user_config().__dict__["autoconnect_regexp"] except KeyError: - autoconnect_regexp = '' + autoconnect_regexp = "" for p in sorted(serial.tools.list_ports.grep(autoconnect_regexp)): try: return pyboard.PyboardExtended(p.device, baudrate=115200) From 2e31158bb43caba29aa37237823f677881abc219 Mon Sep 17 00:00:00 2001 From: mdaeron Date: Tue, 30 Aug 2022 12:21:52 +0200 Subject: [PATCH 3/4] tools/mpremote: Autoconnect ignores cu.Bluetooth-Incoming-Port on macOS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Daëron --- docs/reference/mpremote.rst | 4 +--- tools/mpremote/mpremote/main.py | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/reference/mpremote.rst b/docs/reference/mpremote.rst index e912a443fe6f8..1c941029166d3 100644 --- a/docs/reference/mpremote.rst +++ b/docs/reference/mpremote.rst @@ -185,7 +185,7 @@ It is possible to filter the serial devices eligible for auto connection by defi .. code-block:: python3 # regular expression used to filter ports eligible for auto connect: - autoconnect_regexp = '/dev/cu.usb' # for macOS + autoconnect_regexp = '/dev/cu.usbmodem' Once connected to a device, ``mpremote`` will automatically soft-reset the @@ -238,8 +238,6 @@ Any user configuration, including user-defined shortcuts, can be placed in the f """,], "test": ["mount", ".", "exec", "import test"], } - - autoconnect_regexp = '/dev/cu.usb' # for macOS Examples diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 06c97c1c50da4..279e03650302b 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -242,7 +242,10 @@ def do_connect(args): try: autoconnect_regexp = load_user_config().__dict__["autoconnect_regexp"] except KeyError: - autoconnect_regexp = "" + if sys.platform == 'darwin': + autoconnect_regexp = "/dev/cu.usb" + else: + autoconnect_regexp = "" for p in sorted(serial.tools.list_ports.grep(autoconnect_regexp)): try: return pyboard.PyboardExtended(p.device, baudrate=115200) From f3cc3b7ba7f7cbe09c030aa1dda677dbe3f5f52b Mon Sep 17 00:00:00 2001 From: mdaeron Date: Tue, 30 Aug 2022 12:24:07 +0200 Subject: [PATCH 4/4] tools/mpremote: Change single to double quotes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Daëron --- tools/mpremote/mpremote/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/mpremote/mpremote/main.py b/tools/mpremote/mpremote/main.py index 279e03650302b..397c28de802e2 100644 --- a/tools/mpremote/mpremote/main.py +++ b/tools/mpremote/mpremote/main.py @@ -242,7 +242,7 @@ def do_connect(args): try: autoconnect_regexp = load_user_config().__dict__["autoconnect_regexp"] except KeyError: - if sys.platform == 'darwin': + if sys.platform == "darwin": autoconnect_regexp = "/dev/cu.usb" else: autoconnect_regexp = "" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy