From bc8c505e722cb25ebc4638f793fd44a4d11a7f96 Mon Sep 17 00:00:00 2001 From: Aivar Annamaa Date: Mon, 26 Dec 2022 17:29:03 +0200 Subject: [PATCH] UF2 installation port finding fix --- CHANGELOG.rst | 1 + thonny/plugins/micropython/mp_front.py | 4 ++++ thonny/plugins/micropython/uf2dialog.py | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d2d98d37f..50af29522 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Version history 4.0.2 (2022-12-??) ================== * Ignore flushing errors in the end of UF2 installation +* Make port finding in the end of UF2 installation process more robust 4.0.1 (2022-09-11) ================== diff --git a/thonny/plugins/micropython/mp_front.py b/thonny/plugins/micropython/mp_front.py index 7a103a81e..35d8bd0ce 100644 --- a/thonny/plugins/micropython/mp_front.py +++ b/thonny/plugins/micropython/mp_front.py @@ -987,6 +987,10 @@ def list_serial_ports(): os.path.islink = old_islink +def list_serial_port_infos(): + return [f"{p.device} ({p.hwid})" for p in list_serial_ports()] + + def port_exists(device): for port in list_serial_ports(): if port.device == device: diff --git a/thonny/plugins/micropython/uf2dialog.py b/thonny/plugins/micropython/uf2dialog.py index a443752f5..5a0b72966 100644 --- a/thonny/plugins/micropython/uf2dialog.py +++ b/thonny/plugins/micropython/uf2dialog.py @@ -13,6 +13,7 @@ from thonny import get_runner from thonny.languages import tr from thonny.misc_utils import get_win_volume_name, list_volumes +from thonny.plugins.micropython.mp_front import list_serial_port_infos from thonny.ui_utils import AdvancedLabel, MappingCombobox, set_text_if_different from thonny.workdlg import WorkDialog @@ -465,7 +466,8 @@ def _perform_work( from thonny.plugins.micropython import list_serial_ports try: - ports_before = list_serial_ports() + ports_before = list_serial_port_infos() + logger.debug("Ports before: %s", ports_before) self._download_to_the_device(download_url, size, target_dir, target_filename) if self._state == "working": self.perform_post_installation_steps(ports_before) @@ -552,11 +554,11 @@ def _wait_for_new_ports(self, old_ports): wait_time = 0 step = 0.2 while wait_time < 10: - new_ports = list_serial_ports() + new_ports = list_serial_port_infos() added_ports = set(new_ports) - set(old_ports) if added_ports: for p in added_ports: - self.append_text("Found %s at %s\n" % ("%04x:%04x" % (p.vid, p.pid), p.device)) + self.append_text("Found port %s\n" % p) self.set_action_text("Found port") return if self._state == "cancelling": @@ -564,6 +566,7 @@ def _wait_for_new_ports(self, old_ports): time.sleep(step) wait_time += step else: + logger.debug("Ports after: %s", list_serial_port_infos()) self.set_action_text("Warning: Could not find port") self.append_text("Warning: Could not find port in %s seconds\n" % int(wait_time)) # leave some time to see the warning