How to update CAN Pack / CAN Unpack blocks in the Vehicle Network Toolbox programatically when a new DBC file is loaded?
8 views (last 30 days)
Show older comments
MathWorks Support Team
on 29 May 2012
Edited: MathWorks Support Team
on 5 Jul 2023
I am using the Vehicle Network Toolbox and Simulink version R2017b. In my current workflow, I add CAN Pack / CAN Unpack programmatically to my model which is assigned to a CAN database (DBC file).
My problem is, that the blocks are not updated properly if the DBC is modified. For example, inputs and outputs do not show up in the block appearance. Updating and simulating the model does not help.
Only opening the block dialog box and closing it with Ok solves the problem. This can be very tedious for models with many blocks.
Now, I am looking for a way to implement this update process programmatically into my code.
Does Simulink provide a feature for this?
Accepted Answer
MathWorks Support Team
on 4 Jul 2023
Edited: MathWorks Support Team
on 5 Jul 2023
MATLAB R2019b onwards:
You can programmatically achieve the desired workflow by creating an automated function to programmatically search, open, and then close the block masks. This can be done by programmatically obtaining all the handles for CAN Pack/Unpack blocks, and then looping through and opening and closing these block's masks if their data format is specified by a DBC file.
Please refer to the attached function "updateCAN.m" for an example of the above workflow. To call the function you can pass the Simulink model name as an input string:
>> updateCAN("modelName")
MATLAB R2015a to MATLAB R2019a:
You can use the attached, "slUpdateCANblock.p" file to perform the update process. You can call the script like a normal function:
>> slUpdateCANblock(gcb)
MATLAB R2014b and earlier:
You can use the the attached "slUpdateCANblock_pre2015a.p" file to perform the update process. You can call the script as a normal function:
>> slUpdateCANblock_pre2015a(gcb)
1 Comment
More Answers (0)
See Also
Categories
Find more on Vehicle Network Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!