主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

connect

创建架构模型连接

说明

connectors = connect(srcComponent,destComponent) 根据匹配的端口名称,将源组件 srcComponent 未连接的输出端口连接到目的组件 destComponent 未连接的输入端口,并返回连接器的句柄。对于物理连接,连接器是非定向的,因此源组件和目标组件可以互换。

要移除连接器,请使用 destroy 函数。

示例

connectors = connect(arch,[srcComponent,srcComponent,...],[destComponent,destComponent,...]) 连接架构中的组件数组。

connectors = connect(arch,[],destComponent) 连接父架构输入端口和目标子组件。

connectors = connect(arch,srcComponent,[]) 连接源子组件和父架构输出端口。

connectors = connect(srcPort,destPort) 连接一个源端口和一个目的端口,或连接两个非定向物理端口。

示例

connectors = connect(srcPort,destPort,stereotype) 连接了两个端口,并为连接器应用了一个构造型。

connectors = connect(___,Name=Value) 用于在上述语法中的输入参量之外另使用一个或多个名称-值参量指定选项。

示例

示例

全部折叠

创建并连接两个组件。

创建顶层架构模型。

modelName = "archModel";
arch = systemcomposer.createModel(modelName);
rootArch = get(arch,"Architecture");

创建两个新组件。

names = ["Component1","Component2"];
newComponents = addComponent(rootArch,names);

为组件添加端口。

outPort1 = addPort(newComponents(1).Architecture,"testSig","out"); 
inPort1 = addPort(newComponents(2).Architecture,"testSig","in");

连接组件。

conns = connect(newComponents(1),newComponents(2));

改进模型布局。

Simulink.BlockDiagram.arrangeSystem(modelName)

创建并连接两个端口。

创建顶层架构模型。

modelName = "archModel";
arch = systemcomposer.createModel(modelName);
rootArch = get(arch,"Architecture");                  

创建两个新组件。

names = ["Component1","Component2"];
newComponents = addComponent(rootArch,names);

为组件添加端口。

outPort1 = addPort(newComponents(1).Architecture,"testSig","out"); 
inPort1 = addPort(newComponents(2).Architecture,"testSig","in");

提取组件端口。

srcPort = getPort(newComponents(1),"testSig");
destPort = getPort(newComponents(2),"testSig");

连接端口。

conns = connect(srcPort,destPort);

改进模型布局。

Simulink.BlockDiagram.arrangeSystem(modelName)

创建目标架构端口接口元素并将其连接到组件。

创建顶层架构模型。

modelName = "archModel";
arch = systemcomposer.createModel(modelName);
rootArch = get(arch,"Architecture");                  

创建一个新组件。

newComponent = addComponent(rootArch,"Component1");

为组件和架构添加目标架构端口。

outPortComp = addPort(newComponent.Architecture,"testSig","out");
outPortArch = addPort(rootArch,"testSig","out");

提取相应的端口对象。

compSrcPort = getPort(newComponent,"testSig");
archDestPort = getPort(rootArch,"testSig");

添加接口和接口元素,并将接口与架构端口关联。

interface = arch.InterfaceDictionary.addInterface("interface");
interface.addElement("x");
archDestPort.setInterface(interface);

在架构端口上选择一个元素并建立连接。

conns = connect(compSrcPort,archDestPort,DestinationElement="x");

改进模型布局。

Simulink.BlockDiagram.arrangeSystem(modelName)

输入参数

全部折叠

架构,指定为 systemcomposer.arch.Architecture 对象。

要连接的源端口,指定为 systemcomposer.arch.ComponentPortsystemcomposer.arch.ArchitecturePort 对象。

要连接的目标端口,指定为 systemcomposer.arch.ComponentPortsystemcomposer.arch.ArchitecturePort 对象。

要应用于连接的构造型,指定为 "<profile>.<stereotype>" 形式。

数据类型: char | string

名称-值参数

全部折叠

Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来

示例: connect(archPort,compPort,SourceElement="a")

将构造型应用于连接器的选项,以 "<profile>.<stereotype>" 的形式指定。

此名称-值参量仅适用于连接组件时。

示例: conns = connect(srcComp,destComp,Stereotype="GeneralProfile.ConnStereotype")

数据类型: char | string

用于指定连接规则的选项,可根据端口名称指定为 "name",或根据端口上的接口名称指定为 "interface"

此名称-值参量仅适用于连接组件时。

示例: conns = connect([srcComp1,srcComp2],[destComp1,destComp2],Rule="interface")

数据类型: char | string

允许同一源组件有多个目标组件的选项,指定为 1 (true) 或 0 (false)。

此名称-值参量仅适用于连接组件时。

示例: conns = connect(srcComp,[destComp1,destComp2],MultipleOutputConnectors=true)

数据类型: logical

选择连接源元素的选项,指定为数据元素名称的字符向量或字符串。

此名称-值参量仅适用于连接端口时。

示例: conns = connect(archSrcPort,compDestPort,SourceElement="x")

数据类型: char | string

为连接选择目标元素的选项,指定为数据元素名称的字符向量或字符串。

此名称-值参量仅适用于连接端口时。

示例: conns = connect(compSrcPort,archDestPort,DestinationElement="x")

数据类型: char | string

用于指定自动线路路由类型的选项,指定为以下之一:

  • "smart" - 使用自动线路路由,充分利用画布上的空白空间,避免与其他线路和标签重叠。

  • "on" - 使用自动线路路由。

  • "off" - 不使用自动线路路由。

示例: conns = connect(srcPort,destPort,Routing="on")

数据类型: char | string

输出参量

全部折叠

创建的连接,以 systemcomposer.arch.Connectorsystemcomposer.arch.PhysicalConnector 对象数组的形式返回。

详细信息

全部折叠

版本历史记录

在 R2019a 中推出