How can I stop a simulation in Simulink using a C MEX S-function that enters into an infinite loop ?
Mostrar comentarios más antiguos
This problem is related to a Simulink model using a C MEX S-function inside. This model is intended to simulate a large range of inlet conditions (or simulation cases) and, for some of them, the C MEX S-function bugs and keep doing infinite calculations. My intention is to avoid these single "bug" cases and switching to the next simulation case. I tried several solutions:
1) I created a subsystem from the C MEX S-function and enabled it if a "CPU time" function was under a time limit. If not, simulation stops (Stop block). The goal is to limit to a max simulation time (to 6 seconds in this example) and switch to the next simulation case.

2) Almost the same solution above, but replacing the "Stop Simulation" block by a Matlab function with the following stop code:
function fcn(I_O) %#codegen
coder.extrinsic('bdroot') coder.extrinsic('set_param')
if I_O==1 set_param(bdroot, 'SimulationCommand', 'stop'); end

3) Almost the same solution above, but replacing the code in the Matlab function with the following stop code (just to check if such a solution would lead to a Matlab exit):
function fcn(I_O) %#codegen
coder.extrinsic('exit')
if I_O==1 exit; end
Any of the above solution was successful, it seems like the C MEX S-function run avoid the whole Simulink model to do any action when it enters into this infinite calculation loop.
Thank you for your help, any information, idea or clue will be useful.
Respuestas (0)
Categorías
Más información sobre Simulink Coder en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!