Main Content

canMessageImport

Import CAN messages from third-party log file

Description

message = canMessageImport(file,vendor) imports CAN messages from the log file, file, from a third-party vendor, vendor. All the messages in the log file are imported as an array of CAN message objects, or a cell array with one channel per element.

After importing, you can analyze, transmit, or replay these messages.

canMessageImport assumes that the information in the imported log file is in a hexadecimal format, and that the timestamps in the imported log file are absolute values.

example

message = canMessageImport(file,vendor,candb) applies the information in the specified database to the imported CAN log messages.

To import Vector log files with symbolic message names, specify an appropriate database file.

example

message = canMessageImport(___,'OutputFormat','timetable') returns a timetable of messages. This is the recommended output format for optimal performance and representation of CAN messages within MATLAB®. The default is to return an array of CAN messages.

message = canMessageImport(___,'ChannelID',chanID) returns data for only the specified channel, chanID. By default, all channels are returned.

example

Examples

collapse all

Import raw messages from a log file.

message = canMessageImport('MsgLog.asc','Vector','OutputFormat','timetable');

Import messages from a log file, using database information for physical messages.

candb = canDatabase('myDatabase.dbc');
message = canMessageImport('MsgLog.txt','Kvaser',candb,'OutputFormat','timetable');

From a log file with data from three channels, view the data from channel 2.

Read all channels into a cell array of timetables.

d = canMessageImport("ASC_3CH.asc", "Vector", OutputFormat="timetable")
d =

  3×1 cell array

    {2×12 timetable}
    {3×8  timetable}
    {1×8  timetable}

Index into the cell array for the specific channel

channel2Data = d{2};

Alternatively, specify the channel when importing.

channel2Data = canMessageImport("ASC_3CH.asc", "Vector", OutputFormat="timetable", ChannelID=2);

Input Arguments

collapse all

Name of CAN message log file, specified as a character vector or string.

Example: 'MsgLog.asc'

Data Types: char | string

Name of vendor, specified as a character vector or string, whose CAN message log file you are importing from.

You can import message logs only in certain file formats: ASCII files from Vector, and text files from Kvaser.

Example: 'Vector'

Data Types: char | string

CAN database, specified as a database object. This is the database whose information is applied to the imported log file messages.

Example: candb = canDatabase('CANdb.dbc')

Channel ID, specified as a numeric scalar value, indicating which channel data to import from the log file. If not specified, all channels are read. When importing only one channel, the function returns an array of CAN messages or a timetable, depending on the OutputFormat argument. When importing multiple channels, the function returns a cell array of messages or timetables, with one element per channel.

Example: 2

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Imported messages, returned as an array of CAN message objects or as a timetable of messages for an individual channel specified by the ChannelID argument. When importing multiple channels, the function returns a cell array of messages or timetables, with one element per channel.

Version History

Introduced in R2010b

expand all

See Also

Functions