Skip to content

Commit 0b6d3ca

Browse files
committed
new methods for iscan
1 parent ab4b3a0 commit 0b6d3ca

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

can/interfaces/iscan.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
Interface for isCAN from Thorsis Technologies GmbH, former ifak system GmbH.
66
"""
77

8+
from __future__ import absolute_import, division
9+
810
import ctypes
911
import time
1012
import logging
@@ -76,16 +78,21 @@ def __init__(self, channel, bitrate=500000, poll_interval=0.01, **kwargs):
7678
"""
7779
if iscan is None:
7880
raise ImportError("Could not load isCAN driver")
81+
7982
self.channel = ctypes.c_ubyte(int(channel))
8083
self.channel_info = "IS-CAN: %s" % channel
84+
8185
if bitrate not in self.BAUDRATES:
8286
valid_bitrates = ", ".join(str(bitrate) for bitrate in self.BAUDRATES)
8387
raise ValueError("Invalid bitrate, choose one of " + valid_bitrates)
88+
8489
self.poll_interval = poll_interval
8590
iscan.isCAN_DeviceInitEx(self.channel, self.BAUDRATES[bitrate])
86-
super(IscanBus, self).__init__(channel, **kwargs)
8791

88-
def recv(self, timeout=None):
92+
super(IscanBus, self).__init__(channel=channel, bitrate=bitrate,
93+
poll_interval=poll_interval, **kwargs)
94+
95+
def _recv_internal(self, timeout):
8996
raw_msg = MessageExStruct()
9097
end_time = time.time() + timeout if timeout is not None else None
9198
while True:
@@ -97,19 +104,21 @@ def recv(self, timeout=None):
97104
raise
98105
if end_time is not None and time.time() > end_time:
99106
# No message within timeout
100-
return None
107+
return None, False
101108
# Sleep a short time to avoid hammering
102109
time.sleep(self.poll_interval)
103110
else:
104111
# A message was received
105112
break
106-
return Message(arbitration_id=raw_msg.message_id,
107-
extended_id=bool(raw_msg.is_extended),
108-
timestamp=time.time(), # Better than nothing...
109-
is_remote_frame=bool(raw_msg.remote_req),
110-
dlc=raw_msg.data_len,
111-
data=raw_msg.data[:raw_msg.data_len],
112-
channel=self.channel.value)
113+
114+
msg = Message(arbitration_id=raw_msg.message_id,
115+
extended_id=bool(raw_msg.is_extended),
116+
timestamp=time.time(), # Better than nothing...
117+
is_remote_frame=bool(raw_msg.remote_req),
118+
dlc=raw_msg.data_len,
119+
data=raw_msg.data[:raw_msg.data_len],
120+
channel=self.channel.value)
121+
return msg, False
113122

114123
def send(self, msg, timeout=None):
115124
raw_msg = MessageExStruct(msg.arbitration_id,
@@ -124,6 +133,7 @@ def shutdown(self):
124133

125134

126135
class IscanError(CanError):
136+
# TODO: document
127137

128138
ERROR_CODES = {
129139
1: "No access to device",

0 commit comments

Comments
 (0)