Skip to content

Commit 994241e

Browse files
author
Giuseppe Corbelli
committed
Added CANMSG.__str__
1 parent 9c9860f commit 994241e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

can/interfaces/ixxat/structures.py

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Copyright (C) 2016 Giuseppe Corbelli <[email protected]>
55
"""
66

7+
import binascii
78
import ctypes
89

910

@@ -145,10 +146,15 @@ class Bits(ctypes.Structure):
145146
class CANMSG(ctypes.Structure):
146147
_fields_ = [
147148
("dwTime", ctypes.c_uint32),
149+
# CAN ID of the message in Intel format (aligned right) without RTR bit.
148150
("dwMsgId", ctypes.c_uint32),
149151
("uMsgInfo", CANMSGINFO),
150152
("abData", ctypes.c_uint8 * 8),
151153
]
154+
def __str__(self):
155+
return """ID: 0x{0:04x}{1} DLC: {2:02d} DATA: {3}""".format(
156+
self.dwMsgId, "[RTR]" if self.uMsgInfo.Bits.rtr else "", self.uMsgInfo.Bits.dlc, binascii.hexlify(self.abData, ' ')
157+
)
152158

153159

154160
PCANMSG = ctypes.POINTER(CANMSG)

0 commit comments

Comments
 (0)