Documentation

Simulink Bus Signals

This example introduces you to the following Simulink® bus signal capabilities:

  • Bus Creator, Bus Selector, and Bus Assignment blocks

  • Bus Element Ports at component interfaces

  • Smart editing to perform common bus workflows faster

The three areas in the slexBusExample model used in this example correspond to these three capabilities.

Bus Creator, Bus Selector, and Bus Assignment Blocks

The subsystem in the "Bus Creator, Bus Selector, and Bus Assignment Blocks" area shows how to

  • Create bus signals using the Bus Creator block

  • Replace signals in a bus using the Bus Assignment block

  • Select signals from a bus using the Bus Selector block

Use a Bus Creator block to bundle the signals connected to its inputs into a bus. A bus signal represents a set of signals, analogous to a bundle of wires tied together. For example, the bus signal created by Bus Creator 1 contains the two signals connected to its inputs: sine and chirp. You can view the hierarchy of a signal by right-clicking on it and selecting Signal Hierarchy from the menu. You can also create nested buses. For example, sinusoidal and non-sinusoidal are sub-bus signals in the bus created by Bus Creator 3.

Use a Bus Assignment block to replace one or more signals in the signal that is connected to its Bus input. For example, Bus Assignment replaces the signals constant and non-sinusoidal in the bus created by Bus Creator 3 with new signals. You can use the Bus Assignment block to replace both leaf and sub-bus signals.

Use a Bus Selector block to extract one or more signals from the bus connected to its input. For example, Bus Selector selects the non-sinusoidal.pulse, sinusoidal.sine, and constant signals. You can run the simulation to visualize non-sinusoidal.pulse and sinusoidal.sine in the scope and constant in the display.

After running the simulation, look at the lines in slexBusExample. Notice that several signals are drawn with three lines. This line format indicates that the signal is a bus signal.

For more information on buses, see Getting Started with Buses.

Bus Element Ports at Component Interfaces

The subsystems in the "Buses at Component Interfaces (Bus Element Ports)" area show how to

  • Create bus signals using the Out Bus Element block

  • Select signals from a bus using the In Bus Element block

Out Bus Element Blocks

The first subsystem consists of five source blocks and five Out Bus Element blocks.

An Out Bus Element block is similar to a Bus Creator block connected to an Outport block. Each Out Bus Element block has a label. You can display this label in two modes. In Expanded Notation mode, the label is made up of the name of the corresponding subsystem port and a dot-separated string that determines the element in the bus. For example, the Out Bus Element block with the label Out1.sinusoidal.sine creates a leaf-signal named sine in a sub-bus named sinusoidal at the output port named Out1. In Compact Notation mode the leaf-signal name becomes the label. You can switch between Expanded Notation and Compact Notation.

In either mode, you can directly edit the label text to change the element created in the output bus.

To create a new element in the bus, copy and paste an Out Bus Element block. To create a new output port at the subsystem interface, right-click and drag an Out Bus Element block and select Create New Port.

To see the bus created by a group of Out Bus Element blocks, double click on the icon of one of the blocks to open the port properties dialog box. You can highlight the signals connected to the blocks, change the name and number of the port, change the colors of the blocks, and reorder the signals in the bus.

In Bus Element Blocks

The second subsystem consists of two Scope blocks, one Display block, and five In Bus Element blocks.

An In Bus Element block is similar to an Inport block connected to a Bus Selector block. The labels of In Bus Element blocks work the same way as Out Bus Element block labels do. For example, the In Bus Element block with the label In1.sinusoidal.sine selects a leaf signal named sine in a sub-bus named sinusoidal.

To change the element selected from the input bus, edit the label text directly. If a bus is already connected to the corresponding input port, you can select from a list of available signals.

To select a new element from the bus, copy and paste an In Bus Element block. To create a new input port at the subsystem interface, right-click and drag an In Bus Element block and select Create New Port. To see the bus accessed by a group of In Bus Element blocks, double-click the icon of one of the blocks to open the port properties dialog box. You can change the name and number of the port, change the color of the blocks, and observe any missing or unused signals in the incoming bus.

For more information about using In Bus Element and Out Bus Element blocks, see Simplify Subsystem Bus Interfaces.

Smart Editing to Perform Common Bus Workflows Faster

The subsystems in the "Tips & Tricks For Working With Buses" area show how to speed up common bus tasks by using:

  • The "Bus Element Ports" smart editing cue to convert Bus Selector and Bus Creator blocks to In Bus Element and Out Bus Element blocks

  • The "Create Bus" smart editing cue to create buses at subsystem interfaces and to bundle outputs of individual blocks into a bus

  • Automatic port creation to add a new signal to a Bus Creator block and to select a new signal from a Bus Selector block

Convert Bus Creator and Bus Selector blocks to In Bus Element and Out Bus Element Blocks

You can use the "Bus Element Ports" smart editing cue to convert existing subsystems that use Bus Selector and Bus Creator blocks at their interfaces to use instead In Bus Element and Out Bus Element blocks.

  1. Click on a Bus Selector block that is connected to an Inport block or a Bus Creator block that is connected to an Outport block.

  2. Select Bus Element Ports from the action bar.

Bundle Individual Signals into a Bus

You can use the "Create Bus" smart editing cue to bundle multiple signals into a bus.

  1. Drag a selection box around the signals of interest.

  2. Select Create Bus from the action bar.

Between Subsystems

When performed between two subsystems, this action replaces the Inport and Outport blocks in the source and destination subsystems with In Bus Element and Out Bus Element blocks.

Subsystem Inputs

When performed at the input of a subsystem that is connected to some other non-subsystem block, this action bundles the selected signals into a bus using a Bus Creator block and replaces the Inport blocks in the subsystem with In Bus Element blocks.

Subsystem Outputs

When performed at the output of a subsystem that is connected to some other non-subsystem block, this action replaces the Outport blocks in the subsystem with Out Bus Element blocks and inserts a Bus Selector block to maintain connectivity.

Block Outputs

When performed at the outputs of individual blocks, this action inserts a Bus Creator block, resizes it, and makes the connections.

Automatic Port Creation

You can add a new signal to a bus by dragging a signal line to a Bus Creator block. To select a new signal from a bus, drag a signal line to a Bus Selector block and choose the signal you want from the list of available signals.

Was this topic helpful?