MATLAB: How to obtain the port types of destination ports connected an output port of any Simulink block, from the command line

commandlinesimulink

In the attached Simulink model Test, I would like to query the port types that the inport block is connected to. I use the following code sample to determine this:
ports = get_param('test/In1', 'PortConnectivity')
ports(1)
I get the following result:
ans =
Type: '1'
Position: [155 55]
SrcBlock: []
SrcPort: []
DstBlock: [1x6 double]
DstPort: [0 1 3 2 1 0]
As it can be seen, DstPort is a vector of numbers and I do not know what is the relation between those numbers and the 'trigger', 'enable' and 'ifaction' ports.
I would like to know if there is a way to map those numbers to the corresponding 'trigger', 'enable' and 'ifaction' ports?

Best Answer

The difficulty with using the 'PortConnectivity' property of the inport block is that it does not list the port handles to which the inport block's output is connected to, but rather it lists the destination block handles, and port numbers. The easiest way to find out the port information of the destination ports is to use signal line information as below:
%get the porthandles of ports for the inport block
a = get_param('test/In1','PortHandles');
%get the signal line associated with the output port of the inport
line = get_param(a.Outport,'Line');
%get the destination port handles for the signal
dstport = get_param(line, 'Dstporthandle')
%get the properrites from the handle
port = get(dstport)
%Display the port types of each port
port(1).PortType
port(2).PortType
Related Question