Skip to content
Open
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
4 changes: 3 additions & 1 deletion can/interfaces/serial/serial_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ def _recv_internal(self, timeout: float | None) -> tuple[Message | None, bool]:
else:
arbitration_id = arbitration_id & CAN_ID_MASK_STD

data = self._ser.read(dlc)
# a remote frame carries the requested length in the DLC but
# no payload, see send()
data = b"" if is_remote_frame else self._ser.read(dlc)

delimiter_byte = ord(self._ser.read())
if delimiter_byte == 0xBB:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2151.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the serial interface reading payload bytes for received remote frames, which broke the stream for remote frames with a DLC above 0.
2 changes: 2 additions & 0 deletions doc/interfaces/serial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ arbitration ID will be interpreted as 4 byte unsigned integers. The DLC is
also an unsigned integer with a length of 1 byte. Extended (29-bit)
identifiers are encoded by adding 0x80000000 to the ID. For example, a
29-bit CAN ID of 0x123 is encoded with an arbitration ID of 0x80000123.
Remote frames set bit 30 (0x40000000) of the arbitration ID. They have no
payload; their DLC holds the requested data length.

Serial frame format
^^^^^^^^^^^^^^^^^^^
Expand Down
15 changes: 15 additions & 0 deletions test/serial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ def test_rx_tx_rtr_frame(self):
msg_receive = self.bus.recv()
self.assertMessageEqual(msg, msg_receive)

def test_rx_tx_rtr_frame_with_dlc(self):
"""
Test the transfer of remote frames that request data.
"""
for dlc in (1, 8):
msg = can.Message(
arbitration_id=0x123,
is_extended_id=False,
is_remote_frame=True,
dlc=dlc,
)
self.bus.send(msg)
msg_receive = self.bus.recv()
self.assertMessageEqual(msg, msg_receive)

def test_when_no_fileno(self):
"""
Tests for the fileno method catching the missing pyserial implementeation on the Windows platform
Expand Down
Loading