Skip to content

Commit

Permalink
UF2 installation port finding fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Dec 26, 2022
1 parent b4f7954 commit bc8c505
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
==================
Expand Down
4 changes: 4 additions & 0 deletions thonny/plugins/micropython/mp_front.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions thonny/plugins/micropython/uf2dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -552,18 +554,19 @@ 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":
return
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
Expand Down

0 comments on commit bc8c505

Please sign in to comment.