How to make RTW options persist.

6 vues (au cours des 30 derniers jours)
Sergey Ponomarev
Sergey Ponomarev le 28 Mar 2017
When compiling a Simulink model with RTW (r2013a), I need to check "Code Generation > Interface > Code Interface > Generate reusable code" every time I open the model. I would like to automate my building and so I either need to have this option saved in the model, or drive it from the command-line before building.
This is the only parameter that doesn't seem to be saved in the model. Others like "System target file" save just fine and I don't need to reset them. My guess is that this is a bug in my version of Matlab (r2013a).
So my next question is: How can I over-drive this parameter from the command line? My current method of running this model is:
matlab ^
-nojvm ^
-nodisplay ^
-nodesktop ^
-r "addpath('%modelpath%'); addpath('%tlcpath%'); addpath(genpath('%scriptpath%')); rtwbuild('%modelname%'); quit;" ^
-logfile %modelname%.log
It's possible that the long -r parameter can be turned into a .m file. I think I can set this with:
cs = Simulink.ConfigSet;
cs.set_param('MultiInstanceERTCode', 'on');
If I put it in my build-script it doesn't seem to do anything (probably because my model isn't open yet). If I save it in my "Model Properties > Callbacks > PostLoadFcn" it also doesn't seem to do anything.
Another thing I've tried is:
hCs = getActiveConfigSet('b737ng_yd_solenoid')
hCs.saveAs( 'ConfiguredDataScript', '-format', 'MATLAB script', '-varname', 'config_set')
I've done this before and after swapping the "Generate reusable code" and I do see the difference in the resulting script. However running the script before opening the simulink, or running the script with the simulink open will not restore this specific flag.
I am going to just try installing a new version of MATLAB to see if this is fixed in a later release.

Réponse acceptée

Sergey Ponomarev
Sergey Ponomarev le 24 Mai 2017
I solved this by simply updating the models to MATLAB 2015a, setting the "Reusable Code" flag, saving, and then compiling by simply calling "matlab -r rtwbuild(model)". No need to deal with options via command-line in MATLAB 2015a.

Plus de réponses (1)

Varun Gunda
Varun Gunda le 6 Avr 2017
Modifié(e) : Varun Gunda le 6 Avr 2017
You can use Simulink® Preferences to specify Simulink editing environment options and default behaviors.
In the MATLAB® Command Window, enter slprivate('showprefs')
Here change the preferences in Configuration Defaults > Code Generation > Interface.
This will change the default options.
References:
  1 commentaire
Sergey Ponomarev
Sergey Ponomarev le 10 Avr 2017
Modifié(e) : Sergey Ponomarev le 10 Avr 2017
Thanks for this answer. When I use slprivate('showprefs') to enable this feature, new models I create have "Generate Re-usable code" pre-selected. That's great! However, if I open an existing SLX, the option is not selected.
I've tried selecting, saving, closing, and re-opening again and the option refuses to persist.
In addition, I have lots of users opening the models. It would be best if the solution isn't user-environment-specific and can be tied to the model which is controlled in a version control system.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink Coder dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by