Why doesn't Simulink call the transformation function for masked inport and outport blocks?

3 次查看(过去 30 天)
I have some masked inport and outport blocks in a library and have done some structural changes to the masks of some of them that needs to be handled in a transformation function when an old model using them are loaded. However, the transformation function doesn't seem to be called for inport and outport blocks. I have tested with other blocks that I have masked, such as subsystems, bus creators, goto blocks and whatnot and they all triggers the transformation function. But not inports nor outports.
Is this known or am I doing something wrong? And, if known, is there a workaround?
Minimalistic code to show what I mean:
First define a transformation function:
function outdata = xfunc(indata)
% Very simple transformation function.
% Just prints the path of the library block.
% Printing to stderr since stdout is disabled during load.
fprintf(2, '%s\n', indata.ForwardingTableEntry.('__slOldName__'));
end
Then execute the following:
% Create new library
new_system('mylib', 'Library');
% Add an inport and mask it
add_block('built-in/Inport', 'mylib/Inport', 'Position', [15 28 45 42]);
Simulink.Mask.create('mylib/Inport');
% Add a subsystem and mask it
add_block('built-in/Subsystem', 'mylib/Subsystem', 'Position', [80 15 130 55]);
Simulink.Mask.create('mylib/Subsystem');
% Save library
save_system('mylib');
% Create a new model with blocks from mylib and save it
new_system('mymdl');
add_block('mylib/Inport', 'mymdl/Inport', 'Position', [15 28 45 42]);
add_block('mylib/Subsystem', 'mymdl/Subsystem', 'Position', [80 15 130 55]);
save_system('mymdl');
close_system('mymdl');
% Increment the ModelVersion of the library
set_param('mylib', 'Dirty', 'on');
save_system('mylib');
% Set a forwarding table for both blocks
modelVersion = get_param('mylib', 'ModelVersion');
fwt = {
{'mylib/Subsystem', 'mylib/Subsystem', '0.0', modelVersion, 'xfunc'}
{'mylib/Inport' , 'mylib/Inport' , '0.0', modelVersion, 'xfunc'}
};
set_param('mylib', 'ForwardingTable', fwt);
% Open the model.
open_system('mymdl');
Expected output:
mylib/Inport
mylib/Subsystem
Instead, the code yields just:
mylib/Subsystem

回答(1 个)

Anushka
Anushka 2025-6-19
The ‘Inport’ and ‘Outport’ blocks in Simulink do not trigger the transformation function defined in the ‘ForwardingTable’ when an old model is loaded. This behavior is due to the special treatment of these blocks as built-in interface elements which leads Simulink to optimize or bypass transformation logic for them during model upgrades.
To work around this limitation, you can encapsulate the ‘Inport’ or ‘Outport’ block within a Subsystem. By applying your mask and transformation logic to the Subsystem instead of directly to the ‘Inport’ or ‘Outport’, you ensure that the transformation function is invoked correctly when models that use these blocks are loaded.
Here’s a suggested structure for your library:
mylib/
└── InportWrapper (Subsystem)
└── Inport (inside)
This way, when the model is loaded, the transformation function will be triggered for the Subsystem which allows you to handle any necessary updates or change.
You can refer to the following documentation to know more about masking fundamentals in Simulink and how to effectively use masks to customize block interfaces and parameters: https://www.mathworks.com/help/simulink/ug/block-masks.html
You can also refer to the following documentation of Subsystem: https://www.mathworks.com/help/simulink/slref/subsystem.html
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Subsystems 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by