Documentation

Create Bus Objects with the Bus Editor

To create a bus object and its elements interactively, use the Simulink® Bus Editor. The bus objects that you create with the Bus Editor are stored in the MATLAB® base workspace. To simulate a block that uses a bus object, the bus object must be in the base workspace or in a data dictionary. To save bus object definitions to associate with models, export the bus objects from the base workspace into a MATLAB code file or MAT-file (see Save and Import Bus Objects).

You can specify the bus object to be the data type of a block either before or after defining the bus object. However, before you simulate the model, the bus object and the corresponding bus signal must have the same number of bus elements, in the same order. Also, each bus element in the bus object and in the corresponding signal in the model must have the same attributes.

During model development, you can modify bus signals to match bus objects or modify bus objects to match buses.

Open the Bus Editor

Open the Bus Editor using one of these approaches:

  • In the Simulink Editor, select Edit > Bus Editor.

  • At the MATLAB command line, enter buseditor.

  • In the Model Explorer, in a bus object dialog box, click the Launch Bus Editor button.

Create Bus Objects

Suppose that your model has two buses, with one bus nested inside the other bus.

This example shows how to create bus objects corresponding to the control and main bus signals. To complete the definition of the bus objects and use those objects, also perform the steps in these examples:

  1. Open the ex_bus_object_tutorial.slx model.

  2. In the Simulink Editor, select Edit > Bus Editor.

  3. In the Bus Editor, select File > Add Bus.

    This action creates a bus object with a default name and properties. The object appears in the Hierarchy pane and its properties appear in the Dialog pane.

  4. Specify the name for the bus object, using the Name property. To make it easier to see how the bus object is used in a model, use a name that reflects the bus signal associated with the bus object. The bus signal that combines the valve inputs is named control, therefore, name the bus object CONTROL.

  5. You can provide documentation about the bus object by using the Description property. Enter Combines two valve signals.

  6. Click Apply.

  7. Create the second bus object. In the Hierarchy pane, select the CONTROL bus object and in the toolbar select the Add Bus button ( ).

  8. In the Dialog pane, set Name to MAIN and Description to Defines a bus object for a bus that contains three signals, including the control bus signal.

  9. Click Apply.

    The Hierarchy pane displays bus objects in alphabetical order.

Do not close MATLAB without exporting the bus objects to a MATLAB code file or MAT-file. Otherwise, you lose the bus object definitions.

To define bus element objects for the bus objects, perform the steps in Create Bus Elements for the Bus Object.

Create Bus Elements for the Bus Object

This example builds on bus objects that you created in Create Bus Objects. The example shows how to define the bus element objects for the CONTROL and MAIN bus objects for the ex_bus_object_tutorial.slx model.

    Note:   In this example, the name for the bus element and the corresponding signals are different, to try to highlight that they are distinct entities. If you change the default value for the Element name mismatch diagnostic to error, then the signal name and corresponding bus element name must match exactly to run on all platforms.

    Also, the Bus Creator blocks in this model use the default setting for the Override signal names from inputs block parameter. The default setting of On propagates the signal names of the signals in model, not of the names of the bus elements in the bus object.

To complete the definition of the bus objects and use those objects, also perform the steps in these examples:

  1. In the Bus Editor Hierarchy pane, select the COTNROL bus object.

  2. Select File > Add/Insert BusElement.

    A new bus element with a default name and properties is created in the CONTROL bus object. The bus element appears in the Hierarchy pane below the CONTROL bus object.

  3. In the Dialog pane, set Name to VALVE1, to reflect the name of the top signal in the bus.

  4. For the Constant block, open the Block Parameters dialog box and select the Signal Attributes tab.

  5. In the Bus Editor Dialog pane, set DataType property to double, to match the Output data type block parameter setting for the Constant block. Use the default setting for the other bus element object properties.

  6. Click Apply.

  7. Create a second bus element object that corresponds to the valve2 bus element signal. In the Hierarchy pane, select the VALVE1 bus element object and click the Add/Insert Bus Element button ( ).

  8. For the Constant1 block, open Block Parameters dialog box and select the Signal Attributes tab.

    The Output data type is int8.

  9. In the Bus Editor Dialog pane, for the VALVE2 bus element object, set DataType property to int8. Use the default setting for the other bus element object properties.

  10. Click Apply.

  11. Create a bus element object for the secondary bus element signal of the main bus. In the Hierarchy pane, select the MAIN bus object and click the Add/Insert Bus Element button.

  12. Set the Name property to SECONDARY and the Data type property to int32, matching the In1 block output signal data type. Click Apply.

  13. Create a bus element object for the primary bus element signal of the main bus. In the Hierarchy pane, select the secondary bus element object and click the Add/Insert Bus Element button.

  14. Set the Name property to PRIMARY and the Data type property to boolean, matching the In2 block output signal data type. Click Apply.

To define a bus element object for the control bus, which is the third bus element of the main bus, perform the steps in Nest Bus Object Definitions.

Nest Bus Object Definitions

Any signal in a bus can be another bus, which can in turn contain subordinate buses, to any depth. Describing nested buses with bus objects requires nesting the bus object definitions that the objects provide.

Every bus object defines a data type whose properties are specified by the object. To nest one bus object definition in another, assign to a bus element of one bus object a data type that is defined by another bus object. The bus element object represents a nested bus. The bus object that specifies the data type of the bus element object defines the nested bus elements.

A data type defined by a bus object is called a bus type. Nesting buses by assigning bus types to elements allows the same bus definition to be used conveniently in multiple contexts without unwanted interactions.

This example builds on the bus objects and bus elements that you created for the ex_bus_object_tutorial.slx model in Create Bus Objects and Create Bus Elements for the Bus Object.

  1. In the Bus Editor Hierarchy pane, select the PRIMARY bus element object and click the Add/Insert Bus Element button.

  2. In the Dialog pane, set the Name property to VALVES_BUS.

  3. For the Data type property, use the Bus: <object name> template, replacing <object name> with CONTROL, which is the name of the bus object for the control bus.

  4. Click Apply.

    If you expand the VALVES_BUS bus element object, you see the two bus element objects for the CONTROL bus object, VALVE1 and VALVE2.

  5. You have finished defining bus objects for this example. Consider exporting the bus objects to a MATLAB code file. In the Bus Editor, select File > Export to File. In the Export dialog box, specify a file name for the bus object MAT-file.

To use the bus objects to create nonvirtual buses, perform the steps in Use the Bus Objects in the Model.

Avoid Circular Nested Bus Object Definitions

You can nest a bus object in as many different bus objects as desired, and as many times in the same bus object as desired. You can nest bus objects to any depth, but you cannot define a circular structure by directly or indirectly nesting a bus object within itself.

If you define a circular structure, the Bus Editor posts a warning and sets the data type of the element that would have completed the cycle to double. Click OK to close the warning and continue using the editor.

Use the Bus Objects in the Model

The buses in the ex_bus_object_tutorial model that you defined in the Create Bus Objects example and its associated examples are virtual buses. To use the bus objects you defined in those examples to change the virtual buses to nonvirtual buses:

  1. Open the Bus Creator Block Parameters dialog box. Set Output data type to Bus: CONTROL and select Output as nonvirtual bus.

      Note:   You can use a bus object to specify the data type for a block without specifying that the bus is a nonvirtual bus. You must specify a bus object for a nonvirtual bus, but it is optional for a virtual bus.

  2. Open the Bus Creator1 Block Parameters dialog box. Set Output data type to Bus: MAIN and select Output as nonvirtual bus.

  3. Add another Outport block after the Bus Creator1 block and connect it to the main signal.

  4. Open the Out3 Block Parameters dialog box. In the Signal Attributes tab, set the Data type to Bus: MAIN and select Output as nonvirtual bus in parent model.

The ex_bus_object_tutorial_using_objects.slx model uses the bus objects that you defined. When you simulate the model, you see that the buses are now nonvirtual.

See Also

Blocks

Classes

Related Examples

Was this topic helpful?