Skip to content

Commit

Permalink
ref: use get_default_connected_device for device detection
Browse files Browse the repository at this point in the history
  • Loading branch information
horw committed Dec 13, 2023
1 parent 680deac commit a96d627
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
2 changes: 1 addition & 1 deletion pytest-embedded-idf/pytest_embedded_idf/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _start(self):
if self.app.is_loadable_elf:
self.load_ram()
else:
self.flash() # ???
self.flash()

def load_ram(self) -> None:
if not self.app.is_loadable_elf:
Expand Down
42 changes: 7 additions & 35 deletions pytest-embedded-serial-esp/pytest_embedded_serial_esp/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
from typing import Optional

import esptool
from esptool import CHIP_DEFS, FatalError
from esptool import __version__ as ESPTOOL_VERSION
from esptool import detect_chip
from esptool.targets import CHIP_LIST as ESPTOOL_CHIPS
from pexpect import TIMEOUT
from pytest_embedded.log import MessageQueue, PexpectProcess, live_print_call
Expand Down Expand Up @@ -101,38 +99,13 @@ def __init__(
)

with contextlib.redirect_stdout(msg_queue):
# Temp workaround for esptool
# on windows have to close the unused scanned ports manually
#
# could revert to the following code blocks after fixing it
#
# esp: esptool.ESPLoader = esptool.get_default_connected_device(
# ports,
# port=port,
# connect_attempts=3,
# initial_baud=baud,
# chip=esptool_target,
# )
_esp = None
for each_port in reversed(ports):
print(f'Serial port {each_port}')
try:
if esptool_target == 'auto':
_esp = detect_chip(each_port, baud, connect_attempts=3)
else:
chip_class = CHIP_DEFS[esptool_target]
_esp = chip_class(each_port, baud)
_esp.connect(attempts=3)
break
except (FatalError, OSError) as err:
if port is not None:
raise
print(f'{each_port} failed to connect: {err}')
if _esp:
# ensure unused port is closed.
_esp._port.close()
_esp = None
esp = _esp
esp = esptool.get_default_connected_device(
ports,
port=port,
connect_attempts=3,
initial_baud=baud,
chip=esptool_target,
)

if not esp:
raise ValueError('Couldn\'t auto detect chip. Please manually specify with "--port"')
Expand Down Expand Up @@ -180,7 +153,6 @@ def wrapper(self, *args, **kwargs):
with contextlib.redirect_stdout(self._q):
settings = self.proc.get_settings()
try:
self.esp = None
self.esp = esptool.detect_chip(self.proc, self.baud)
self.esp.connect('hard_reset')

Expand Down

0 comments on commit a96d627

Please sign in to comment.