Main Content

Simulink.Bus

Specify properties of buses

Description

ASimulink.Busobject is a data type that, when used withSimulink.BusElementobjects, specifies and validates the properties of a bus. When you simulate or update a model, Simulink®checks whether buses connected to blocks match theSimulink.Busobject data types that the blocks specify.

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

ABusobject is analogous to a structure definition in C: it defines the members of the bus but does not create the bus. ABusobject 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, aBusobject defines the configuration and properties of the signals that the associated bus must have.

Busobjects containSimulink.BusElementobjects. EachBusElementobject specifies the properties of a signal in a bus, such as its name, data type, and dimension. The order of theBusElementobjects in theBusobject defines the order of the signals in the bus.

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

To create and modifyBusobjects in the base workspace or a data dictionary, you can use theBus Editoror MATLAB®commands. You cannot storeBusobjects in model workspaces.

To useBusobjects in a model, seeSpecify Bus Properties with Simulink.Bus Objects.

Creation

Description

example

name= Simulink.Bus返回一个Busobject with default property values. The name of theBusobject is the name of the MATLAB variable to which you assign theBusobject.

Properties

expand all

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

Data Types:char|string

Elements of bus, specified as an array ofSimulink.BusElementobjects. EachBusElement对象定义了名称、数据类型nsions, and other properties of a signal within the bus. For more information, seeSimulink.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 theHeaderFileproperty.

Value Action
'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 theDataScopeproperty, import the data type definition from or export the data type definition to the header file. TheSimulink Coder™software uses this property for code generation. Simulink software ignores this property.

By default, the generated#includedirective uses the preprocessor delimiter"instead of<and>. To generate the directive#include , specifyHeaderFileas.

Data Types:char|string

Data alignment boundary, specified as an integer, in number of bytes. TheSimulink Codersoftware 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 theAlignmentsetting. If the object occurs in a context that requires alignment, you must specify anAlignmentvalue 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 ofBusobjects using arrays. Array indexing lets you create and access multiple elements in an array. Dot notation lets you access property values.

Create twoBusElementobjects, namedChirpandSine, in the base workspace.

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

Create aBusobject, namedNestedBus, that uses the elements defined in theelemsarray.

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

Create two moreBusElementobjects, namedNestedBusandStep. To haveNestedBusrepresent aBusobject, specify aBusobject data type.

clearelemselems(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 theelemsarray.

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

You can view the created objects in theBus Editor.

buseditor

Alternatives

To interactively create aBus对象,使用Bus Editor.

To createBusobjects from blocks in a model, MATLAB data, and external C code, seeCreate Bus Objects Programmatically.

Introduced before R2006a