Main Content

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 theslexBusExamplemodel 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 byBus Creator 1contains the two signals connected to its inputs:sineandchirp. You can view the hierarchy of a signal by right-clicking on it and selectingSignal Hierarchyfrom the menu. You can also createnestedbuses. For example,sinusoidalandnon-sinusoidalare sub-bus signals in the bus created byBus Creator 3.

Use a Bus Assignment block to replace one or more signals in the signal that is connected to itsBusinput. For example,Bus Assignmentreplaces the signalsconstantandnon-sinusoidalin the bus created byBus Creator 3with 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选择non-sinusoidal.pulse,sinusoidal.sine, andconstantsignals. You can run the simulation to visualizenon-sinusoidal.pulseandsinusoidal.sinein the scope andconstantin the display.

After running the simulation, look at the lines inslexBusExample. Notice that several signals are drawn with three lines. This line format indicates that the signal is abus signal.

For more information on buses, seeGetting 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. InExpanded Notationmode, 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 labelOut1.sinusoidal.sinecreates a leaf-signal namedsinein a sub-bus namedsinusoidalat the output port namedOut1. InCompact Notationmode the leaf-signal name becomes the label. You can switch betweenExpanded NotationandCompact 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 selectCreate 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 labelIn1.sinusoidal.sine选择一个名叫叶信号sinein a sub-bus namedsinusoidal.

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 selectCreate 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, seeSimplify 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. SelectBus Element Portsfrom 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. SelectCreate Busfrom 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

当执行输入的一个子系统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.