Main Content

Explore Simulink Bus Capabilities

This example introduces you to Simulink® bus capabilities in three areas:

  • Working with buses in components

  • Using bus ports at component interfaces

  • Smart editing to perform common bus workflows faster

Open the slexBusExample model.

Display Bus Line Styles

When you open a model that contains buses, the buses have the same line style as scalar signals. To update the line styles, on the Modeling tab, select Update Model.

After the model compiles, several lines appear with three lines. This line style indicates that the line represents a bus.

Work with Buses in Components

The contents of the subsystem in the Working with Buses in Components area demonstrate how to:

  • Create buses using Bus Creator blocks.

  • Replace elements in a bus using a Bus Assignment block.

  • Extract elements from a bus using a Bus Selector block.

Each Bus Creator block groups the elements connected to its input port into a bus. A bus represents a set of elements, analogous to a bundle of wires tied together. For example, the bus created by the Bus Creator block named Bus Creator 1 contains the signals sine and chirp, which are connected to its input ports.

To view the hierarchy of the bus, click the bus and, on the Signal tab, select Signal Hierarchy.

You can also create nested buses. For example, sinusoidal and nonsinusoidal are nested buses in the bus created by the Bus Creator block named Bus Creator 3.

A Bus Assignment block replaces one or more elements in the bus that connects to its Bus input port. For example, the Bus Assignment block replaces the signals constant and nonsinusoidal in the bus created by the Bus Creator block named Bus Creator 3 with new signals. You can use the Bus Assignment block to replace nested buses and nonbus elements.

A Bus Selector block extracts one or more elements from the bus connected to its input. For example, the Bus Selector block selects the nonsinusoidal.pulse, sinusoidal.sine, and constant signals. To display the values of nonsinusoidal.pulse and sinusoidal.sine in the Scope block and constant in the Display block, simulate the model.

Use Bus Ports at Component Interfaces

The subsystems in the Using Bus Ports at Component Interfaces area demonstrate how to:

  • Create buses at the output ports of components by using Out Bus Element blocks.

  • Extract bus elements from the input ports of components by using In Bus Element blocks.

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

Out Bus Element blocks are similar to a Bus Creator block connected to an Outport block. Each Out Bus Element block has a label that you can edit directly to change the names of the output port and bus elements.

You can display the label in either expanded or compact notation.

  • Expanded Notation: Label displays the corresponding port name and the element hierarchy. For example, the Out Bus Element block with the label Out1.sinusoidal.sine creates a bus element named sine in a nested bus named sinusoidal at the output port named Out1.

  • Compact Notation: Label displays only the leaf bus element name. For example, the label Out1.sinusoidal.sine becomes sine.

In either mode, you can directly edit both parts of the label.

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

To see the bus created by a group of Out Bus Element blocks, double-click one of the blocks to open the dialog box for port properties. From the dialog box, you can:

  • Change the name and number of the port.

  • Highlight the lines that correspond to the elements you select.

  • Change the colors of the blocks individually, by bus, or by selected elements.

  • Reorder the elements in the bus.

  • Add or delete bus elements and their corresponding blocks.

  • Specify attributes.

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

In Bus Element blocks are 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 bus element named sine in a nested bus named sinusoidal.

To change the element selected from the input bus, edit the label text directly. When a bus is connected to the corresponding input port, you can select from the 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, then 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 dialog box for the port properties. From the dialog box, you can:

  • Change the name and number of the port.

  • Change the colors of the blocks individually, by bus, or by selected elements.

  • Observe any missing or unused elements in the incoming bus.

  • Add or delete blocks that correspond to selected elements.

  • Specify attributes.

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

Perform Common Bus Workflows Faster

The subsystems in the Smart Editing to Perform Common Bus Workflows Faster area show how to speed up common bus tasks:

  • Convert Bus Selector and Bus Creator blocks to In Bus Element and Out Bus Element blocks.

  • Create buses at subsystem interfaces and bundle outputs of individual blocks into a bus.

  • Automatically create ports to add new elements to a Bus Creator block and select new elements from a Bus Selector block.

The Bus Ports smart editing cue converts Bus Selector and Bus Creator blocks at subsystem interfaces to 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 Ports from the action bar.

The Create Bus smart editing cue bundles multiple elements into a bus.

  1. Drag a selection box around elements.

  2. Select Create Bus from the action bar.

When creating a bus at subsystem interfaces, this action bundles the selected elements in a bus, replaces the Inport and Outport blocks with In Bus Element and Out Bus Element blocks in the subsystem, and adds Bus Creator and Bus Selector blocks to maintain connectivity outside of the subsystem.

When creating a bus at the outputs of individual blocks, this action inserts a Bus Creator block, resizes it, and connects the elements.

To add an element to a bus, drag a line to a Bus Creator block. To select an element from a bus, drag a line to a Bus Selector block and choose the element you want from the list of available elements.

See Also

| | | |

Related Topics