How to get port names for built-in blocks?

16 ビュー (過去 30 日間)
Danijel Domazet
Danijel Domazet 2020 年 10 月 7 日
コメント済み: Danijel Domazet 2020 年 10 月 8 日
This is how I find port names in my Simulink model:
function [portNames] = findOutputPortNames(obj)
% Lists output port names for the target module.
simBlockH = get_param(target_module, 'Handle');
portH = find_system(simBlockH, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Outport');
portNames = cellstr(get_param(portH, 'Name'));
end
This works fine for my subblocks.
However, it does not work for blocks that are builtin, for example "Biquad Filter".
How do I get output (or input) port names for built-in blocks?
The above find_system() call returns empty result.
When I remove the BlockType parameter:
portH = find_system(simBlockH, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1);
portNames = cellstr(get_param(portH, 'Name'));
I get the following output:
portNames =
5×1 cell array
{'PH20hz'}
{'Signal_in'}
{0×0 char}
{0×0 char}
{'Signal_out'}
How do I find out which are input ports, and which are output ports?
Or, instead of 'BlockType', 'Outport', should I use somethig else for 'BlockType'?
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2020 年 10 月 7 日
That is not port name. That is under masks Inport/Outport block name. Port names, if they exist, are different. What name you really want for built-in blocks?
Danijel Domazet
Danijel Domazet 2020 年 10 月 8 日
Hi Fangjun,
I need output port/wire/link name.
After some experimenting, I found this works:
open_system(test_model, 'loadonly');
...
bt = get_param(target_module, 'BlockType');
if bt == "S-Function"
portNames = get_param(target_module, 'OutputSignalNames');
end
...
close_system(test_model, 0)

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgrammatic Model Editing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by