Skip to Main Content Skip to Search
Product Documentation

Loading and Creating Messages Using the .dbc File

Loading the CAN Database

To use a CANdb file, load the database into your MATLAB session. At the MATLAB command prompt, type:

db = canDatabase('filename.dbc')

Here db is a variable you chose for your database handle and filename.dbc is the actual file name of your CAN database. If your CAN database is not in the current working directory, type the path to the database:

db = canDatabase('path\filename.dbc')

This command returns a database object that you can use to create and interpret CAN messages using information stored in the database. Refer to the canDatabase function for more information.

Creating a CAN Message

This example shows you how to create a message using a database constructed specifically for a demo. You can access this database in the Toolbox > VNT > VNTDemos subfolder in your MATLAB installation folder. This database has a message, EngineMsg. To try this example, create messages and signals using definitions in your own database.

  1. Create the CAN database object:

    d = canDatabase('demoVNT_CANdbFiles.dbc')
  2. Create a CAN message using the message name in the database:

    message = canMessage(d, 'EngineMsg')

Accessing Signals in the Constructed CAN Message

You can access the two signals defined for the message you created in the example database, message. You can also change the values for some signals.

  1. To display signals in your message, type:

    sig = (message.Signals)

    Signals in the message are displayed as follows:

    sig = 
    
        VehicleSpeed: 0
           EngineRPM: 250
  2. Change the value of the EngineRPM signal:

    message.Signals.EngineRPM = 300
  3. Display signal information again to see the change:

    sig
    
    sig = 
    
        VehicleSpeed: 0
           EngineRPM: 300

Adding a Database to a CAN Channel

To add a database to the CAN channel canch, type:

canch.Database = canDatabase('Mux.dbc') 

For more information, see the Database property.

Updating Database Information

When you make changes to a database file:

  1. Reload the database file into your MATLAB session using the canDatabase function.

  2. Reattach the database to messages using the attachDatabase function.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS