Main Content

connect

Create architecture model connections

Description

connectors = connect(srcComponent,destComponent) connects the unconnected output ports of the source component srcComponent to the unconnected input ports of the destination component destComponent based on matching port names, and returns a handle to the connector. For physical connections, the connectors are nondirectional so the source and destination components can be interchanged.

To remove a connector, use the destroy function.

example

connectors = connect(arch,[srcComponent,srcComponent,...],[destComponent,destComponent,...]) connects arrays of components in the architecture.

connectors = connect(arch,[],destComponent) connects a parent architecture input port to a destination child component.

connectors = connect(arch,srcComponent,[]) connects a source child component to a parent architecture output port.

connectors = connect(srcPort,destPort) connects a source port and a destination port, or connects two nondirectional physical ports.

example

connectors = connect(srcPort,destPort,stereotype) connects two ports and applies a stereotype to the connector.

connectors = connect(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes.

example

Examples

collapse all

Create and connect two components.

Create a top-level architecture model.

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

Create two new components.

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

Add ports to the components.

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

Connect the components.

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

Improve the model layout.

Simulink.BlockDiagram.arrangeSystem(modelName)

Create and connect two ports.

Create a top-level architecture model.

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

Create two new components.

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

Add ports to the components.

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

Extract the component ports.

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

Connect the ports.

conns = connect(srcPort,destPort);

Improve the model layout.

Simulink.BlockDiagram.arrangeSystem(modelName)

Create and connect a destination architecture port interface element to a component.

Create a top-level architecture model.

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

Create a new component.

newComponent = addComponent(rootArch,"Component1");

Add destination architecture ports to the component and the architecture.

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

Extract corresponding port objects.

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

Add an interface and an interface element, and associate the interface with the architecture port.

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

Select an element on the architecture port and establish a connection.

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

Improve the model layout.

Simulink.BlockDiagram.arrangeSystem(modelName)

Input Arguments

collapse all

Architecture, specified as a systemcomposer.arch.Architecture object.

Source component, specified as a systemcomposer.arch.Component or systemcomposer.arch.VariantComponent object.

Destination component, specified as a systemcomposer.arch.Component or systemcomposer.arch.VariantComponent object.

Source port to connect, specified as a systemcomposer.arch.ComponentPort or systemcomposer.arch.ArchitecturePort object.

Destination port to connect, specified as a systemcomposer.arch.ComponentPort or systemcomposer.arch.ArchitecturePort object.

Stereotype to apply to the connection, specified in the form "<profile>.<stereotype>".

Data Types: char | string

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: connect(archPort,compPort,SourceElement="a")

Option to apply stereotype to connector, specified in the form "<profile>.<stereotype>".

This name-value argument applies only when you connect components.

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

Data Types: char | string

Option to specify rule for connections, specified as either "name" based on the name of ports or "interface" based on the interface name on ports.

This name-value argument applies only when you connect components.

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

Data Types: char | string

Option to allow multiple destination components for the same source component, specified as 1 (true) or 0 (false).

This name-value argument applies only when you connect components.

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

Data Types: logical

Option to select source element for connection, specified as a character vector or string of the name of the data element.

This name-value argument applies only when you connect ports.

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

Data Types: char | string

Option to select destination element for connection, specified as a character vector or string of the name of the data element.

This name-value argument applies only when you connect ports.

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

Data Types: char | string

Option to specify type of automatic line routing, specified as one of the following:

  • "smart" — Use automatic line routing that takes the best advantage of the blank spaces on the canvas and avoids overlapping other lines and labels.

  • "on" — Use automatic line routing.

  • "off" — Use no automatic line routing.

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

Data Types: char | string

Output Arguments

collapse all

Created connections, returned as an array of systemcomposer.arch.Connector or systemcomposer.arch.PhysicalConnector objects.

More About

collapse all

Version History

Introduced in R2019a