Programmatically connect two subsystems

心不动则不痛 提交于 2019-12-02 19:54:15

问题


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


回答1:


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:

  • Matlab Version 7.12.0.635 (R2011a)

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.



来源:https://stackoverflow.com/questions/22793255/programmatically-connect-two-subsystems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!