Skip to content

Commit 5e97bc5

Browse files
authored
Merge branch 'develop' into add_typing_for_slcan_interface
2 parents 6e09ca6 + 7601f22 commit 5e97bc5

File tree

6 files changed

+260
-146
lines changed

6 files changed

+260
-146
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import logging
1212
import os
1313
import tempfile
14-
from collections import deque
14+
from collections import deque, defaultdict
15+
from itertools import cycle
16+
from threading import Event
1517

1618
from can import Message, CanError, BusABC
1719

@@ -55,6 +57,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5557
# Use inter-process mutex to prevent concurrent device open.
5658
# When neoVI server is enabled, there is an issue with concurrent device open.
5759
open_lock = FileLock(os.path.join(tempfile.gettempdir(), "neovi.lock"))
60+
description_id = cycle(range(1, 0x8000))
5861

5962

6063
class ICSApiError(CanError):
@@ -176,6 +179,7 @@ def __init__(self, channel, can_filters=None, **kwargs):
176179
logger.info("Using device: {}".format(self.channel_info))
177180

178181
self.rx_buffer = deque()
182+
self.message_receipts = defaultdict(Event)
179183

180184
@staticmethod
181185
def channel_to_netid(channel_name_or_id):
@@ -261,9 +265,18 @@ def _process_msg_queue(self, timeout=0.1):
261265
for ics_msg in messages:
262266
if ics_msg.NetworkID not in self.channels:
263267
continue
268+
264269
is_tx = bool(ics_msg.StatusBitField & ics.SPY_STATUS_TX_MSG)
265-
if not self._receive_own_messages and is_tx:
266-
continue
270+
271+
if is_tx:
272+
if bool(ics_msg.StatusBitField & ics.SPY_STATUS_GLOBAL_ERR):
273+
continue
274+
if ics_msg.DescriptionID:
275+
receipt_key = (ics_msg.ArbIDOrHeader, ics_msg.DescriptionID)
276+
self.message_receipts[receipt_key].set()
277+
if not self._receive_own_messages:
278+
continue
279+
267280
self.rx_buffer.append(ics_msg)
268281
if errors:
269282
logger.warning("%d error(s) found", errors)
@@ -343,7 +356,19 @@ def _recv_internal(self, timeout=0.1):
343356
return None, False
344357
return msg, False
345358

346-
def send(self, msg, timeout=None):
359+
def send(self, msg, timeout=0):
360+
"""Transmit a message to the CAN bus.
361+
362+
:param Message msg: A message object.
363+
364+
:param float timeout:
365+
If > 0, wait up to this many seconds for message to be ACK'ed.
366+
If timeout is exceeded, an exception will be raised.
367+
None blocks indefinitely.
368+
369+
:raises can.CanError:
370+
if the message could not be sent
371+
"""
347372
if not ics.validate_hobject(self.dev):
348373
raise CanError("bus not open")
349374
message = ics.SpyMessage()
@@ -379,7 +404,20 @@ def send(self, msg, timeout=None):
379404
else:
380405
raise ValueError("msg.channel must be set when using multiple channels.")
381406

407+
msg_desc_id = next(description_id)
408+
message.DescriptionID = msg_desc_id
409+
receipt_key = (msg.arbitration_id, msg_desc_id)
410+
411+
if timeout != 0:
412+
self.message_receipts[receipt_key].clear()
413+
382414
try:
383415
ics.transmit_messages(self.dev, message)
384416
except ics.RuntimeError:
385417
raise ICSApiError(*ics.get_last_api_error(self.dev))
418+
419+
# If timeout is set, wait for ACK
420+
# This requires a notifier for the bus or
421+
# some other thread calling recv periodically
422+
if timeout != 0 and not self.message_receipts[receipt_key].wait(timeout):
423+
raise CanError("Transmit timeout")

can/interfaces/pcan/basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,10 @@ def __init__(self):
545545
logger.error("Exception: The PEAK-driver couldn't be found!")
546546
finally:
547547
winreg.CloseKey(aReg)
548+
elif "CYGWIN" in platform.system():
549+
self.__m_dllBasic = cdll.LoadLibrary("PCANBasic.dll")
550+
# Unfortunately cygwin python has no winreg module, so we can't
551+
# check for the registry key.
548552
elif platform.system() == "Darwin":
549553
self.__m_dllBasic = cdll.LoadLibrary("libPCBUSB.dylib")
550554
else:

0 commit comments

Comments
 (0)