Main Content

can.Message Properties

Properties of the can.Message object

Use the following properties to examine or configure CAN and CAN FD message settings. Use canMessage to create a CAN message.

Message Identification

expand all

This property is read-only.

The ProtocolMode property indicates the communication protocol for which the CAN message is configured, either CAN or CAN FD.

The value is defined when you configure the message with the canChannel function.

Data Types: char

This property is read-only.

The ID property represents a numeric identifier for a CAN message. The values range:

  • 0 through 2047 for a standard identifier

  • 0 through 536,870,911 for an extended identifier

You can configure the message ID when constructing it. For example, to set a standard identifier of value 300 and a data length of eight bytes, type:

message = canMessage(300,false,8)

For hexadecimal values, convert using the hex2dec function.

Data Types: double

This property is read-only.

The Extended property is the identifier type for a CAN message. It can either be a standard identifier or an extended identifier, according to the following values:

  • false — The identifier type is standard (11 bits).

  • true — The identifier type is extended (29 bits).

You can configure the message extended property when constructing it. For example, to set the message identifier type to extended, with the ID set to 2350, and the data length to eight bytes, type:

message = canMessage(2350,true,8)

Data Types: logical

This property is read-only.

The Name property displays the name of the message, as a character vector value. This value is acquired from the name of the message you defined in the database. You cannot edit this property if you are defining raw messages.

Data Types: char

Data Details

expand all

The Timestamp property displays the time at which the message was received on a CAN channel. This time is based on the receiving channel start time.

You might want to set the value when constructing a message. For example, to set the time stamp of a message to 12, type:

message.Timestamp = 12

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

Use the Data property to define the raw data in a CAN message. The data is an array of uint8 values, based on the data length you specify in the message.

For example, to create a CAN message and define its data:

message = canMessage(2500,true,8)
message.Data = [23 43 23 43 54 34 123 1]

If you are using a CAN database for your message definitions, you can directly specify values in the Signals property structure.

You can also use the pack function to load data into your message.

Data Types: uint8

The Signals property allows you to view and edit decoded signal values defined for a CAN message. This property displays an empty structure if the message has no defined signals or a database is not attached to the message. The input values for this property depend on the signal type.

Create a CAN message.

message = canMessage(canDb,'messageName');

Display message signals.

message.Signals
    VehicleSpeed: 0
       EngineRPM: 250

Change the value of a signal.

message.Signals.EngineRPM = 300

Data Types: struct

Length of the CAN message in bytes, specified as a uint8 value. This indicates the number of elements in the Data vector. For CAN messages this is limited to 8 bytes; for CAN FD messages the length can be 0-8, 12, 16, 20, 24, 32, 48, or 64 bytes.

Data Types: uint8

This property is read-only.

Length code of the CAN FD message data, returned as a uint8 value. This relates to the Length property: for sizes up to 8 bytes they are the same, but DLC values ranging from 9 (binary 1001) to 15 (binary 1110) are used to specify the data lengths of 12, 16, 20, 24, 32, 48, and 64 bytes. For more information, see CAN FD - The Basic Idea.

Data Types: uint8

Protocol Flags

expand all

The BRS property indicates that the CAN FD message bit rate switch is set. This determines whether the bit rate for the data phase of the message is faster (true) or the same (false) as the bit rate of the arbitration phase. For more information, see CAN FD - The Basic Idea.

Data Types: logical

This property is read-only.

The ESI property indicates that the CAN FD message error state indicator flag is set. For more information, see CAN FD - The Basic Idea.

Data Types: logical

This property is read-only.

The Error property indicates if true that the CAN message is an error frame.

Data Types: logical

Use the Remote property to specify the CAN message as a remote frame.

  • false (default) — The message is not a remote frame.

  • true — The message is a remote frame.

To change the default value of Remote and make the message a remote frame, type:

message.Remote = true

Data Types: logical

Other Information

expand all

The Database property stores information about an attached CAN database. If your channel message is not attached to a database, the property value is an empty structure, []. You can edit the CAN channel Database property, but cannot edit the CAN message Database property.

To see information about the database attached to your CAN message, type:

message.Database

To set the database information on your CAN channel to C:\Database.dbc, type:

channel.Database = canDatabase('C:\Database.dbc')

Tip

CAN database file names containing non-alphanumeric characters such as equal signs and ampersands are incompatible with Vehicle Network Toolbox™. You can use a period in your database name. Rename any CAN database files with non-alphanumeric characters before you use them.

Data Types: struct

Enter custom data to be stored in your CAN message or a J1939 parameter group, channel, or database object using the UserData property. When you save an object with UserData specified, you automatically save the custom data. When you load an object with UserData specified, you automatically load the custom data.

Tip

To avoid unexpected results when you save and load an object with UserData, specify your custom data in simple data types and constructs.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | function_handle | categorical | datetime | duration | calendarDuration | fi
Complex Number Support: Yes

Version History

Introduced in R2009a