0

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
jgsogo
  • 706
  • 1
  • 9
  • 18
  • I tried to reproduce your problem, but I don't get any error. Can you provide the 'circuit_cell'? Does it have input and output ports? – Daniel Apr 01 '14 at 21:25
  • I've edited the question to post a link to 'circuit_cell.mdl'. Thanks in advance for your help. – jgsogo Apr 02 '14 at 07:53
  • And yes, I'm trying to connect ports (maybe I'm misunderstanding what they were thought for) – jgsogo Apr 02 '14 at 07:59
  • If you go into `cell1` and select the (presumably output) block you want to connect to `cell2` with the mouse, then type `gcb` at the command line, what do you get? Is it really `cell1/1`? Likewise for for `cell2/1`. – am304 Apr 02 '14 at 08:16
  • @am304 Yes, checked that and names are ok: `cell1/1` and `cell2/1`; and if I change names I get the updated ones with `gcb` ...and it is failing the same way when calling `add_line` with them. – jgsogo Apr 02 '14 at 08:23
  • 1
    @jgsogo OK, if they are Simscape or physical ports, you may want to try something like `cell1/RConn1` (if on the right-hand side of the block) or `cell1/LConn1` (if on the left-hand side of the block). I have a vague memory that these blocks are special and the exact want to connect them programmatically is not documented. – am304 Apr 02 '14 at 08:44

1 Answers1

0

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.

jgsogo
  • 706
  • 1
  • 9
  • 18