- open_system: https://www.mathworks.com/help/simulink/slref/open_system.html
- load_system: https://www.mathworks.com/help/simulink/slref/load_system.html
- close_system: https://www.mathworks.com/help/simulink/slref/close_system.html
How to switch between 'Connected IO' mode and 'Run in Kernel' mode programmatically when using Simulink Desktop Real-Time (SLDRT) ?
11 次查看(过去 30 天)
显示 更早的评论
Hi all,
Release: MATLAB 2022b Update 8
Using Simulink Desktop Real-Time, we can select two execution modes : 'Run in Kernel', or 'Connected IO' :
Switching between modes is easy enough through the Simulink menu shown above. But I would like to know if it is possible to change this option programmatically, from the MATLAB command window, or from a script?
I came upon these commands :
set_param(gcs, 'SimulationMode', 'external');
set_param(gcs, 'SimulationMode', 'normal');
However, these commands do not update the Simulink button shown above. They only take effect when running the Simulink model from the command line, using :
set_param(gcs, 'SimulationCommand', 'start');
set_param(gcs, 'SimulationCommand', 'stop');
If I run the model through the "Run in Real Time" button in the Simulink top menu, the simulation mode still corresponds to the old button state, and not to the command that was entered.
It feels like I should force the refresh of the Simulink top ribbon menu after entering the set_param(gcs, 'SimulationMode', 'external') command, so that it actually registers in the Simulink UI (top ribbon), but how to do this?
0 个评论
采纳的回答
Aravind
2024-10-23,11:21
It seems like you want to change Simulink's simulation mode programmatically and have these changes reflected in the Simulink UI.
Typically, programmatic control and UI-based control in Simulink are separate workflows and do not easily synchronize with each other. As a result, changes made using the "set_param" function may not immediately appear in the Simulink UI toolstrip.
One workaround is to close the model, load it into memory, make your changes via the command line, and then reopen the model. Here is an example of how you can do it:
close_system(mdl);
load_system(mdl);
set_param(mdl, 'SimulationMode', 'external'); % or 'normal'
open_system(mdl);
Here, “mdl” is the name of the Simulink model file that is currently under consideration. This sequence of functions ensures that changes are applied and reflected when you reopen the model in the UI.
For more information on these functions, you can refer to the following official documentation pages:
I hope this helps!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Real-Time Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!