MATLAB: How to find and work with Physical Modeling I/O ports of a subsystem in Simulink

drivelinehydraulicsmechanicsphysmodpmiopowersystemssimsimdrivelinesimhydraulicssimmechanicssimpowersystemssimulink

I would like to use the model construction commands to manipulate the Physical Modeling (SimPowerSystems, SimMechanics, SimHydraulics, etc) connection i/o ports in a manner similar to regular block ports.

Best Answer

The Connection Ports on the blocks are like any other port. The best way to get a handle is to first acquire the handle of the block (use find_system etc.). Once you have the block handle then do the following:
PortH = get_param(blockH,'PortHandles');
PortH will be a structure that will have all the port handles. The Physical Modeling connection port handles will be under the fields LConn and RConn (for left connection and right connection).
When finding a port handle corresponding to a port block, you need to do the following:
1. Search for the peer port blocks (find_system for BlockType PMIOPort with
SearchDepth 1 but not 0)
2. Filter out those with a different Side property
3. Work out the corresponding block number among blocks of matching Side
4. Index into the PortHandles.L/RConn