How to handle errors within a mask callback?

11 views (last 30 days)
Sylvain R.
Sylvain R. on 6 Mar 2018
Answered: Sanman on 27 Jan 2022
Hello,
I want to validate the mask input (edit fields) from the user using the parameter's callback.
How shall I report those invalid values (missing WS parameter, negative number when positive only, etc) ?
try
%paramName might reference a WS variable or be a numeric-string.
var = evalin(paramName, 'base')
test = (var >= 0);
catch ME
...
end
I can use both
sldiagviewer.reportError(sprintf('... block %s ...', getfullname(containerHandle)));
or
error(... block %s ...' , getfullname(containerHandle));
This is troublesome when having a library block allowed to modify itself as the init_callback is executed twice, hence doubling the error message in the 'Diagnostic Viewer'.
Is there another way to gently output an error message within Simulink?
As a side question: is there a way to prevent the repeated execution of the initialization callback?

Answers (1)

Sanman
Sanman on 27 Jan 2022
Hi Sylvain,
If I understand correctly, you're looking to validate the mask parameter values. These could be done without introducing a parameter callback as well by using "Mask Parameter Constraints". If you do not necessarily want to use the parameter callback for validation, you can check out the following link to the doc page.
You can also refer to this documentation page for further reference.
https://www.mathworks.com/help/simulink/ug/mask-parameter-constraints.html

Community Treasure Hunt

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

Start Hunting!