I understand that when you update a "CAN Pack" block with a new DBC file, the block ports do not refresh automatically. Currently, you have to open the block, select the new message, and enable “Output as bus” manually to see the updated ports.
You can automate this process programmatically using set_param. The key parameters for the CAN Pack block required here are:
- CANdbFile : to specify the DBC file path
- MsgName : choose the message from the DBC (optional)
- BusOutput : enable the bus output (equivalent to checking “Output as bus”)
I tried to recreate this on my side using a dummy Simulink model with 2 similar databases ('dummy_can.dbc' and 'dummy_can_copy.dbc'). And to update the parameters programmatically I scripted a method which would change the database and keep the 'Output port as bus'.
You can refer to this example method definition of "updateCanBlock":
function updateCanBlock(modelName, dbcFile)
blk = find_system(modelName, 'MaskType', 'CAN Pack');
error('No CAN Pack block found in model %s', modelName);
set_param(blk{i}, 'CANdbFile', dbcFile);
set_param(blk{i}, 'BusOutput', 'on');
fprintf('Updated CAN Pack block: %s\n', blk{i});
set_param(modelName, 'SimulationCommand', 'update');
In command line, call method with by supplying new database like below:
updateCanBlock('dummyCANModel', fullfile(pwd, 'dummy_can_copy.dbc'));
You can compare the below outputs:
1.Before changing the database :
2.After calling the method :
If you want to know try for more parameters that the block seupport, try this command :
>> blk = find_system('dummyCANModel', 'Name', 'CAN Pack');
>> p = get_param(blk, 'DialogParameters');
For more clarification, refer to following links:
- 'set_param' : https://www.mathworks.com/help/simulink/slref/set_param.html
- 'CAN Pack' : https://www.mathworks.com/help/ecoder/ref/canpack.html
Hope this helps you!