How to make RTW options persist.

5 ビュー (過去 30 日間)
Sergey Ponomarev
Sergey Ponomarev 2017 年 3 月 28 日
回答済み: Sergey Ponomarev 2017 年 5 月 24 日
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 Center および File ExchangeSimulink Coder についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by