How to make RTW options persist.

4 次查看(过去 30 天)
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.

采纳的回答

Sergey Ponomarev
Sergey Ponomarev 2017-5-24
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.

更多回答(1 个)

Varun Gunda
Varun Gunda 2017-4-6
编辑:Varun Gunda 2017-4-6
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 个评论
Sergey Ponomarev
Sergey Ponomarev 2017-4-10
编辑:Sergey Ponomarev 2017-4-10
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by