Main Content

canMessage

Build CAN message based on user-specified structure

Description

message = canMessage(id,extended,datalength) creates a CAN message object from the raw message information.

example

message = canMessage(id,extended,datalength,'ProtocolMode','CAN FD') creates a CAN FD message. The default ProtocolMode is standard 'CAN'.

example

message = canMessage(candb,messagename) creates a message using the message definition in the specified database. Because ProtocolMode is defined in the message database, you cannot specify it as an argument to canMessage when using a database.

example

Examples

collapse all

Create a CAN message with an extended ID format.

message1 = canMessage(2500,true,4)
message1 = 

  Message with properties:

   Message Identification
    ProtocolMode: 'CAN'
              ID: 2500
        Extended: 1
            Name: ''

   Data Details
       Timestamp: 0
            Data: [0 0 0 0]
         Signals: []
          Length: 4

   Protocol Flags
           Error: 0
          Remote: 0

   Other Information
        Database: []
        UserData: []

Create a CAN FD message with a standard ID format.

message2 = canMessage(1000,false,64,'ProtocolMode','CAN FD')
message2 = 

  Message with properties:

   Message Identification
    ProtocolMode: 'CAN FD'
              ID: 1000
        Extended: 0
            Name: ''

   Data Details
       Timestamp: 0
            Data: [1×64 uint8]
         Signals: []
          Length: 64
             DLC: 15

   Protocol Flags
             BRS: 0
             ESI: 0
           Error: 0

   Other Information
        Database: []
        UserData: []

Create a message using the definitions of a CAN database.

candb = canDatabase("C:\myVNTData\VehicleInfo.dbc")
message3 = canMessage(candb,"WheelSpeeds")
message3 = 

  Message with properties:

   Message Identification
    ProtocolMode: 'CAN'
              ID: 1200
        Extended: 0
            Name: 'WheelSpeeds'

   Data Details
       Timestamp: 0
            Data: [0 0 0 0 0 0 0 0]
         Signals: [1×1 struct]
          Length: 8

   Protocol Flags
           Error: 0
          Remote: 0

   Other Information
        Database: [1×1 can.Database]
        UserData: []

Input Arguments

collapse all

ID of the message, specified as a numeric value. If this ID used an extended format, set the extended argument true.

Example: 2500

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

Indicates whether the message ID is of standard or extended type, specified as true or false. The logical value true indicates that the ID is of extended type, false indicates standard type.

Example: true

Data Types: logical

The length of the message data, specified as an integer value of 0 through 8, inclusive.

Example: 8

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

CAN database, specified as a database object. The database contains the message definition.

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

The name of the message definition in the database, specified as a character vector or string.

Example: 'VehicleDataMulti'

Data Types: char | string

Output Arguments

collapse all

CAN message, returned as a CAN message object, with can.Message Properties.

Version History

Introduced in R2009a