Stop Simulink simulation launched programatically on a machine without display

2 vues (au cours des 30 derniers jours)
Felix Arnoux
Felix Arnoux le 13 Avr 2021
Modifié(e) : Mario Malic le 13 Avr 2021
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 commentaire
Mario Malic
Mario Malic le 13 Avr 2021
Modifié(e) : Mario Malic le 13 Avr 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?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by