How do I get the handle of an app in a Simulink callback without opening a new app window?
3 次查看(过去 30 天)
显示 更早的评论
I'm calling a Simulink model (let's say Model.slx) from an app (let's say GUI.mlapp) using:
load_system('Model.slx')
set_param(gcs,'SimulationCommand','start')
Within the StopFcn callback of Model.slx, I want to call the function PostSimActions(), which is defined in GUI.mlapp. Essentially, I want Simulink to notify the app when the simulation is complete so that I can re-enable the "Run Simulation" button and process the simulation data in the app. I realize that I could use a while loop and the pause function after starting my model to simply wait until the SimulationStatus is no longer 'running', but I would prefer that the app not be hung up in a loop while the simulation runs (in case the user wants to change other settings or turn other knobs in the app). Within the Simulink callbacks, I have tried:
h_app = GUI;
PostSimActions(h_app);
However, grabbing the handle of the app this way opens a new app window, which I do not want. If I insert another line in the model callback...
h_app.UIFigure.Visible = "off";
...then any actions that I perform in PostSimActions(h_app) do not affect the original app window (since the function is tied to the new window...I think?) So, for example, if I try to re-enable the "Run Simulation" button that was used to run Model.slx, only the button on the invisible window is enabled, not the original window.
Is there a way I can get the handle of an app in a Simulink callback that is linked to my original app window (and doesn't open another window)?
2 个评论
Thomas Husson
2020-2-18
You can get the handle of your app by first getting the figure object:
fig = findall(0,"Name", "name_of_your_app");
where "name_of_your_app" is the name of the opened window. And then to obtain the handle:
handle = fig.RunningAppInstance;
From that handle you should be able to reach the function you defined in your app.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model, Block, and Port Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!