Skip to content

Commit 046af70

Browse files
Extented slcan.py to use "L" command optional to "O" command. (#1496)
* Update slcan.py Added additional parameter "listen_only" to open interface/channel with "L" command (in opposite to "O" command). * make listen_only attribute private --------- Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com>
1 parent 35e847f commit 046af70

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

can/interfaces/slcan.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __init__(
6262
btr: Optional[str] = None,
6363
sleep_after_open: float = _SLEEP_AFTER_SERIAL_OPEN,
6464
rtscts: bool = False,
65+
listen_only: bool = False,
6566
timeout: float = 0.001,
6667
**kwargs: Any,
6768
) -> None:
@@ -81,12 +82,18 @@ def __init__(
8182
Time to wait in seconds after opening serial connection
8283
:param rtscts:
8384
turn hardware handshake (RTS/CTS) on and off
85+
:param listen_only:
86+
If True, open interface/channel in listen mode with ``L`` command.
87+
Otherwise, the (default) ``O`` command is still used. See ``open`` method.
8488
:param timeout:
8589
Timeout for the serial or usb device in seconds (default 0.001)
90+
8691
:raise ValueError: if both ``bitrate`` and ``btr`` are set or the channel is invalid
8792
:raise CanInterfaceNotImplementedError: if the serial module is missing
8893
:raise CanInitializationError: if the underlying serial connection could not be established
8994
"""
95+
self._listen_only = listen_only
96+
9097
if serial is None:
9198
raise CanInterfaceNotImplementedError("The serial module is not installed")
9299

@@ -188,7 +195,10 @@ def flush(self) -> None:
188195
self.serialPortOrig.reset_input_buffer()
189196

190197
def open(self) -> None:
191-
self._write("O")
198+
if self._listen_only:
199+
self._write("L")
200+
else:
201+
self._write("O")
192202

193203
def close(self) -> None:
194204
self._write("C")

0 commit comments

Comments
 (0)