How do you add physical signal lines programmatically?

조회 수: 5 (최근 30일)
Isaac Friedman
Isaac Friedman 2020년 1월 24일
댓글: Maximilian Bleicher 2020년 3월 29일
I just need to connect a Simulink-PS Converter to a Connector port in a subsystem, but the usual add_line function doesn't work. It returns an error, saying the object doesn't exist.
add_line('mymodel/mySubsystem','C_1','Conn_1', 'autorouting', 'on');
This is the specific error:
Invalid Simulink object name: C_1/1

채택된 답변

Isaac Friedman
Isaac Friedman 2020년 1월 30일
Figured it out. Simscape blocks use "/RConn1", "/LConn1", etc. to denote ports, while Simulink blocks use "/1", "/2", etc. The converter blocks use both depending on which side you're referencing.

추가 답변 (2개)

J Chen
J Chen 2020년 1월 30일
use h1 = get_param('mymodel/mySubsystem/C_1','PortHandles'); to get the port handles. Use add_line to draw line between the handles. Refer to Connect Blocks Using Port Handles section at https://www.mathworks.com/help/simulink/slref/add_line.html?searchHighlight=add_line&s_tid=doc_srchtitle

Maximilian Bleicher
Maximilian Bleicher 2020년 3월 29일
Hi,
i'm facing the same issue. But neither of these variants work:
'PS-Simulink Converter1/1' or 'PS-Simulink Converter1/LConn1'
Is there a simple way to display all ports? What does the following information tell me?
get_param('model/PS-Simulink Converter1','PortHandles')
Inport: []
Outport: 91.0541
Enable: []
Trigger: []
State: []
LConn: 92.0541
RConn: []
Ifaction: []
Reset: []
Thank you in advance
  댓글 수: 1
Maximilian Bleicher
Maximilian Bleicher 2020년 3월 29일
I just figured it out. As long as the connection rules are fulfilled you just have to find the right connectors.
In this case, the following solution works:
port1 = 'Voltage Sensor/RConn1';
port2 = 'PS-Simulink Converter1/LConn1';
add_line(sys,port1,port2);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Physical Units에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by