Skip to content

Commit 1f8aaa9

Browse files
Add support for socketcan send timeout
Related to issue hardbyte#205
1 parent 65330f8 commit 1f8aaa9

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

can/interfaces/socketcan/socketcan_ctypes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def recv(self, timeout=None):
125125

126126
def send(self, msg, timeout=None):
127127
frame = _build_can_frame(msg)
128+
if timeout:
129+
# Wait for write availability. write will fail below on timeout
130+
select.select([], [self.socket], [], timeout)
128131
bytes_sent = libc.write(self.socket, ctypes.byref(frame), ctypes.sizeof(frame))
129132
if bytes_sent == -1:
130133
log.debug("Error sending frame :-/")

can/interfaces/socketcan/socketcan_native.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ def send(self, msg, timeout=None):
419419
arbitration_id |= 0x20000000
420420
l = log.getChild("tx")
421421
l.debug("sending: %s", msg)
422+
if timeout:
423+
# Wait for write availability. send will fail below on timeout
424+
select.select([], [self.socket], [], timeout)
422425
try:
423426
self.socket.send(build_can_frame(arbitration_id, msg.data))
424427
except OSError:

0 commit comments

Comments
 (0)