MATLAB Answers

Why are the parameters of the CAN Pack or CAN Unpack block not transmitted correctly when I modify them with set_param?

3 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Mar 2020
Edited: MathWorks Support Team on 26 Mar 2020
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

  1 Comment

Stefanie Schwarz
Stefanie Schwarz on 2 Apr 2019
Tip: Using the attached small wrapper around configure_CANMsgBlock_CANdb, you can directly re-load a CAN database file into the block. Simply add refreshCANdb(gcb) to the InitFcn callback of the CAN Pack / Unpack blocks. Then, the DBC file will be automatically reloaded at the beginning of the code generation process.

Sign in to comment.

More Answers (0)

Sign in to answer this question.


No tags entered yet.