How to handle errors within a mask callback?

2 ビュー (過去 30 日間)
Sylvain R.
Sylvain R. 2018 年 3 月 6 日
回答済み: Sanman 2022 年 1 月 27 日
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) ?
%paramName might reference a WS variable or be a numeric-string.
var = evalin(paramName, 'base')
test = (var >= 0);
catch ME
I can use both
sldiagviewer.reportError(sprintf('... block %s ...', getfullname(containerHandle)));
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?

回答 (1 件)

Sanman 2022 年 1 月 27 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by