Main Content

Simulink.Bus

Specify properties of buses

Description

A Simulink.Bus object is a data type that, when used with Simulink.BusElement objects, specifies and validates the properties of a bus. When you simulate or update a model, Simulink® checks whether buses connected to blocks match the Simulink.Bus object data types that the blocks specify.

A Bus object specifies only the architectural properties of a bus. For example, a bus object can specify element names, hierarchy, order, and data types. A Bus object cannot specify the values of the signals in a bus.

A Bus object is analogous to a structure definition in C: it defines the members of the bus but does not create the bus. A Bus object is also similar to a cable connector. The connector defines all the pins and their configuration and controls what types of wires can be connected to it. Similarly, a Bus object defines the configuration and properties of the signals that the associated bus must have.

Bus objects contain Simulink.BusElement objects. Each BusElement object specifies the properties of a signal in a bus, such as its name, data type, and dimension. The order of the BusElement objects in the Bus object defines the order of the signals in the bus.

A Bus object can specify properties that were not defined by constituent signals, but were left to be inherited.

To create and modify Bus objects in the base workspace or a data dictionary, you can use the Bus Editor or MATLAB® commands. You cannot store Bus objects in model workspaces.

To use Bus objects in a model, see Specify Bus Properties with Simulink.Bus Objects.

Creation

Description

example

name = Simulink.Bus returns a Bus object with default property values. The name of the Bus object is the name of the MATLAB variable to which you assign the Bus object.

Properties

expand all

Bus description, specified as a character vector. Use the description to document information about the Bus object, such as the kind of signal it applies to or where the Bus object is used. This information does not affect Simulink processing.

Data Types: char | string

Elements of bus, specified as an array of Simulink.BusElement objects. Each BusElement object defines the name, data type, dimensions, and other properties of a signal within the bus. For more information, see Simulink.BusElement.

Data type definition mode in generated code, specified as 'Auto', 'Exported', or 'Imported'. This property specifies whether during code generation the data type definition is imported from, or exported to, the header file specified with the HeaderFile property.

ValueAction
'Auto' (default)

Import the data type definition from the specified header file. If you do not specify the header file, export the data type definition to the default header file.

'Exported'Export the data type definition to the specified header file or default header file.
'Imported'Import the data type definition from the specified header file or default header file.

Data Types: char | string

C header file used with data type definition, specified as a character vector. Based on the value of the DataScope property, import the data type definition from or export the data type definition to the header file. The Simulink Coder™ software uses this property for code generation. Simulink software ignores this property.

By default, the generated #include directive uses the preprocessor delimiter " instead of < and >. To generate the directive #include <myTypes.h>, specify HeaderFile as <myTypes.h>.

Data Types: char | string

Data alignment boundary, specified as an integer, in number of bytes. The Simulink Coder software uses this property for code generation. Simulink software ignores this property.

The starting memory address for the data allocated for the bus is a multiple of the Alignment setting. If the object occurs in a context that requires alignment, you must specify an Alignment value with a positive integer that is a power of 2, not exceeding 128.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Examples

collapse all

Create a hierarchy of Bus objects using arrays. Array indexing lets you create and access multiple elements in an array. Dot notation lets you access property values.

Create two BusElement objects, named Chirp and Sine, in the base workspace.

elems(1) = Simulink.BusElement;
elems(1).Name = 'Chirp';

elems(2) = Simulink.BusElement;
elems(2).Name = 'Sine';

Create a Bus object, named NestedBus, that uses the elements defined in the elems array.

NestedBus = Simulink.Bus;
NestedBus.Elements = elems;

Create two more BusElement objects, named NestedBus and Step. To have NestedBus represent a Bus object, specify a Bus object data type.

clear elems

elems(1) = Simulink.BusElement;
elems(1).Name = 'NestedBus';
elems(1).DataType = 'Bus: NestedBus';

elems(2) = Simulink.BusElement;
elems(2).Name = 'Step';

Create the bus at the top of the bus hierarchy that uses the elements defined in the elems array.

TopBus = Simulink.Bus;
TopBus.Elements = elems;

You can view the created objects in the Bus Editor.

buseditor

Alternatives

To interactively create a Bus object, use the Bus Editor.

To create Bus objects from blocks in a model, MATLAB data, and external C code, see Create Bus Objects Programmatically.

Introduced before R2006a