From b422a3992a51359c7a3177cf9473381331f36655 Mon Sep 17 00:00:00 2001 From: Billy Rooke Date: Mon, 6 Jan 2025 13:06:31 +0000 Subject: [PATCH 1/3] Enable LOCAL_TXACK to fix is_rx for Kvaser --- can/interfaces/kvaser/canlib.py | 11 +++++++++++ can/interfaces/kvaser/constants.py | 1 + 2 files changed, 12 insertions(+) diff --git a/can/interfaces/kvaser/canlib.py b/can/interfaces/kvaser/canlib.py index 51a77a567..426fa1573 100644 --- a/can/interfaces/kvaser/canlib.py +++ b/can/interfaces/kvaser/canlib.py @@ -554,6 +554,15 @@ def __init__( 1, ) + # enable canMSG_LOCAL_TXACK in messages from write handle + + canIoCtlInit( + self._read_handle, + canstat.canIOCTL_SET_LOCAL_TXACK, + ctypes.byref(ctypes.c_byte(local_echo)), + 1, + ) + if self.single_handle: log.debug("We don't require separate handles to the bus") self._write_handle = self._read_handle @@ -671,6 +680,7 @@ def _recv_internal(self, timeout=None): is_remote_frame = bool(flags & canstat.canMSG_RTR) is_error_frame = bool(flags & canstat.canMSG_ERROR_FRAME) is_fd = bool(flags & canstat.canFDMSG_FDF) + is_rx = not bool(flags & canstat.canMSG_LOCAL_TXACK) bitrate_switch = bool(flags & canstat.canFDMSG_BRS) error_state_indicator = bool(flags & canstat.canFDMSG_ESI) msg_timestamp = timestamp.value * TIMESTAMP_FACTOR @@ -682,6 +692,7 @@ def _recv_internal(self, timeout=None): is_error_frame=is_error_frame, is_remote_frame=is_remote_frame, is_fd=is_fd, + is_rx=is_rx, bitrate_switch=bitrate_switch, error_state_indicator=error_state_indicator, channel=self.channel, diff --git a/can/interfaces/kvaser/constants.py b/can/interfaces/kvaser/constants.py index 3d01faa84..4d6c722e7 100644 --- a/can/interfaces/kvaser/constants.py +++ b/can/interfaces/kvaser/constants.py @@ -63,6 +63,7 @@ def CANSTATUS_SUCCESS(status): canMSG_ERROR_FRAME = 0x0020 canMSG_TXACK = 0x0040 canMSG_TXRQ = 0x0080 +canMSG_LOCAL_TXACK = 0x1000_0000 canFDMSG_FDF = 0x010000 canFDMSG_BRS = 0x020000 From e0a8d17d678332a1f4d1da3a5391a92a1eb385b9 Mon Sep 17 00:00:00 2001 From: Billy Rooke Date: Mon, 6 Jan 2025 13:11:05 +0000 Subject: [PATCH 2/3] Add missing constant definition --- can/interfaces/kvaser/constants.py | 1 + 1 file changed, 1 insertion(+) diff --git a/can/interfaces/kvaser/constants.py b/can/interfaces/kvaser/constants.py index 4d6c722e7..dc710648c 100644 --- a/can/interfaces/kvaser/constants.py +++ b/can/interfaces/kvaser/constants.py @@ -196,6 +196,7 @@ def CANSTATUS_SUCCESS(status): canIOCTL_GET_USB_THROTTLE = 29 canIOCTL_SET_BUSON_TIME_AUTO_RESET = 30 canIOCTL_SET_LOCAL_TXECHO = 32 +canIOCTL_SET_LOCAL_TXACK = 46 canIOCTL_PREFER_EXT = 1 canIOCTL_PREFER_STD = 2 canIOCTL_CLEAR_ERROR_COUNTERS = 5 From c8774266706c2eb1e32531cc40debcd38226fc1a Mon Sep 17 00:00:00 2001 From: Billy Rooke Date: Mon, 6 Jan 2025 13:46:51 +0000 Subject: [PATCH 3/3] Update comment --- can/interfaces/kvaser/canlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/interfaces/kvaser/canlib.py b/can/interfaces/kvaser/canlib.py index 426fa1573..9731a4415 100644 --- a/can/interfaces/kvaser/canlib.py +++ b/can/interfaces/kvaser/canlib.py @@ -554,7 +554,7 @@ def __init__( 1, ) - # enable canMSG_LOCAL_TXACK in messages from write handle + # enable canMSG_LOCAL_TXACK flag in received messages canIoCtlInit( self._read_handle,