MATLAB Answers

Executing callbacks of custom simulink blocks in a subsystem reference

15 views (last 30 days)
Alexander Lampe
Alexander Lampe on 17 Apr 2020
Commented: Tim Hattrell on 22 Feb 2021
I have a custom Simulink block with a mask that executes callback on mask paramater changes and changes the underlying subsystem content (e.g. rename a signal)
When I want to use this block in a subsystem reference and I get the error:
  • Error in 'XXX: Failed to evaluate mask initialization commands.
  • Caused by:
Block 'XXX' is inside a Subsystem Reference block 'XXX'. Incorrect to modify contents of a Subsystem Reference block using callback code.
How can I fix it?
Thanks in advance!
  4 Comments
Fabian Müller
Fabian Müller on 7 Feb 2021
Hi! I have also the same problem. I want to promote units from input / output ports to the mask. The initialization code is:
set_param([gcb '/In1'], 'Unit', S_unit);
set_param([gcb '/Out1'], 'Unit', q_unit);
It is not possible to initialize the subsystem reference. With the same error message:
Block 'XXX' is inside a Subsystem Reference block 'XXX'. Incorrect to modify contents of a Subsystem Reference block using callback code.
However, it works when defining the subsystem directly in a library without subsystem reference.
Is this intended? It would be nice if that also works with a subsystem reference.

Sign in to comment.

Answers (1)

Mark McBroom
Mark McBroom on 20 Feb 2021
I believe you need to put a mask on the subsystem reference and use this mask to pass values for each instance down into your custom simulink block mask that exists inside the subsystem reference.
This link contains instructions for creating a mask on the subsystem reference.
  1 Comment
Tim Hattrell
Tim Hattrell on 22 Feb 2021
I came to the conclusion, after posting my original comment above, that it should not be possible to change the contents of a Subsystem Reference block using mask initialisation code. If the point of a Subsystem Reference is that each block is an identical copy of the saved subsystem file, using the mask initialisation to reconfigure the internals of the Subsystem Reference blocks will cause some of the Subsystem Reference blocks to be different to the others. Once this is done, which one is the true copy? After having that though, I gave up.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!