From 8c62ff40eb43d6ca16d1d96c01e53823d18cc924 Mon Sep 17 00:00:00 2001 From: daid Date: Sat, 20 Apr 2024 08:45:10 +0200 Subject: [PATCH] pyboard.py: Default to the last available serial port on the system. Signed-off-by: daid --- tools/pyboard.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/pyboard.py b/tools/pyboard.py index c422b64ac5..e369434e5a 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -766,12 +766,19 @@ del _injected_buf, _FS def main(): import argparse + import serial.tools.list_ports + + default_device = "/dev/ttyACM0" + available_devices = serial.tools.list_ports.comports() + if available_devices: + default_device = available_devices[-1].name + default_device = os.environ.get("PYBOARD_DEVICE", default_device) cmd_parser = argparse.ArgumentParser(description="Run scripts on the pyboard.") cmd_parser.add_argument( "-d", "--device", - default=os.environ.get("PYBOARD_DEVICE", "/dev/ttyACM0"), + default=default_device, help="the serial device or the IP address of the pyboard", ) cmd_parser.add_argument(