Stop Simulink simulation launched programatically on a machine without display

1 visualización (últimos 30 días)
Hello,
I launch Simulink simulations programatically from another program, on HPC machines (without display).
To do that, I use the Matlab Engine via the C++ API and after some setup I use the sim() command in a C++ separate thread to run the simulation itself. This thread will wait for the end of the simulation, retreive messages and catch exceptions if any.
When the user clicks on a button in my program, I want to stop the simulation.
However, I have no "clean" way to stop the Simulink run. The documentation states that when using sim() you have to use Ctrl+C to stop a simulation.
Moreover, I can't use the set_param() command to run the simulation, it is forbidden to use it on a machine without display (why ?).
Therefore I came out with some workarounds:
  • attach a listener on a Simulink block to check periodically if a stop flag has been defined in the Matlab workspace (can we interact with the workspace from another C++ thread ?)
  • send a SIGTERM signal to Matlab (what is Matlab state after that ?)
  • add a S-function to the simulink model (very intrusive !)
  • use the C API instead of the C++ one with set_param() to run the simulation (seems to work, even without display ?)
Well, as you can see, I need some help to find the right solution...
Any advice is most welcome !
  1 comentario
Mario Malic
Mario Malic el 13 de Abr. de 2021
Editada: Mario Malic el 13 de Abr. de 2021
Just a note, I am not super familiar with the Simulink.
When you start your sim with separate thread is the MATLAB instance busy, or you are able to interact with it? It's even questionable whether your Simulink can see MATLAB when ran on separate thread?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Simulink Environment Customization en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by