How do I get the port names of a block based on their port handles?

134 ビュー (過去 30 日間)
Kulan Sinclair
Kulan Sinclair 2018 年 7 月 11 日
I'm trying to find A,B,C,a,b or c from the port handle they are set from inside the mask but if I try something like
get_param(porthandle, 'name')
I get an empty string, but name is a valid object parameter.

回答 (2 件)

Christopher Wallace
Christopher Wallace 2018 年 7 月 19 日
Select the subsystem and then use the following code:
find_system(gcb, 'SearchDepth', 1, 'BlockType', 'Inport')
find_system(gcb, 'SearchDepth', 1, 'BlockType', 'Outport')
  3 件のコメント
ciming zhu
ciming zhu 2023 年 4 月 27 日
I get the same problem as you...
Rafael Souza Baquero
Rafael Souza Baquero 2023 年 8 月 3 日
Matthew Calder: the answer is 'PMIOPort'.
When you don't know the exact string you need to find the desired block, I suggest you create a blank Simulink model, place the block, click on it and then run the command "get_param(gcb,'BlockType')".

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


Simon Ellwanger
Simon Ellwanger 2021 年 2 月 26 日
編集済み: Simon Ellwanger 2021 年 2 月 26 日
try this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% please load and select/mark the block before execution !!!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%get block handles and port handles
rootmodel= gcb;
porthandles=get(gcbh,'PortHandles')
% get OUTPORT PortNames:
simBlockH = get_param(gcbh, 'Handle')
handles = find_system(simBlockH, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Outport');
portInfo = [get_param(handles, 'Name'), get_param(handles, 'Port')]
for i = 1: size(porthandles.Outport,2)
%draw line at each port
pos = get(porthandles.Outport(i), 'Position');
Linepos = [pos(1)+200 pos(2)-5 pos(1)+200+10 pos(2)+5];
temp_block = add_block('simulink/Commonly Used Blocks/Terminator',[gcs '/Term_' int2str(i)],'Position', Linepos);
h1 = get_param(temp_block,'PortHandles');
add_line(gcs,porthandles.Outport(i),h1.Inport);
% name line
linehandle = get(porthandles.Outport(i), 'Line');
set(linehandle, 'Name', portInfo{i});
end

カテゴリ

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

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by