MATLAB: Are the parameters of the CAN Pack or CAN Unpack block not transmitted correctly when I modify them with set_param

vehicle network toolbox

I have trouble changing the parameter of a CAN Pack or CAN Unpack block with set_param.
My goal is to implement a GUI that interacts with the Simulink model.
When I modify the parameters of the block from MATLAB, then it seems that the parameter are set correctly (just looking at the block).
However, the the CAN message is not recognized by a control unit connected to the CAN bus. I have to open the blocks mask manually and click on OK so that the CAN message can be transmitted correctly.

Best Answer

Using MATLAB R2019a or earlier, it is not possible to use 'set_param' to programmatically control certain CAN Pack/Unpack block functionalities (such as CAN database file, or manually configured CAN message/signals). This ability has been added in R2019b.
The following workaround has been tested in MATLAB R2015b:
Find attached "configure_CANMsgBlock_manual.m" (and required privatecanslsignalvalidation_prog.m") and "configure_CANMsgBlock_CANdb.m" as examples of programmatic configuration of a CAN Unpack or CAN Pack block in "manually specified signals" or "CANdb specified signals". Usage example code is also attached.
These functions can be used with the following 4 block configurations:
  • CAN Pack with "CANdb specified signals" mode
  • CAN Pack with "manually specified signals" mode
  • CAN Unpack with "CANdb specified signals" mode
  • CAN Unpack with "manually specified signals" mode
Please refer to 'help' for these workaround example functions, as they have usage examples, additional notes, and disclaimers.
This workaround can be used as an alternative to using the set_param directly. For example: * with a "manually specified signals" mode create the msgInfo and signalsInfo structures from scratch (as in "example_usage_manual.m") and use "configure_CANMsgBlock_manual.m" instead of set_param * with "CANdb specified signals" mode use "configure_CANMsgBlock_CANdb.m" instead of set_param (as in "example_usage_CANdb.m").
Installation instructions for “privatecanslsignalvalidation_prog.m”:
  1. Copy "privatecanslsignalvalidation_prog.m" into [matlabroot '\toolbox\shared\can\canmasks\private'
  2. Execute: >> rehash toolbox