matlabsimulinksimscape

Programmatically connect two subsystems


I'm trying to build a complex model programmatically reusing some custom blocks/models I have developed before, but I cannot manage to connect two PMC_Port

This is what I have:

% Main system    
sys_name = 'model';
sys = new_system(sys_name)
open_system(sys_name)

load_system('circuit_cell') % Subsystem with 6 PMC_Port elements
                            % stored in circuit_cell.mdl file
% Add cell #1
add_block('built-in/Subsystem', [sys_name '/cell1'])
Simulink.BlockDiagram.copyContentsToSubSystem('circuit_cell', [sys_name '/cell1']);

% Add cell #2
add_block('built-in/Subsystem', [sys_name '/cell2'])
Simulink.BlockDiagram.copyContentsToSubSystem('circuit_cell', [sys_name '/cell2']);

% And now I want to connect one cell with the other
add_line('model', 'cell1/1', 'cell2/1', 'autorouting', 'on')

...but I always get a 'Invalid Simulink object name: cell1/1' error message.

EDIT.- Here it is circuit_cell.mdl file: http://pastebin.com/mXuVFtM3


Solution

  • Thanks to @am304 comments I manage to solve this issue.

    Connection through physical ports must be made through RConn1 and LConn1 keynames, so the command add_line should be executed as follows:

    add_line('model', 'cell1/RConn1', 'cell2/LConn1', 'autorouting', 'on')
    

    Tested for:

    Thanks!

    Edit.- As @am304 says it's not documented so it can be changed. If more versions are checked, please post a comment and I will update the answer.