From dcb5cbc83086d5d64907002f89630560bb58be1f Mon Sep 17 00:00:00 2001 From: zhaojiale2021 <86412178+zhaojiale2021@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:50:24 +0000 Subject: [PATCH 1/3] Fix ASC reader CANoe 7 CAN FD layouts Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- can/io/asc.py | 52 +++++++++++++++++++++++++++++++++++++++++ test/logformats_test.py | 34 +++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/can/io/asc.py b/can/io/asc.py index 37de0d198..4479ce29b 100644 --- a/can/io/asc.py +++ b/can/io/asc.py @@ -235,6 +235,43 @@ def _process_classic_can_frame( return Message(**msg_kwargs) def _process_fd_can_frame(self, line: str, msg_kwargs: dict[str, Any]) -> Message: + fields = line.split() + if len(fields) >= 4 and fields[1] not in ("Rx", "Tx"): + # CANoe 7.x uses instead of + # . CANoe also writes FD DLC codes in + # decimal even for hex-base logs, so the data-length field decides + # between decimal and hexadecimal interpretation. + channel, can_id_str, direction = fields[:3] + msg_kwargs["channel"] = int(channel) - 1 + msg_kwargs["is_rx"] = direction == "Rx" + self._extract_can_id(can_id_str, msg_kwargs) + + rest = fields[3:] + if rest[:1] and rest[0].lower() == "errorframe": + msg_kwargs["is_error_frame"] = True + return Message(**msg_kwargs) + if len(rest) < 4: + return Message(**msg_kwargs) + + brs, esi = rest[0], rest[1] + index = 2 + if index < len(rest) and not rest[index].isdigit(): + index += 1 + if index + 1 >= len(rest): + return Message(**msg_kwargs) + + dlc_str = rest[index] + data_length = int(rest[index + 1]) + dlc = self._parse_fd_dlc(dlc_str, data_length) + msg_kwargs["is_fd"] = True + msg_kwargs["bitrate_switch"] = brs == "1" + msg_kwargs["error_state_indicator"] = esi == "1" + msg_kwargs["dlc"] = data_length + msg_kwargs["data"] = self._parse_data( + rest[index + 2:], data_length + ) + return Message(**msg_kwargs) + channel, direction, rest_of_message = line.split(None, 2) # See ASCWriter msg_kwargs["channel"] = int(channel) - 1 @@ -294,6 +331,21 @@ def _process_fd_can_frame(self, line: str, msg_kwargs: dict[str, Any]) -> Messag return Message(**msg_kwargs) + def _parse_fd_dlc(self, dlc_str: str, data_length: int) -> int: + """Resolve CANoe decimal and python-can hexadecimal DLC spellings.""" + candidates: list[int] = [] + for base in (self._converted_base, BASE_DEC): + try: + code = int(dlc_str, base) + except ValueError: + continue + if code not in candidates: + candidates.append(code) + for code in candidates: + if dlc2len(code) == data_length: + return code + return candidates[0] if candidates else 0 + def __iter__(self) -> Generator[Message, None, None]: first_line = self._extract_header() lines = ( diff --git a/test/logformats_test.py b/test/logformats_test.py index f1a8614ea..a936fff80 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -535,6 +535,40 @@ def test_roundtrip_empty_can_fd_data(self): (actual,) = reader self.assertTrue(msg.equals(actual, timestamp_delta=None)) + def test_read_canoe_7_can_fd_layout(self): + stream = StringIO( + "date Mon Oct 12 06:42:09 PM 2026\n" + "base hex timestamps absolute\n" + "// version 7.0.0\n" + "0.000000 CANFD 1 1d3 Rx 1 0 d 8 8 " + "78 88 00 00 00 00 0c e6\n" + ) + with can.ASCReader(stream) as reader: + (actual,) = reader + + self.assertTrue(actual.is_fd) + self.assertEqual(actual.arbitration_id, 0x1D3) + self.assertEqual(actual.channel, 0) + self.assertTrue(actual.is_rx) + self.assertTrue(actual.bitrate_switch) + self.assertEqual(actual.dlc, 8) + self.assertEqual(actual.data, b"\x78\x88\x00\x00\x00\x00\x0c\xe6") + + def test_read_canoe_7_decimal_fd_dlc(self): + stream = StringIO( + "base hex timestamps absolute\n" + "0.004238 CANFD 1 1e3 Rx 1 0 d 13 32 " + + " ".join(["00"] * 32) + + "\n" + ) + with can.ASCReader(stream) as reader: + (actual,) = reader + + self.assertTrue(actual.is_fd) + self.assertEqual(actual.arbitration_id, 0x1E3) + self.assertEqual(actual.dlc, 32) + self.assertEqual(len(actual.data), 32) + @parameterized.expand( [ ("empty_data", "0 0 0 0 0", False, 0, b""), From f93ee1719263b20cbc46f333f272044e186daffe Mon Sep 17 00:00:00 2001 From: zhaojiale2021 <86412178+zhaojiale2021@users.noreply.github.com> Date: Wed, 25 Nov 2026 05:51:45 +0000 Subject: [PATCH 2/3] Add CANoe 7 ASC fix changelog Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- doc/changelog.d/canoe7.fixed.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 doc/changelog.d/canoe7.fixed.rst diff --git a/doc/changelog.d/canoe7.fixed.rst b/doc/changelog.d/canoe7.fixed.rst new file mode 100644 index 000000000..9847d36db --- /dev/null +++ b/doc/changelog.d/canoe7.fixed.rst @@ -0,0 +1,3 @@ +Fixed ``ASCReader`` support for CANoe 7.x CAN FD records that place the CAN +identifier before the ``Rx``/``Tx`` direction. CANoe decimal DLC codes are now +resolved against the record's authoritative data-length field. From b5cec68974f26e6df9c0daec429c7faca77f61e4 Mon Sep 17 00:00:00 2001 From: zhaojiale2021 <86412178+zhaojiale2021@users.noreply.github.com> Date: Wed, 25 Nov 2026 06:16:33 +0000 Subject: [PATCH 3/3] Format CANoe ASC changes with Black Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- can/io/asc.py | 4 +--- test/logformats_test.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/can/io/asc.py b/can/io/asc.py index 4479ce29b..0f01f0c82 100644 --- a/can/io/asc.py +++ b/can/io/asc.py @@ -267,9 +267,7 @@ def _process_fd_can_frame(self, line: str, msg_kwargs: dict[str, Any]) -> Messag msg_kwargs["bitrate_switch"] = brs == "1" msg_kwargs["error_state_indicator"] = esi == "1" msg_kwargs["dlc"] = data_length - msg_kwargs["data"] = self._parse_data( - rest[index + 2:], data_length - ) + msg_kwargs["data"] = self._parse_data(rest[index + 2 :], data_length) return Message(**msg_kwargs) channel, direction, rest_of_message = line.split(None, 2) diff --git a/test/logformats_test.py b/test/logformats_test.py index a936fff80..cca9ddd59 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -557,9 +557,7 @@ def test_read_canoe_7_can_fd_layout(self): def test_read_canoe_7_decimal_fd_dlc(self): stream = StringIO( "base hex timestamps absolute\n" - "0.004238 CANFD 1 1e3 Rx 1 0 d 13 32 " - + " ".join(["00"] * 32) - + "\n" + "0.004238 CANFD 1 1e3 Rx 1 0 d 13 32 " + " ".join(["00"] * 32) + "\n" ) with can.ASCReader(stream) as reader: (actual,) = reader