Receive messages from CAN bus


message = receive(canch, messagesrequested)


message = receive(canch, messagesrequested) returns an array of CAN message objects received on the CAN channel canch. The number of messages returned is less than or equal to messagesrequested. If fewer messages are available than messagesrequested specifies, the function returns the currently available messages. If no messages are available, the function returns an empty array. If messagesrequested is infinite, the function returns all available messages.

To understand the elements of a message, refer to canMessage.

Input Arguments


The CAN channel from which to receive the message.


The maximum count of messages to receive. The specified value must be a nonzero and positive, or Inf.

Output Arguments


An array of CAN message objects received from the channel.


Receive Message Properties

MessageReceivedFcnSpecify function to run
MessageReceivedFcnCountSpecify number of messages available before function is triggered
MessagesAvailableDisplay number of messages available to be received by CAN channel
MessagesReceivedDisplay number of messages received by CAN channel
MessagesTransmittedDisplay number of messages transmitted by CAN channel

Error Log Properties

ReceiveErrorCountDisplay number of received errors detected by channel
TransmitErrorCountDisplay number of transmitted errors by channel


canch = canChannel('Vector','CANCaseXL 1',1)
message = receive(canch,5)

To receive all messages, type:

message = receive(canch,Inf)
Was this topic helpful?