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
42 changes: 39 additions & 3 deletions can/interfaces/pcan/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@


class TPCANMsg (Structure):
"""
Represents a PCAN message
"""
_fields_ = [ ("ID", c_uint), # 11/29-bit message identifier
("MSGTYPE", TPCANMessageType), # Type of the message
("LEN", c_ubyte), # Data Length Code of the message (0..8)
("DATA", c_ubyte * 8) ] # Data of the message (DATA[0]..DATA[7])


class TPCANMsgMac (Structure):
"""
Represents a PCAN message
"""
Expand All @@ -298,6 +308,16 @@ class TPCANMsg (Structure):


class TPCANTimestamp (Structure):
"""
Represents a timestamp of a received PCAN message
Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
"""
_fields_ = [ ("millis", c_uint), # Base-value: milliseconds: 0.. 2^32-1
("millis_overflow", c_ushort), # Roll-arounds of millis
("micros", c_ushort) ] # Microseconds: 0..999


class TPCANTimestampMac (Structure):
"""
Represents a timestamp of a received PCAN message
Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow
Expand All @@ -308,6 +328,15 @@ class TPCANTimestamp (Structure):


class TPCANMsgFD (Structure):
"""
Represents a PCAN message
"""
_fields_ = [ ("ID", c_uint), # 11/29-bit message identifier
("MSGTYPE", TPCANMessageType), # Type of the message
("DLC", c_ubyte), # Data Length Code of the message (0..15)
("DATA", c_ubyte * 64) ] # Data of the message (DATA[0]..DATA[63])

class TPCANMsgFDMac (Structure):
"""
Represents a PCAN message
"""
Expand Down Expand Up @@ -484,8 +513,12 @@ def Read(
A touple with three values
"""
try:
msg = TPCANMsg()
timestamp = TPCANTimestamp()
if platform.system() == 'Darwin':
msg = TPCANMsgMac()
timestamp = TPCANTimestampMac()
else:
msg = TPCANMsg()
timestamp = TPCANTimestamp()
res = self.__m_dllBasic.CAN_Read(Channel,byref(msg),byref(timestamp))
return TPCANStatus(res),msg,timestamp
except:
Expand Down Expand Up @@ -514,7 +547,10 @@ def ReadFD(
A touple with three values
"""
try:
msg = TPCANMsgFD()
if platform.system() == 'Darwin':
msg = TPCANMsgFDMac()
else:
msg = TPCANMsgFD()
timestamp = TPCANTimestampFD()
res = self.__m_dllBasic.CAN_ReadFD(Channel,byref(msg),byref(timestamp))
return TPCANStatus(res),msg,timestamp
Expand Down
5 changes: 4 additions & 1 deletion can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def send(self, msg, timeout=None):
msgType = PCAN_MESSAGE_STANDARD

# create a TPCANMsg message structure
CANMsg = TPCANMsg()
if platform.system() == 'Darwin':
CANMsg = TPCANMsgMac()
else:
CANMsg = TPCANMsg()

# configure the message. ID, Length of data, message type and data
CANMsg.ID = msg.arbitration_id
Expand Down
4 changes: 2 additions & 2 deletions can/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ def parse_args(args):
'\nNote that the IDs are always interpreted as hex values.'
'\nAn optional conversion from integers to real units can be given'
'\nas additional arguments. In order to convert from raw integer'
'\nvalues the values are multiplied with the corresponding scaling value,'
'\nsimilarly the values are divided by the scaling value in order'
'\nvalues the values are divided with the corresponding scaling value,'
'\nsimilarly the values are multiplied by the scaling value in order'
'\nto convert from real units to raw integer values.'
'\nFx lets say the uint8_t needs no conversion, but the uint16 and the uint32_t'
'\nneeds to be divided by 10 and 100 respectively:'
Expand Down