Main Content

read

Read messages from CAN channel

Since R2020a

Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.

Description

message = read(ch) reads a timetable of CAN messages received on the CAN channel ch.

example

message = read(ch,maxMessages) reads a timetable of CAN messages less than or equal to maxMessages received on the CAN channel ch.

example

Examples

Read CAN Messages

Read messages as a timetable.

arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN');
ch = canChannel(arduinoObj,"Sparkfun CAN-Bus Shield", "BusSpeed", 500e3);
read(ch)

The output message timetable

Read Specified Number of CAN Messages

Read messages as a timetable.

arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN');
ch = canChannel(arduinoObj,"Sparkfun CAN-Bus Shield", "BusSpeed", 500e3);
read(ch,5)

The output message timetable

Use database to see the 'Name' field populated in the output message timetable.

db = canDatabase(demoVNT_CANdbFiles.dbc);
ch.Database = db;
read(ch,5)

Input Arguments

collapse all

Connection to the CAN channel specified as an object.

Maximum number of messages to read, specified as a positive numeric value. If fewer messages are available than maxMessages , the function returns the currently available messages. If no messages are available, the function returns an empty timetable.

Output Arguments

collapse all

CAN messages from the channel, returned as a timetable of messages. With Vehicle Network Toolbox™ the message output will have additional information about CAN messages. When database property is used, the Name and Signals information of messages will also be filled.

Note

Error and Remote frames are not supported.

Version History

Introduced in R2020a

See Also

|