How to know the contexte (simulation, code generation ...) when running a mask init function?
显示 更早的评论
I got trouble in a bloc with a mask I have created in a personal librairi.
In the mask,I change some block type according to the parameter (set by user in the mask dialog panel).
It alow to change a block input to constant (and resip.) in order to remove inputs when unused.
The code I used is given here:
ParamCheckbox = get_param(gcb,'Pid_En');
BlockName = 'Enable';
MyBlocType = get_param([gcb '/' BlockName],'BlockType');
pos = get_param([gcb '/' BlockName],'Position');
orient = get_param([gcb '/' BlockName],'Orientation');
if(strcmp(ParamCheckbox,'on'))
if(strcmp(MyBlocType,'Constant'))
delete_block([gcb '/' BlockName]);
add_block('built-in/Inport',[gcb '/' BlockName],'Position',pos,'Orientation',orient);
set_param([gcb '/' BlockName],'OutDataTypeStr','boolean');
end
else
if(strcmp(MyBlocType,'Inport'))
delete_block([gcb '/' BlockName]);
add_block('built-in/Constant',[gcb '/' BlockName],'Position',pos,'Orientation',orient);
set_param([gcb '/' BlockName],'OutDataTypeStr','boolean');
set_param([gcb '/' BlockName],'Value','true');
end
end
The problem is that during code generation, the init function is called.
It reset the corresponding port: the input port is removed and set again according to the user selection in dialog panel.
But the line connected to the block are not well "reconnected" to the block and the code generation produce a code where the connection is not done.
And that is not what I expect.
A solution I see is to "read" the execution context in the init function (simulation, code generation ...) and avoid to execute the code during code generation.
Any other solution is of course welcome.
What is strange, is that I allready use the same pattern in other library bloc without trouble.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!