MATLAB Answers

How to refresh System Target File (.tlc) SelectCallback?

7 views (last 30 days)
I have a custom target file that is based on ert.tlc. I am editing the target-specific code generation options for a model's Configuration Parameters dialog box using a custom SelectCallback script (e.g., custom_ert_callback.m). In my custom_ert.tlc I have:
rtwgensettings.SelectCallback = 'custom_ert_callback(hDlg,hSrc)';
Using this SelectCallback, I am changing some of the configuration parameters to be specific values for my custom target, or disabling some altogether so the user can't edit it themselves. For example:
slConfigUISetVal(hDlg,hSrc,'ArrayBoundsChecking', 'error'); % Set parameter
slConfigUISetEnabled(hDlg,hSrc,'ArrayBoundsChecking', false); % Disable users from changing it
My question is, after changes are made to the callback, how do I refesh the target to reflect the changes in a model's configuration parameters? For example, I have a closed model that is already using my custom target (i.e. the SystemTargetFile parameter is already set to custom_ert.tlc). I then change the custom_ert_callback.m to apply the above changes, that is, make the ArrayBoundsChecking parameter disabled and set it to 'error'. When I open the model, and view the Configuration Parameters, this field is still enabled and the value is still set to 'none'. Is there a way to ensure the changes are registered? I essentially want something akin to the sl_refresh_customizations command, but for tlc callbacks.
The only way I can acheive a 'refresh' is to set the target file back to ert.tlc, and then back again to my custom tlc:
set_param(gcs, 'SystemTargetFile', 'ert.tlc');
set_param(gcs, 'SystemTargetFile', 'custom_ert.tlc');
Is there a better way?

  0 Comments

Sign in to comment.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 22 Apr 2020
Edited: Fangjun Jiang on 22 Apr 2020
Reloading the model should should make it effective
From the document
rtwgensettings.SelectCallback: This structure field specifies a SelectCallback function. You must setrtwgensettings.Version = '1'; or your callback will be ignored. SelectCallback is associated with the target rather than with any of its individual options. The SelectCallback function is triggered when you:
  • Load the model.
  • Update any configuration settings in the Configuration Parameters dialog box.
  • Build the model.
The SelectCallback function is useful for setting up (or disabling) configuration parameters specific to the target.
Or consider rtwgensettings.PostApplyCallback
rtwgensettings.PostApplyCallback: this property specifies a PostApplyCallback function. The PostApplyCallback function is triggered when the user clicks the Apply or OK button after editing options in the Configuration Parameters dialog box. ThePostApplyCallback function is called after the changes have been applied to the configuration set.

  2 Comments

Monika Jaskolka
Monika Jaskolka on 15 May 2020
Unfortunately if a re-load the model, or even restart Matlab, the configuration parameters of my model don't update to the current SelectCallback configurations. The rtwgensettings.PostApplyCallback function is called after I change the model's configuration set, but in the case where I am enabling a parameter, it remains disabled, so I cannot actually perform the change. Trying to change the parameter with set_param gives me an error message that "Changing property X is not allowed".
Is there a function available that will re-apply the configuration set in SelectCallback to a model?
Fangjun Jiang
Fangjun Jiang on 15 May 2020
You want to modify the .tlc file on the fly to enable/disable certerain parameters, and then you want to run some set_param() statements during the callback. I wonder by that time, the new .tlc file has not be applied yet. The .tlc file will be applied after the callabacks are done.
Or, due to the fact that the .tlc file is the same (you modified the content of the .tlc file but it is unknown to the Simulink model), the new content of the .tlc file won't be re-applied. That is why it will take effect after you switch the .tlc file back and forth.
My remaining suggestion would be to set the default value for those parameters directly in the .tlc file when you enable/disable those parameters.
Other than that, it might be better if you contact the Mathworks tech support. Give you example files and state what you need, I bet they might give you a solution.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by