From 0de8ca82f1c18afff438a7c0efba5f512ea6581e Mon Sep 17 00:00:00 2001 From: BroderickJack <39026705+BroderickJack@users.noreply.github.com> Date: Sat, 22 Jun 2024 07:03:11 -0400 Subject: [PATCH] Support CANdapter extended length arbitration ID (#1528) * Support CANdapter extended length arbitration ID * Update can/interfaces/slcan.py More efficient check of arbitration ID Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> * Add description of x extended arbitration identifier * Add test for CANDapter extended arbitration ID * Update test/test_slcan.py Type fix in slcan test Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> * format black --------- Co-authored-by: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> --- can/interfaces/slcan.py | 5 ++++- test/test_slcan.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/can/interfaces/slcan.py b/can/interfaces/slcan.py index f32d82fd0..f023e084c 100644 --- a/can/interfaces/slcan.py +++ b/can/interfaces/slcan.py @@ -215,7 +215,10 @@ def _recv_internal( if not string: pass - elif string[0] == "T": + elif string[0] in ( + "T", + "x", # x is an alternative extended message identifier for CANDapter + ): # extended frame canId = int(string[1:9], 16) dlc = int(string[9]) diff --git a/test/test_slcan.py b/test/test_slcan.py index f74207b9f..af7ae60c4 100644 --- a/test/test_slcan.py +++ b/test/test_slcan.py @@ -43,6 +43,16 @@ def test_recv_extended(self): self.assertEqual(msg.dlc, 2) self.assertSequenceEqual(msg.data, [0xAA, 0x55]) + # Ewert Energy Systems CANDapter specific + self.serial.write(b"x12ABCDEF2AA55\r") + msg = self.bus.recv(TIMEOUT) + self.assertIsNotNone(msg) + self.assertEqual(msg.arbitration_id, 0x12ABCDEF) + self.assertEqual(msg.is_extended_id, True) + self.assertEqual(msg.is_remote_frame, False) + self.assertEqual(msg.dlc, 2) + self.assertSequenceEqual(msg.data, [0xAA, 0x55]) + def test_send_extended(self): msg = can.Message( arbitration_id=0x12ABCDEF, is_extended_id=True, data=[0xAA, 0x55]