Skip to content

Commit b66afab

Browse files
authored
Update slcan.py
Added additional parameter "listen_only" to open interface/channel with "L" command (in opposite to "O" command).
1 parent 5c523ec commit b66afab

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

can/interfaces/slcan.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(
6464
btr: Optional[str] = None,
6565
sleep_after_open: float = _SLEEP_AFTER_SERIAL_OPEN,
6666
rtscts: bool = False,
67+
listen_only: bool = False,
6768
**kwargs: Any,
6869
) -> None:
6970
"""
@@ -82,11 +83,16 @@ def __init__(
8283
Time to wait in seconds after opening serial connection
8384
:param rtscts:
8485
turn hardware handshake (RTS/CTS) on and off
86+
:param listen_only:
87+
If True, open interface/channel in listen mode with ``L`` command.
88+
Otherwise the (default) ``O`` command is still used. See ``open`` methode.
8589
8690
:raise ValueError: if both ``bitrate`` and ``btr`` are set or the channel is invalid
8791
:raise CanInterfaceNotImplementedError: if the serial module is missing
8892
:raise CanInitializationError: if the underlying serial connection could not be established
8993
"""
94+
self.listen_only = listen_only
95+
9096
if serial is None:
9197
raise CanInterfaceNotImplementedError("The serial module is not installed")
9298

@@ -192,7 +198,10 @@ def flush(self) -> None:
192198
self.serialPortOrig.read()
193199

194200
def open(self) -> None:
195-
self._write("O")
201+
if self.listen_only == True:
202+
self._write("L")
203+
else:
204+
self._write("O")
196205

197206
def close(self) -> None:
198207
self._write("C")

0 commit comments

Comments
 (0)