Search code examples
simulinks-function

Conditionally enabled rtwoptions in a custom System Target File (Simulink Coder)


I'm creating a custom System Target File (STF) and adding some RTW options that need to be configured. Some options are dependent on others, and may or may not make sense depending on how they are configured. In these cases I would like to conditionally disable them (grey out).

So far I have something like this (Using MATLAB R2014a)

...

rtwoptions(oIdx).prompt         = 'Enable Foo';
rtwoptions(oIdx).type           = 'Checkbox';
rtwoptions(oIdx).default        = 'off';
rtwoptions(oIdx).enable         = 'on';  
rtwoptions(oIdx).tlcvariable    = 'Foo';
rtwoptions(oIdx).makevariable   = 'FOO';

oIdx = oIdx + 1;

rtwoptions(oIdx).prompt         = 'Bar only makes sense if Foo is enabled';
rtwoptions(oIdx).type           = 'Checkbox';
rtwoptions(oIdx).default        = 'off';
if foo <--- WHAT DO I PUT HERE?
    rtwoptions(oIdx).enable         = 'on';
else
    rtwoptions(oIdx).enable         = 'off';
end

According to the documentation there is such a thing as a conditional rtwoption by calling a MATLAB function, but I would like to make it dependent on another options.

This must be possible, as it is implemented in Code Generation --> Report tab ("Open report" is only enabled if you enable "Create Report").

What is the syntax of this condition? Can I use the "tlcvariable"?


Solution

  • This is possible using the rtwoptions(i).callback field and a Matlab function that uses slConfigUIGetVal to get the value of the controlling option (Foo in the example) and slConfigUISetEnabled to enable/disable the dependant option (Bar in the example).