Load .dbc Files and Create Messages
Vector CAN Database Support
Vehicle Network Toolbox™ allows you to use a Vector CAN database. The database
.dbc file contains definitions of CAN messages and signals.
Using the information defined in the database file, you can look up message and
signal information, and build messages. You can also represent message and signal
information in engineering units so that you do not need to manipulate raw data
Load the CAN Database
To use a CAN database file, load the database into your MATLAB® session. At the MATLAB command prompt, type:
db = canDatabase('filename.dbc')
db is a variable you chose for your database
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')
CAN database file names containing non-alphanumeric characters such as equal signs, ampersands, and so forth are incompatible with Vehicle Network Toolbox. You can use periods in your database name. Rename any CAN database files with non-alphanumeric characters before you use them.
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.
Create a CAN Message
This example shows you how to create a message using a database constructed
specifically for this example. 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.
Create the CAN database object.
cd ([matlabroot '\examples\vnt']) d = canDatabase('demoVNT_CANdbFiles.dbc');
Create a CAN message using the message name in the database.
message = canMessage(d,'EngineMsg');
Access Signals in the Constructed CAN Message
You can access the two signals defined for the message you created in the example
message. You can also change the values for some
To display signals in your message, type:
sig = message.Signals
sig = struct with fields: VehicleSpeed: 0 EngineRPM: 250
Change the value of the
message.Signals.EngineRPM = 300;
Reassign the signals and display them again to see the change.
sig = message.Signals
sig = struct with fields: VehicleSpeed: 0 EngineRPM: 300
Add a Database to a CAN Channel
To add a database to the CAN channel
canch.Database = canDatabase('Mux.dbc')
Update Database Information
When you make changes to a database file: