Skip to content

Commit ba5d714

Browse files
committed
Minor adjustments to slcan
1 parent 78c3a40 commit ba5d714

3 files changed

Lines changed: 15 additions & 11 deletions

File tree

can/interfaces/slcan.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Interface for slcan compatible interfaces (win32/linux).
3-
(Linux could use slcand/socketcan as well).
3+
4+
Note Linux users can use slcand/socketcan as well.
45
"""
56

67
from __future__ import absolute_import
@@ -15,6 +16,7 @@
1516

1617
logger = logging.getLogger(__name__)
1718

19+
1820
class slcanBus(BusABC):
1921
"""
2022
slcan interface
@@ -73,15 +75,13 @@ def __init__(self, channel, ttyBaudrate=115200, timeout=1, bitrate=None, **kwarg
7375
self.serialPort = io.TextIOWrapper(io.BufferedRWPair(self.serialPortOrig, self.serialPortOrig, 1),
7476
newline='\r', line_buffering=True)
7577

76-
# why do we sleep here?
7778
time.sleep(self._SLEEP_AFTER_SERIAL_OPEN)
7879

7980
if bitrate is not None:
8081
self.close()
8182
if bitrate in self._BITRATES:
8283
self.write(self._BITRATES[bitrate])
8384
else:
84-
# this only prints the keys of the dict
8585
raise ValueError("Invalid bitrate, choose one of " + (', '.join(self._BITRATES)) + '.')
8686

8787
self.open()
@@ -93,27 +93,31 @@ def recv(self, timeout=None):
9393

9494
canId = None
9595
remote = False
96+
extended = False
9697
frame = []
9798
readStr = self.serialPort.readline()
98-
if not readStr: # if not None and not empty
99+
if not readStr:
99100
return None
100101
else:
101-
if readStr[0] == 'T': # extended frame
102+
if readStr[0] == 'T':
103+
# extended frame
102104
canId = int(readStr[1:9], 16)
103105
dlc = int(readStr[9])
104106
extended = True
105107
for i in range(0, dlc):
106108
frame.append(int(readStr[10 + i * 2:12 + i * 2], 16))
107-
elif readStr[0] == 't': # normal frame
109+
elif readStr[0] == 't':
110+
# normal frame
108111
canId = int(readStr[1:4], 16)
109112
dlc = int(readStr[4])
110113
for i in range(0, dlc):
111114
frame.append(int(readStr[5 + i * 2:7 + i * 2], 16))
112-
extended = False
113-
elif readStr[0] == 'r': # remote frame
115+
elif readStr[0] == 'r':
116+
# remote frame
114117
canId = int(readStr[1:4], 16)
115118
remote = True
116-
elif readStr[0] == 'R': # remote extended frame
119+
elif readStr[0] == 'R':
120+
# remote extended frame
117121
canId = int(readStr[1:9], 16)
118122
extended = True
119123
remote = True

doc/interfaces/slcan.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ Bus
2020
Internals
2121
---------
2222

23-
.. TODO:: Implement and document slcan interface.
23+
.. TODO:: Document internals of slcan interface.

doc/interfaces/socketcan_native.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SocketCAN (python)
33

44
Python 3.3 added support for socketcan for linux systems.
55

6-
The socketcan_native interface directly uses Python's socket module to
6+
The ``socketcan_native`` interface directly uses Python's socket module to
77
access SocketCAN on linux. This is the most direct route to the kernel
88
and should provide the most responsive one.
99

0 commit comments

Comments
 (0)