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
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.
5 changes: 4 additions & 1 deletion 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 All @@ -45,7 +47,8 @@ Serial frame format
+-------------------+----------------+-----------------------------------------------+-------------------------------+-------------------------+---------+--------------+
| **Byte order** | \- | Little-Endian | Little-Endian | Little-Endian | \- | \- |
+-------------------+----------------+-----------------------------------------------+-------------------------------+-------------------------+---------+--------------+
| **Description** | Must be 0xAA | Usually s, ms or µs since start of the device | Length in byte of the payload | \- | \- | Must be 0xBB |
| **Description** | Must be 0xAA | Usually s, ms or µs since start of the device | Payload length; requested | \- | \- | Must be 0xBB |
| | | | data length for remote frames | | | |
+-------------------+----------------+-----------------------------------------------+-------------------------------+-------------------------+---------+--------------+

Examples of serial frames
Expand Down
20 changes: 12 additions & 8 deletions test/serial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,18 @@ def test_rx_tx_err_frame(self):

def test_rx_tx_rtr_frame(self):
"""
Test the transfer of remote frames.
"""
msg = can.Message(
is_extended_id=False, is_error_frame=False, is_remote_frame=True
)
self.bus.send(msg)
msg_receive = self.bus.recv()
self.assertMessageEqual(msg, msg_receive)
Test the transfer of remote frames, with and without a requested length.
"""
for dlc in (0, 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):
"""
Expand Down
Loading