Model Callbacks in Referenced Models
4 views (last 30 days)
Show older comments
I see inconsistent behavior in the execution of model callback functions in model references. Should the model callback functions of referenced models run whenever the same model callback function runs in the top model? If so, in what order? For example, suppose the top model contains two references to the same model and that model contains two references to different models. Which model callbacks run, how many times, and when? How are model callbacks in referenced models handled during the code generation process?
0 Comments
Answers (1)
Kaustubha Govind
on 22 Oct 2012
My guess is that the callbacks are executed in the order that each referenced model is compiled - I would expect this to be the same as the block sorted order, but I'm not absolutely certain. Here is a description of when each model callback is executed. A good exercise might be to dump debugging statements in each callback such as:
fprintf('Executing InitFcn callback for %s', gcs)
2 Comments
Kaustubha Govind
on 23 Oct 2012
Paul: Thanks for posting the results of your experiment.
1) makes sense, because no code is generated for the referenced model, so it is executed normally. 2) makes sense too since InitFcn is executed during model compilation, which happens during code-generation. Then, the generated code is executed, and not the model itself, so the StopFcn will not run (since callbacks are not present in generated code). 3) Could this be because both references are to the same model? Simulink only needs to generate code once.
I agree that this should be clearly documented - could you please submit an enhancement request to MathWorks Tech Support, so that the appropriate team is notified.
I don't recall explicitly looking for R2012a documentation - it may have been what showed up in my web search.
See Also
Categories
Find more on Model, Block, and Port Callbacks in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!