Skip to content

Commit

Permalink
[serial] Support serial both by id, by path name
Browse files Browse the repository at this point in the history
  • Loading branch information
alexVinarskis committed Aug 19, 2024
1 parent e18dde8 commit 4469f19
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/emdbg/serial/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,20 @@ def is_alive(self, timeout: float = _TIMEOUT, attempts: int = 4) -> bool:
@contextmanager
def nsh(serial: str, baudrate: int = 57600):
"""
Opens a serial port with the `serial` number and closes it again.
Opens a serial port with the `serial` number or filepath and closes it again.
:param serial: the serial number of the port to connect to.
:param serial: the serial number or filepath (if contains '/') of the port to connect to.
:param baudrate: the baudrate to use.
:raises `SerialException`: if serial port is not found.
:return: yields an initialized `Nsh` object.
"""
nsh = None
port = find_serial_port(serial)
ttyDevice = serial if "/" in serial else find_serial_port(serial).device
try:
LOGGER.info(f"Starting on port '{serial}'..." if serial else "Starting...")
device = Serial(port.device, baudrate=baudrate)
device = Serial(ttyDevice, baudrate=baudrate)
reader_thread = ReaderThread(device, lambda: _NshReader(device))
with reader_thread as reader:
nsh = Nsh(reader_thread, reader)
Expand Down

0 comments on commit 4469f19

Please sign in to comment.