Documentation

Simplify Subsystem Bus Interfaces

The In Bus Element and Out Bus Element blocks provide a simplified and flexible way to use bus signals as inputs and outputs to subsystems. The In Bus Element block is equivalent to an Inport block combined with a Bus Selector block. The Out Bus Element block is equivalent to an Outport block combined with a Bus Creator block.

Using Bus Creator and Bus Selector Blocks

This model uses Inport, Bus Selector, Bus Creator, and Outport blocks.

Using Simplified Approach

Here is an equivalent model that simplifies the interface by using bus element port blocks.

To work with buses at subsystem interfaces, consider using In Bus Element and Out Bus Element blocks. This bus element port block combination:

  • Reduces signal line complexity and clutter in a block diagram.

  • Makes it easy to change the interface incrementally.

  • Allows access to a bus element closer to the point of usage.

    • For input, avoid a configuration that contains duplicate Inport blocks and a Bus Selector, Goto, and From blocks.

    • For output, avoid a configuration that contains duplicate Goto, From, and Bus Creator blocks.

Tip

To refactor a subsystem interface that uses Inport, Bus Selector, Bus Creator, and Outport blocks to use In Bus Element and Out Bus Element blocks, you can use Simulink® Editor action bars. For details, see Convert Models to Use Bus Element Ports

.

Bus Element Ports

The simplified interface involves creating bus element ports. Use In Bus Element blocks to select elements from a bus signal that is fed to a subsystem. For nonbus signals (including array of buses signals) that feed a subsystem, the In Bus Element block can pass (if no signals are selected) through the value of the input signal for use within the subsystem.

Use Out Bus Element blocks to combine subsystem signals into a virtual bus to output from the subsystem.

You can use bus element port blocks with virtual buses. For nonvirtual bus signals, array of buses signals, and nonbus signals, these limitations apply:

  • For array of bus signals and nonbus signals, the bus element port blocks can only pass through the whole signal, rather than selecting individual elements of the signal.

  • An Out Bus Element block outputs a virtual bus signal from the subsystem.

The In Bus Element block is of block type Inport. The Out Bus Element block is of block type Outport. The bus element port blocks support inherited workflows. You cannot use the Block Parameters dialog box of a bus element port block to specify bus element attributes, such as data type or dimensions.

In the same subsystem, you can use a combination of bus element port blocks with Inport and Outport blocks. However, to improve the readability of the model, define a bus interface for a subsystem by using bus element port blocks throughout the subsystem.

Note

If you save a model containing bus element port blocks to a version of Simulink earlier than R2017a, Simulink converts the model to use a subsystem that contains Bus Selector and Bus Creator blocks, as appropriate.

Create Bus Element Ports

For a new subsystem, creating bus element ports involves adding In Bus Element blocks to select subsystem input signals and Out Bus Element blocks to create virtual bus output signals for the subsystem. For an example showing the workflow for adding bus element ports, see the In Bus Element documentation.

Note

The In Bus Element block has two different names, depending on the Simulink library in which it appears. The functionality of both blocks is the same.

  • In the Sources library and the Ports & Subsystems library — In Bus Element

  • In the Signal Routing library — Bus Element In

The Out Bus Element block has two different names, depending on the Simulink library in which it appears. The functionality of both blocks is the same.

  • In the Sinks library and the Ports & Subsystems library — Out Bus Element

  • In the Signal Routing library — Bus Element Out

Add In Bus Element Blocks

To add an In Bus Element block, you can:

  • Drag the block from the Library Browser. This action adds a port or adds a new element if a port with the same name exists.

  • Use quick insert. This action adds a port.

  • Copy the block from an existing block. Either use copy and paste or right-click and drag the block. If you use the right-click approach, specify whether to use the same port as the original block for new block or to add a subsystem port.

  • In the Block Parameters dialog box list of input signals, select a signal and click .

Tip

Before selecting a signal, make sure that a bus input signal is connected to a subsystem input port.

To select a signal from the input port, use one of these approaches. To select multiple signals from an input bus signal, create multiple In Bus Element blocks, one for each selected signal.

  • Using the Block Parameters dialog box, select from the signals that are in the bus connected to this port. The signals listed in black are already selected and used in the subsystem, and signals in grey are available but are not used already. Signals in red are not available in the input bus signal. For example, signals a and b are already selected, signal c is available to select, and signal d is not available.

    After you select the signals, click

  • In the Simulink Editor, edit the element part of the block icon text. If the port is already connected outside the subsystem, you can select from a list of available signals. For example, if you did a right-click copy of an In Bus Element port block and used the existing port, you can click on text to change the selected element.

    If you delete the b (the element part of the block icon text), then you get a list of signals that you can select.

To pass through a whole signal, leave the element section of the block icon text empty.

You can specify the background color for bus element port blocks, using the Block Parameters dialog box Set color option. This action sets the color of blocks associated with selected elements, or to all blocks if you do not select elements. You can change the name of the port using the Block Parameters dialog box.

Add Out Bus Element Blocks

To output multiple signals from a subsystem as a bus signal, create multiple Out Bus Element blocks, one for each signal that you want to include in the bus. To add an Out Bus Element block, you can:

  • Drag the block from the Library Browser. This action adds a port or adds a new element if a port with the same name exists.

  • Use quick insert. This action adds a port.

  • Copy the block from an existing block. Either copy and paste or right-click and drag the block. If you use the right-click approach, specify whether to use the same port as the original block for the new block or to add a subsystem port.

  • In the Block Parameters dialog box, click . To change the signal name, double-click the signal name in the tree view or in the block diagram and edit the icon text.

If an Out Bus Element block creates a signal A, then another Out Bus Element block for the same port cannot specify signal A (or a child of signal A) as an element.

To add a subbus, in the Block Parameters dialog box, click . To remove blocks associated with selected elements, click .

You can reorder bus elements by dragging and dropping a signal in the list of signals in the Block Parameters dialog box.

You can specify the background color for bus element port blocks, using the Block Parameters dialog box Set color option. This action sets the color of blocks associated with selected elements, or of all blocks if you do not select elements.

Convert Models to Use Bus Element Ports

You can refactor a subsystem interface that uses Inport, Bus Selector, Bus Creator, and Outport blocks to use In Bus Element and Out Bus Element blocks. Conversion operations are supported only when the signal lines or blocks do not have any extra specification, including signal logging. You can:

  • Convert Inport and Bus Selector blocks in a subsystem to In Bus Element blocks.

  • Convert Outport and Bus Creator blocks in a subsystem to Out Bus Element blocks.

  • Transform input or output interfaces of subsystems to use bus element port blocks.

Convert Subsystem Bus Selector Blocks

You can convert a subsystem that uses Bus Selector blocks to use In Bus Element blocks instead.

  1. Click the Bus Selector block that is connected to the Inport block.

  2. From the action bar, select Bus Element Ports.

    The converted subsystem uses In Bus Element blocks.

You can do a similar conversion for multiple layers of Bus Selector blocks.

  1. Perform the conversion on the Bus Selector block that is connected to the Inport block.

  2. Convert the second Bus Selector block.

    Note

    This action is not available if the Bus Creator block output signal has a branch.

Convert Subsystem Bus Creator Blocks

You can convert a subsystem that uses Bus Creator blocks to use Out Bus Element blocks instead.

  1. Click the Bus Creator block that is connected to the Outport block.

  2. From the action bar, select Bus Element Ports.

    The converted subsystem uses Out Bus Element blocks.

You can do a similar conversion for multiple layers of Bus Creator blocks.

  1. Perform the conversion on the Bus Creator block that is connected to the Outport block.

  2. Convert the second Bus Creator block.

Transform Subsystem Input and Output Interfaces

You can convert signals between subsystems to use In Bus Element and Out Bus Element blocks.

Note

Conversion of existing subsystem inputs and outputs to use bus element ports creates virtual buses. If your model relies on the types of the original signals being nonvirtual buses, array of buses, or scalars, choose one of these options:

  • Do not perform the conversion.

  • Modify the model so that it works properly with the newly created virtual buses.

  1. Perform a marquee selection of the signals that connect two subsystems.

  2. From the action bar, select Create Bus.

    The conversion creates Out Bus Element blocks in the source subsystem and In Bus Element blocks in the destination subsystem.

    In the converted model, there is one bus signal between the subsystems, and the BasicSrc and BasicDst subsystems use In Bus Element and Out Bus Element blocks, respectively.

If the input of a subsystem is not directly connected to another subsystem, you can transform the input of the subsystem. If you transform the subsystem input, Simulink inserts a Bus Creator block to maintain connectivity and the subsystem uses In Bus Element blocks.

  1. Perform a marquee selection of the input signals of the subsystem.

  2. From the action bar, select Create Bus.

The converted model uses Bus Creator blocks for subsystem inputs and Bus Selector blocks for subsystem outputs. The converted subsystem (Subsystem3) contains In Bus Element and Out Bus Element blocks.

See Also

Blocks

Related Topics

Was this topic helpful?