From 4c2aca4956af387332046ba74c697f61a5c93b94 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 8 Jul 2022 15:18:52 +0300 Subject: [PATCH] Show "TimeoutError" only in the verbose mode when can not find a serial port --- HISTORY.rst | 5 +++ platformio/builder/tools/pioupload.py | 1 + platformio/device/finder.py | 37 ++++++++++++----------- platformio/test/runners/readers/serial.py | 1 + 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7ad9d795..ad63cc38 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -13,6 +13,11 @@ PlatformIO Core 6 **A professional collaborative platform for declarative, safety-critical, and test-driven embedded development.** +6.1.1 (2022-??-??) +~~~~~~~~~~~~~~~~~~ + +* Show "TimeoutError" only in the verbose mode when finding a serial port + 6.1.0 (2022-07-06) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/pioupload.py b/platformio/builder/tools/pioupload.py index 2229a9fb..d46b1590 100644 --- a/platformio/builder/tools/pioupload.py +++ b/platformio/builder/tools/pioupload.py @@ -117,6 +117,7 @@ def AutodetectUploadPort(*args, **kwargs): board_config=env.BoardConfig() if "BOARD" in env else None, upload_protocol=upload_protocol, prefer_gdb_port="blackmagic" in upload_protocol, + verbose=int(ARGUMENTS.get("PIOVERBOSE", 0)), ) ) diff --git a/platformio/device/finder.py b/platformio/device/finder.py index 98aef4f6..f4c29cab 100644 --- a/platformio/device/finder.py +++ b/platformio/device/finder.py @@ -88,6 +88,7 @@ def find_serial_port( # pylint: disable=too-many-arguments ensure_ready=False, prefer_gdb_port=False, timeout=2, + verbose=False, ): if initial_port: if not is_pattern_port(initial_port): @@ -97,8 +98,8 @@ def find_serial_port( # pylint: disable=too-many-arguments if upload_protocol and upload_protocol.startswith("blackmagic"): return find_blackmagic_serial_port(prefer_gdb_port, timeout) if board_config and board_config.get("build.hwids", []): - return find_board_serial_port(board_config, timeout) - port = find_known_uart_port(ensure_ready, timeout) + return find_board_serial_port(board_config, timeout, verbose) + port = find_known_uart_port(ensure_ready, timeout, verbose) if port: return port @@ -158,7 +159,7 @@ def find_blackmagic_serial_port(prefer_gdb_port=False, timeout=0): return None -def find_board_serial_port(board_config, timeout=0): +def find_board_serial_port(board_config, timeout=0, verbose=False): hwids = board_config.get("build.hwids", []) try: @@ -175,18 +176,19 @@ def find_board_serial_port(board_config, timeout=0): except retry.RetryStopException: pass - click.secho( - "TimeoutError: Could not automatically find serial port " - "for the `%s` board based on the declared HWIDs=%s" - % (board_config.get("name", "unknown"), hwids), - fg="yellow", - err=True, - ) + if verbose: + click.secho( + "TimeoutError: Could not automatically find serial port " + "for the `%s` board based on the declared HWIDs=%s" + % (board_config.get("name", "unknown"), hwids), + fg="yellow", + err=True, + ) return None -def find_known_uart_port(ensure_ready=False, timeout=0): +def find_known_uart_port(ensure_ready=False, timeout=0, verbose=False): known_hwids = list(BLACK_MAGIC_HWIDS) # load from UDEV rules @@ -222,12 +224,13 @@ def find_known_uart_port(ensure_ready=False, timeout=0): except retry.RetryStopException: pass - click.secho( - "TimeoutError: Could not automatically find serial port " - "based on the known UART bridges", - fg="yellow", - err=True, - ) + if verbose: + click.secho( + "TimeoutError: Could not automatically find serial port " + "based on the known UART bridges", + fg="yellow", + err=True, + ) return None diff --git a/platformio/test/runners/readers/serial.py b/platformio/test/runners/readers/serial.py index da4b1a05..5a3aeeee 100644 --- a/platformio/test/runners/readers/serial.py +++ b/platformio/test/runners/readers/serial.py @@ -73,6 +73,7 @@ class SerialTestOutputReader: ), upload_protocol=project_options.get("upload_protocol"), ensure_ready=True, + verbose=self.test_runner.verbose, ) if port: return port