How to make RTW options persist.

조회 수: 6 (최근 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 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