How to send a message with new CAN driver

Can someone please post an example of how to send a message with the new CAN driver? The documentation is good about showing how to receive a message, but…

Is is simple.
int numberOf messagesThatWasPosted = PostMessags(msgList, index into the megList, number of messages to send);

Actually, it’s not so simple :smiley:
The definition of the method to post a message is:
public int PostMessages(
CAN.Message[] msg,
int offset,
int count

But this method takes an array of CAN messages which are defined as readonly. How do I initialize a read only array with the data that I want to send?

Could you please post an actual working sample?


I see. We will add this to the example we have:

// example for sending one message
// msg ID
msgList[0].ArbID = 0x55;
msgList[0].Data[0] = 1;
msgList[0].Data[1] = 2;
msgList[0].Data[2] = 3;
msgList[0].Data[3] = 4;
msgList[0].Data[4] = 5;
msgList[0].Data[5] = 6;
msgList[0].Data[6] = 7;
msgList[0].Data[7] = 8;
// Send the 8 bytes for example
msgList[0].DLC = 8;
msgList[0].IsEID = false;
msgList[0].IsRTR = false;
// Send one messages
int numbeOfMessagesPosted = can.PostMessages(msgList, 0, 1);