How do I run my External Mode simulation from the command line or a MATLAB script?

조회 수: 34 (최근 30일)
I would like to run my External Mode simulation from the command line or a MATLAB script. My aim is to monitor and parameterize an application running on targets such as Simulink Desktop Real-Time, Simulink Real-Time, or other hardware that has External Mode support enabled, without the need to press the "Run on Target" or "Monitor & Tune" button in Simulink Toolstrip.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 5월 4일
편집: MathWorks Support Team 2023년 4월 14일

Run External Mode simulation from the MATLAB Command Window:

To run these commands, you must have a Simulink model open and a target application running.
1. Set the model simulation mode to external mode.
>> set_param(gcs,'SimulationMode','external');
2. Connect Simulink to the target application.
>> set_param(gcs,'SimulationCommand','connect')
This command is equivalent to pressing the "Connect to target" button.
3. Run generated model code.
>> set_param(gcs,'SimulationCommand','start');
4. To tune a parameter, change its workspace variable value through a line command. For example, if a block parameter value is specified as a Simulink.Parameter object, assign the new value to the Value property.
>> myParamObj.Value = 5.23;
To download the new value to the target application, update the model.
>> set_param(gcs,'SimulationCommand','update');
5. Stop the target application and disconnect Simulink from the target environment.
>> set_param(gcs,'SimulationCommand','stop');
6. To disconnect Simulink from the target application without stopping the execution of generated code, use this command:
>> set_param(gcs,'SimulationCommand','disconnect');
.

Run External Mode simulation from a MATLAB script:

The set_param commands that use the 'SimulationCommand' argument are asynchronous. If you run the commands successively from a script, each command starts without waiting for the previous command to complete. To check that each command is complete, in the script, use the get_param command with the 'SimulationStatus' argument. 
For example, for steps 1 to 3, specify these commands in the script:
set_param(gcs,'SimulationMode','external');
set_param(gcs,'SimulationCommand','connect');
isExternalSimulationActive = false;
while ~isExternalSimulationActive
simStatus = get_param(gcs, 'SimulationStatus');
isExternalSimulationActive = strcmp(simStatus, 'external');
end
set_param(gcs,'SimulationCommand','start');
For more information, see the Simulink and Simulink Coder documentation:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by