Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
PCAN_MESSAGE_FD,
PCAN_MESSAGE_RTR,
PCAN_MESSAGE_STANDARD,
PCAN_MESSAGE_STATUS,
PCAN_NONEBUS,
PCAN_PARAMETER_OFF,
PCAN_PARAMETER_ON,
Expand Down Expand Up @@ -518,6 +519,8 @@ def _recv_internal(self, timeout: float | None) -> tuple[Message | None, bool]:
)

if result == PCAN_ERROR_OK:
if pcan_msg.MSGTYPE & PCAN_MESSAGE_STATUS.value:
continue
# message received
break

Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2133.fixed.rst

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to the PR number

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip PCAN controller status frames instead of returning them as CAN messages.
28 changes: 28 additions & 0 deletions test/test_pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,34 @@ def test_recv_fd(self):
self.assertEqual(recv_msg.timestamp, 0)
self.assertEqual(recv_msg.channel, "PCAN_USBBUS1")

@parameterized.expand([("classic", False), ("fd", True)])
def test_recv_skips_status_frames(self, name, fd):
if fd:
status = TPCANMsgFD(ID=1, DLC=4, MSGTYPE=PCAN_MESSAGE_STATUS.value)
data = TPCANMsgFD(ID=1, DLC=1, MSGTYPE=PCAN_MESSAGE_FD.value)
timestamp = TPCANTimestampFD()
read = self.mock_pcan.ReadFD
else:
status = TPCANMsg(ID=1, LEN=4, MSGTYPE=PCAN_MESSAGE_STATUS.value)
data = TPCANMsg(ID=1, LEN=1, MSGTYPE=PCAN_MESSAGE_STANDARD.value)
timestamp = TPCANTimestamp()
read = self.mock_pcan.Read
data.DATA[0] = 0xAB
read.side_effect = [
(PCAN_ERROR_OK, status, timestamp),
(PCAN_ERROR_OK, data, timestamp),
(PCAN_ERROR_OK, status, timestamp),
(PCAN_ERROR_QRCVEMPTY, type(status)(), timestamp),
]
self.bus = can.Bus(interface="pcan", fd=fd)

recv_msg = self.bus.recv(timeout=0)
self.assertIsNotNone(recv_msg)
self.assertEqual(recv_msg.arbitration_id, 1)
self.assertEqual(recv_msg.is_fd, fd)
self.assertSequenceEqual(recv_msg.data, [0xAB])
self.assertIsNone(self.bus.recv(timeout=0))

def _load_timestamp_backend(self, linux: bool) -> ModuleType:
# The platform choice is made at import time; use a separate namespace.
spec = importlib.util.spec_from_file_location(
Expand Down
Loading