Get the port handle for the reference mode

Hello All
Is there anyway to get the port handler for the reference model and then for Inport/Outport read the resolved signal ?

Answers (2)

I would think that you porbably need to follow the Model block, open the referenced model and then get the input and output port handels and then the resolved signal object/names.
The info is saved in the referenced model. The referenced model is not loaded when barely open the top-level model.
Thank you Fangjun for your answer
I tried the below code for get all Inputs( Name and port number)
simBlockH = get_param(BclkName, 'Handle');
handles = find_system(simBlockH, 'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Inport');
PortNameArray = get_param(handles, 'Name');
PortNumberArray = get_param(handles, 'Port');
And it's worked correctly.But when i tried to get the port handle for each inport i get an error, could you plese guide me how can i get the port handle for each port to read the Resolved signal name and if this port is connected to Goto/From block
I tried this code for read the port handle ( does not work for Model reference, but work normally for Subsyste)
ph=get_param(BclkName,'PortHandles');

5 Comments

Once you get the block handle, get its line handles. For Inport block, then check the lh.Outport line handle
>> lh=get(gcbh,'LineHandles')
lh =
struct with fields:
Inport: []
Outport: 104.0001
Enable: []
Trigger: []
State: []
LConn: []
RConn: []
Ifaction: []
Reset: []
>> get(lh.Outport,'Name')
ans =
'SignalLabel'
i tried it for model reference but it doesn't work
lh=get(simBlockH,'LineHandles ')
ModelReference block does not have a parameter named 'LineHandles '
It needs to be done within the referenced model itself. The line handles of the Inport and Outport blocks.
This is done within the Modelreference itself
BclkName is the Bloxk handler for the model reference
Could you please correct my code?
See my original answer. Forget about the "Model" block. Open the model and start from there.

Sign in to comment.

Categories

Products

Release

R2018a

Asked:

on 1 Feb 2022

Commented:

on 7 Feb 2022

Community Treasure Hunt

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

Start Hunting!