Hi Anna,
I understand that you are trying to control the simulation of your Simulink model with 'NI myDAQ' blocks through a MATLAB App Designer interface and are facing issues with pausing and stopping the simulation correctly.
The issue with pausing and stopping the simulation is caused by the real-time communication between the 'NI myDAQ' blocks and Simulink. These blocks operate continuously during simulation, and when a 'Pause' command is issued, Simulink attempts to halt, but the analog I/O remains actively communicating with NI myDAQ' at its sample rate. This is why the simulation appears unresponsive when paused.
Similarly, the error during the Stop command occurs because the 'getSimulationOutput' function is called while the simulation status is still Running. 'NI myDAQ' operations need to safely terminate before the status is updated to 'Inactive'.
To address this issue, you can consider adopting the following workarounds in your application:
- Switching to External Mode in Simulink: In External Mode, the NI myDAQ communication is more flexible and allows proper pausing and stopping through Simulink's interface.
- Event Listener for Pause and Stop: You can add the following event listeners in your MATLAB App to appropriately pause/stop 'NI myDAQ' simulation, as shown below:
function pauseSimulation()
set_param('model_name', 'SimulationCommand', 'pause');
while ~strcmp(get_param('model_name', 'SimulationStatus'), 'paused')
function stopSimulation()
set_param('model_name', 'SimulationCommand', 'stop');
while ~strcmp(get_param('model_name', 'SimulationStatus'), 'stopped')
You can refer to the following documentation link to know more callbacks and usage of 'set_param' functions:
Hope this helps!