This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

canMessage

Build CAN message based on user-specified structure

Syntax

message = canMessage(id,extended,datalength)
message = canMessage(id,extended,datalength,'ProtocolMode','CAN FD')
message = canMessage(candb,messagename)

Description

example

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.

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: 5000
        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(string([(matlabroot) '\examples\vnt\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('J1939.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 the following properties:

PropertyPurpose
BRSCAN FD bit rate switch, as true or false
Data

Data of CAN message or J1939 parameter group

Database

CAN database information

DLCData length code value
Error

CAN message error frame, as true or false

ESICAN FD error state indicator, as true or false
Extended

True of false indication of extended CAN Identifier type

ID

Identifier for CAN message

LengthMessage length in bytes
Name

CAN message name

ProtocolModeProtocol mode defined as CAN or CAN FD
Remote

Specify if CAN message is remote frame

Signals

Physical signals defined in CAN message or J1939 parameter group

Timestamp

Message received timestamp

UserData

Custom data

Introduced in R2009a