Hi everyone,
I finally got the Linux-API working on my RaspberryPi with the PCAN USB bus. I am able to receive messages from my device, but am having trouble sending messages in the proper format. From the API, the message object should have the specified types:
Code: Select all
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])
Arbitration ID: 0x350
Data: 0x00AAFF
Would I be able to format it like so?:
Code: Select all
import ctypes
from PCANBasic import *
can = PCANBasic()
can.Initialize(PCAN_USBBUS1, PCAN_BAUD_500K) #Initialize CAN
ID = c_uint(0x350)
MSGTYPE = PCAN_MESSAGE_STANDARD #From the API
LEN = c_ubyte * 3 #Since data is 0x00AAFF
py_data = c_ubyte * 3 #Creates a list of length 3 ubytes
DATA = py_data(0x00, 0xAA, 0xFF)
MyMSG = TPCANMsg(ID, MSGTYPE, LEN, DATA)
can.Write(PCAN_USBBUS1, MyMSG)
Thank you!