How to handle errors within a mask callback?
5 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(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.
https://www.mathworks.com/help/simulink/ug/mask-parameter-constraints.html
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!