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 authored and niklaut committed Aug 19, 2024
1 parent e18dde8 commit 22c78c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.5.4

- Allow NSH port to be opened by filepath.

## 1.5.3

- Fix enabling vector catch with OpenOCD.
Expand Down
17 changes: 11 additions & 6 deletions src/emdbg/serial/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,22 +253,27 @@ def is_alive(self, timeout: float = _TIMEOUT, attempts: int = 4) -> bool:

# -----------------------------------------------------------------------------
@contextmanager
def nsh(serial: str, baudrate: int = 57600):
def nsh(serial_or_port: 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_or_port: the serial number or the filepath 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)
if "/" in serial_or_port:
ttyDevice = serial_or_port
else:
ttyDevice = find_serial_port(serial_or_port).device
try:
LOGGER.info(f"Starting on port '{serial}'..." if serial else "Starting...")
device = Serial(port.device, baudrate=baudrate)
LOGGER.info(f"Starting on port '{serial_or_port}'..."
if serial_or_port else "Starting...")
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 22c78c4

Please sign in to comment.