Main Content

Simplify Subsystem and Model Interfaces with Bus Element Ports

Buses simplify subsystem and model interfaces by letting you associate multiple signals or messages with one port. They reduce line complexity and clutter in a block diagram, make it easier to change the interface incrementally, and allow access to elements closer to their point of usage.

For an overview of how to use buses to simplify component interfaces, see Reduced Bus Wiring: Bus Element Ports (2 min, 7 sec).

For example, this model contains subsystems that have multiple input and output ports.

Each subsystem has multiple input and output ports.

This equivalent model uses buses, and each subsystem has one input and output port.

Each subsystem has one input port and one output port.

For buses at component interfaces:

In Bus Element and Out Bus Element blocks support multirate virtual buses and do not require Simulink.Bus objects at model interfaces, unlike Inport and Outport blocks. They also provide cleaner bus interfaces.

For example, this model uses Inport, Bus Selector, Bus Creator, and Outport blocks.

Bus Selector and Bus Creator blocks modify the input bus.

This equivalent model uses In Bus Element and Out Bus Element blocks.

In Bus Element and Out Bus Element blocks make the block diagram easier to parse.

At the interface you want to update:

  • Remove signal logging, test points, and descriptions from the lines that the conversion removes. For example, the line between a Bus Creator block and an Outport block must not be designated as a test point.

  • Remove conflicting specifications. For example, when you specify a Simulink.Bus object as the data type of an output port, each element of the output port must inherit its data type from the Simulink.Bus object.

The following examples demonstrate how to update interfaces to use In Bus Element and Out Bus Element blocks. The example models are simple, however, buses are most useful when you have many elements to combine.

Combine Multiple Subsystem Ports into One Port

This example shows three ways to simplify a subsystem interface by converting multiple ports and their connected signals into one port and a bus. Model interfaces do not support this automated conversion.

Open the example model, which contains two subsystems with multiple input and output ports.

mdl = "VirtualBusPortCreation";
open_system(mdl);

Block diagram of VirtualBusPortCreation model

Drag a selection box around the signal lines between the two subsystems. From the action bar that appears, click Create Bus.

Pointer on Create Bus for lines between subsystems

Simulink® replaces the Inport and Outport blocks in the source and destination subsystems with In Bus Element and Out Bus Element blocks.

Drag a selection box around the signal lines between the source blocks and first subsystem. From the action bar that appears, click Create Bus.

Pointer on Create Bus for input lines

Simulink adds a Bus Creator block before the first subsystem and replaces the Inport blocks in the first subsystem with In Bus Element blocks.

Drag a selection box around the signal lines between the second subsystem and Scope blocks. From the action bar that appears, click Create Bus.

Pointer on Create Bus for output lines

Simulink replaces the Outport blocks in the second subsystem with Out Bus Element blocks and adds a Bus Selector block after the second subsystem.

The resulting model uses virtual buses at the subsystem interfaces.

Updated block diagram

Simplify Bus Interfaces in Subsystems and Models

This example shows how to convert a subsystem or model interface that uses Inport, Bus Selector, Bus Creator, and Outport blocks to use In Bus Element and Out Bus Element blocks.

Open the BusInterfaceConversion model. To update the line styles, in the Simulink Toolstrip, on the Modeling tab, click Update Model or Run. Updating the line styles can help you visually identify buses.

mdl = "BusInterfaceConversion";
open_system(mdl)
set_param(mdl,SimulationCommand="Update")

Block diagram of the BusInterfaceConversion model

Double-click the Subsystem block.

Block diagram of the subsystem

In the subsystem, Inport and Outport blocks represent the subsystem input and output. Bus Selector and Bus Creator blocks modify the input bus hierarchy.

To convert Inport and Bus Selector blocks to In Bus Element blocks:

  1. Click a Bus Selector block that directly connects to an Inport block.

  2. In the action bar that appears when you pause on the ellipsis, click Bus Ports.

For example, click the top-level Bus Selector block. Then, click Bus Ports.

Pointer on Bus Ports for top-level Bus Selector block

In this example, the bus between the Inport block and top-level Bus Selector block has a signal label. The conversion uses the signal label as the name of the new bus element port.

Block diagram with In Bus Element blocks

When an Inport block has nondefault parameter values, the conversion applies the nondefault parameter values to the top-level element of the bus element port.

You can similarly convert In Bus Element and Bus Selector blocks. To convert In Bus Element and Bus Selector blocks to In Bus Element blocks:

  1. Click a Bus Selector block that directly connects to an In Bus Element block.

  2. In the action bar that appears when you pause on the ellipsis, click Bus Ports.

For example, click the remaining Bus Selector block. Then, click Bus Ports.

Pointer on Bus Ports for remaining Bus Selector block

To convert Bus Creator and Outport blocks to Out Bus Element blocks:

  1. Click a Bus Creator block that directly connects to an Outport block without branching.

  2. In the action bar that appears when you pause on the ellipsis, click Bus Ports.

For example, select the top-level Bus Creator block. Then, click Bus Ports.

Pointer on Bus Ports for top-level Bus Creator block

In this example, the bus between the top-level Bus Creator block and Outport block has a signal label. The conversion uses the signal label as the name of the new bus element port.

When an Outport block has nondefault parameter values, the conversion applies the nondefault parameter values to the top-level element of the bus element port.

You can similarly convert Bus Creator and Out Bus Element blocks. To convert Bus Creator and Out Bus Element blocks to Out Bus Element blocks:

  1. Click a Bus Creator block that directly connects to an Out Bus Element block.

  2. In the action bar that appears when you pause on the ellipsis, click Bus Ports.

For example, click the remaining Bus Creator block. Then, click Bus Ports.

Pointer on Bus Ports for remaining Bus Creator block

The resulting model simplifies line routing, makes it easier for you to incrementally change the interface, and lets you access elements closer to their point of usage.

Simplified block diagram, which uses In Bus Element and Out Bus Element blocks

To further simplify your block diagram, consider moving the blocks.

To change the name of a bus or element, double-click and edit the corresponding part of the block label.

To easily identify elements of the same port or nested bus, specify block colors.

  1. Double-click an In Bus Element or Out Bus Element block to open the dialog box for the related port.

  2. Select an element or the top bus.

  3. Select a background color from the Set color list.

Final block diagram with blocks aligned and colored

See Also

|

Related Topics