Can I attach multiple DBC files to a single "canChannel" object?

21 views (last 30 days)
I am using the Vehicle Network Toolbox, and would like to either concatenate two DBC files or attach multiple DBC files to the same "canChannel" object. Is this possible?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 25 Jul 2024
Edited: MathWorks Support Team on 20 Aug 2024
While you cannot concatenate multiple DBC objects or attach multiple to the same CAN Channel, there is a workaround for accomplishing the same end result.
Generally, the reason you would want to do this is because your message definitions are split between two different database files, and therefore you need both DBC files to decode all of your messages.
Attached is an example script which demonstrates how you can go about decoding a timetable of messages whose definitions are in different DBC files. Essentially, you attach one of the databases to the RX CAN channel object, whose messages are decoded upon receipt and returned as a timetable.
 
% Open two example DBC files (notice they have no conflicting IDs) db1 = canDatabase("CANBus.dbc"); db1.MessageInfo.ID db2 = canDatabase('CruiseControl.dbc'); db2.MessageInfo.ID % Create virtual tx and rx channels txCh = canFDChannel('MathWorks', 'Virtual 1', 1); rxCh = canFDChannel('MathWorks', 'Virtual 1', 2); % Configure both channels configBusSpeed(txCh, 500000, 1000000); configBusSpeed(rxCh, 500000, 1000000); % Attach the first database to the receiving channel rxCh.Database = db1; % Start up both channels start(txCh); start(rxCh); % Create three messages, two which are defined in db1, and one which is % defined in db2 msg1 = canMessage(100, false, 8); msg2 = canMessage(200, false, 8); msg3 = canMessage(512, false, 8); % Transmit the messages transmit(txCh, [msg1 msg2 msg3]); % Receive the messages disp("After decoding db1 messages:") rxMsg = receive(rxCh, Inf,'OutputFormat','timetable') % Decode the messages which are defined in db2 disp("After decoding both db1 and db2 messages:") rxMsg = canMessageTimetable(rxMsg, db2) % Stop and clear both channels stop(txCh); stop(rxCh); clear all
You can then call "canMessageTimetable" on the output timetable, specifying the second DBC file you wish to use for decoding.
Note that if there are any conflicting message IDs between the two DBC files, "canMessageTimetable" will overwrite any messages which were initially decoded using the first DBC. Consequently, you will want to make sure the two DBC files do not have any overlapping IDs.
If there are more than 2 databases, create a database array of "canDatabase" objects and pass it on as the second argument to "canMessageTimetable".

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!