Main Content

Interface Adapter

A source port and its destination port can be defined by different data interfaces in System Composer™. Such a connection can represent an intermediate point in design, where components from different sources come together. To connect components that have different data interfaces, use an Adapter block and the Interface Adapter dialog box. For interfaces terminology, see Define Port Interfaces Between Components.

An adapter helps connect two components with incompatible port interfaces by mapping between the two interfaces. Use the Adapter block to implement an adapter. Open the Interface Adapter dialog box by double-clicking an Adapter block on the connection between the ports.

With an adapter, you can perform functions on the Interface Adapter dialog box:

  • Create and edit mappings between input and output interfaces.

  • Apply an interface conversion UnitDelay to break an algebraic loop.

  • Apply an interface conversion RateTransition to reconcile different sample time rates for reference models.

  • Apply an interface conversion Merge to merge two or more message or signal lines.

  • When output interfaces are undefined, you can use input interfaces in bus creation mode to author owned output interfaces.

systemcomposer.openModel("exMobileRobotInterfaces");

Map Incompatible Interfaces

When two connected components with Simulink® behaviors have incompatible interfaces, use an Adapter block and the Interface Adapter to define the port connections.

  1. Add an Adapter block on the connection between the two components Sensor and Motor.

  2. Rename the port on the Motor component MotorData.

  3. Assign the coordinates interface to the MotionData port. In the Interface Editor, select the coordinates interface. Then, right-click the port on the System Composer canvas and select Apply selected interface coordinates.

  4. Open the Interface Adapter by double-clicking the Adapter block.

  5. In the Select input box, select the MotorData data element. In the Select output box, select the x data element.

  6. Click the Map and Overwrite button.

You have mapped the MotorData port to the MotionData port by mapping to the data element x from the coordinates data interface.

The MotorData port and Out output are selected in the Interface Adapter dialog box. In the Create new mapping section on the right, the MotorData input and x data element are selected.

You can use an Adapter block to map similar interfaces for an N:1 connection, which is an Adapter with more than one input port and a single output port. A data element from each input connection maps to the output connection data elements.

  1. Create a Motor output port on the top of the Motor component. Add an Adapter block on the connection between the Sensor, Motor, and Command components. Change the number of input ports on an Adapter block in the same way you add and remove component ports. For more information, see Compose Architectures Visually.

  2. Click the name of each port to edit and rename them. Rename the port on the Sensor component Sensor, the port on the Motor component Motor, and the port on the Command component Command.

  3. Assign the sensorData interface to the Sensor port. In the Interface Editor, select the sensorData interface. Then, right-click the port on the System Composer canvas and select Apply selected interface sensorData.

  4. Assign the GPSData interface to the Command port. In the Interface Editor, select the GPSData interface. Then, right-click the port on the System Composer canvas and select Apply selected interface GPSData.

  5. Open the Interface Adapter by double-clicking the Adapter block.

  6. In the Select input box, select the location data element. In the Select output box, select the coordinates data element.

  7. Click the Map button.

On the Adapter block, the data element location associated with the input port Command is now mapped to the data element coordinates associated with the output port Sensor. Now, the Sensor port on the Sensor component can communicate with the Command port on the Command component.

The Command input port and Sensor output port are selected in the Interface Adapter. In the Create new mapping section on the right, the location data element and coordinates output data element are selected.

Use Unit Delay to Break Algebraic Loop

When connecting two components with port connections in both directions, an algebraic loop can occur. To break the algebraic loop, use an Adapter block to insert a unit delay between the components.

  1. Add an Adapter block on the connection between the two components.

  2. Open the Interface Adapter by double-clicking the Adapter block.

  3. From the Apply interface conversion list, select UnitDelay.

You can configure unit delays by clicking the configure icon. Options include:

  • Initial conditions — Default 0

For more information, see Remove Algebraic Loops.

Use Rate Transition Between Simulink Behaviors

When connecting two reference components, the Simulink models that the components reference can have different sample time rates. For compatibility, use an Adapter block to insert a rate transition between the components.

  1. Add an Adapter block on the connection between the two components.

  2. Open the Interface Adapter by double-clicking the Adapter block.

  3. From the Apply interface conversion list, select RateTransition.

You can configure rate transitions by clicking the configure icon. Options include:

  • Ensure data integrity during data transfer — Default true

  • Ensure deterministic data transfer (maximum delay) — Default true

  • Initial conditions — Default 0

For more information, see Rate Transitions and Data Transfers (Simulink Coder).

Use Adapter Block as Merge Block

Use an Adapter block as a Merge block to merge multiple message lines for system architecture models or merge multiple message lines or multiple signal and message lines for software architecture models.

  1. Add an Adapter block on the connection between the two components.

  2. Open the Interface Adapter by double-clicking the Adapter block.

  3. From the Apply interface conversion list, select Merge.

For more information, see Merge Message Connections for Architectures Using Adapter Block.

Use Bus Creation Mode to Author Owned Interfaces

When input ports for an Adapter block are typed by interfaces from incoming connections and no interfaces are defined on the output ports of the adapter, you can use the interface elements from the input ports to author owned interfaces for outgoing connections. An owned interface is an interface that is local to a specific port and not shared in a data dictionary or the model dictionary. Instead of predefining interface structures, you can create the bus structure.

systemcomposer.openModel("SewingMachine");

1. Open the Interface Adapter in bus creation mode by double-clicking the Adapter block.

2. Click the button-add-element.png button to add the input data element Torque to the output port interface for the port named Signal.

The Torque element is selected in the Interface Adapter dialog box, and the cursor is paused on the Add selected input to output port interface button.

3. Select the Displacement element from the Select output box. Click the button-remove-element.png button to remove the output data element Displacement from the output port interface for the port named Signal.

The Displacement element is selected in the Interface Adapter dialog box, and the cursor is paused on the Remove selected output from output port interface button.

4. Click OK to apply the changes.

The owned interface on the output port of the Adapter block is connected to the Signal input port on the Controller component.

The owned interface on the output port of the Adapter block propagates to the connected input port Signal on the Controller component. The owned interface contains one element, Torque.

To convert an owned interface into a shared interface, right-click the port with the owned interface and select Convert to shared interface.

See Also

Blocks

Functions

Related Topics