From 4afa299105c0b0b1d70b4db83887f066f860adcf Mon Sep 17 00:00:00 2001 From: Werner Wolfrum <42910294+wolfraven@users.noreply.github.com> Date: Mon, 23 Jan 2023 19:48:26 +0100 Subject: [PATCH 1/2] Update slcan.py Added additional parameter "listen_only" to open interface/channel with "L" command (in opposite to "O" command). --- can/interfaces/slcan.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/can/interfaces/slcan.py b/can/interfaces/slcan.py index 7851a0322..694622655 100644 --- a/can/interfaces/slcan.py +++ b/can/interfaces/slcan.py @@ -62,6 +62,7 @@ def __init__( btr: Optional[str] = None, sleep_after_open: float = _SLEEP_AFTER_SERIAL_OPEN, rtscts: bool = False, + listen_only: bool = False, timeout: float = 0.001, **kwargs: Any, ) -> None: @@ -81,12 +82,18 @@ def __init__( Time to wait in seconds after opening serial connection :param rtscts: turn hardware handshake (RTS/CTS) on and off + :param listen_only: + If True, open interface/channel in listen mode with ``L`` command. + Otherwise, the (default) ``O`` command is still used. See ``open`` methode. :param timeout: Timeout for the serial or usb device in seconds (default 0.001) + :raise ValueError: if both ``bitrate`` and ``btr`` are set or the channel is invalid :raise CanInterfaceNotImplementedError: if the serial module is missing :raise CanInitializationError: if the underlying serial connection could not be established """ + self.listen_only = listen_only + if serial is None: raise CanInterfaceNotImplementedError("The serial module is not installed") @@ -188,7 +195,10 @@ def flush(self) -> None: self.serialPortOrig.reset_input_buffer() def open(self) -> None: - self._write("O") + if self.listen_only: + self._write("L") + else: + self._write("O") def close(self) -> None: self._write("C") From 2e7fe57683275c4c04d6b36047556bfed42a2c98 Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:23:36 +0200 Subject: [PATCH 2/2] make listen_only attribute private --- can/interfaces/slcan.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/can/interfaces/slcan.py b/can/interfaces/slcan.py index 694622655..f32d82fd0 100644 --- a/can/interfaces/slcan.py +++ b/can/interfaces/slcan.py @@ -84,7 +84,7 @@ def __init__( turn hardware handshake (RTS/CTS) on and off :param listen_only: If True, open interface/channel in listen mode with ``L`` command. - Otherwise, the (default) ``O`` command is still used. See ``open`` methode. + Otherwise, the (default) ``O`` command is still used. See ``open`` method. :param timeout: Timeout for the serial or usb device in seconds (default 0.001) @@ -92,7 +92,7 @@ def __init__( :raise CanInterfaceNotImplementedError: if the serial module is missing :raise CanInitializationError: if the underlying serial connection could not be established """ - self.listen_only = listen_only + self._listen_only = listen_only if serial is None: raise CanInterfaceNotImplementedError("The serial module is not installed") @@ -195,7 +195,7 @@ def flush(self) -> None: self.serialPortOrig.reset_input_buffer() def open(self) -> None: - if self.listen_only: + if self._listen_only: self._write("L") else: self._write("O")