Main Content

read

Read messages from CAN channel

Description

example

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.

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.

See Also

|

Introduced in R2020a