主要内容

Create Nonvirtual Buses

A nonvirtual Simulink®bus is analogous to a struct in C code. To package bus data as structures in generated C code, use nonvirtual buses.

您还必须使用非虚拟巴士来:

  • Construct an array of buses.

  • Interface with external code through an S-function.

  • Have bus data crossMATLAB功能block or Stateflow®图表边界。

  • Display and log buses with aScopeblock.

要创建非虚拟巴士,您必须:

  • Specify aSimulink.Busobject as the data type for the bus. Set数据类型to巴士:<对象名称>, where<对象名称>是个Busobject name.

  • Specify that the output of the block is a nonvirtual bus. Select作为非虚拟巴士的输出or, for外港块,作为非虚拟巴士的输出in parent model.

全部signals in a nonvirtual bus must have the same sample time. For more information, seeModify Sample Times for Nonvirtual Buses.

为了模拟包含非虚拟巴士的模型,引用了Busobjects must be in the base workspace or a data dictionary. You must define theBusobject or use an already definedBusobject. A model callback can load the necessaryBusobjects.

The way to create nonvirtual buses differs based on the location of the bus:

To focus on fundamental steps, these examples are simple. However, buses are most useful when you have many signals to combine.

用公交创建者块创建非虚拟巴士

此示例显示了如何配置总线创建器块以输出非虚拟总线。

Open and simulate the example model, which contains a virtual bus hierarchy.

Create Simulink.Bus Objects

由于此模型中的虚拟总线未定义Busobjects, you must createBusobjects that match the bus hierarchy. If the virtual buses were defined byBusobjects, you would not need to createBusobjects.

To create and saveBus模型中的总线对象,使用Simulink.Bus.createObject功能。当您指定创建包含其他总线的总线的公共汽车创建器块时,此功能会创建Busobjects for the bus created by the block and all nested buses. When you specify a file name, it saves theBusobjects in a function with that name.

businfo = 金宝appsimulink.bus.createobject ...('nonvirtualBusCreationModel',...'nonvirtualBusCreationModel/Bus createor1',...'nont virtualBusCreationFunction');

In the base workspace, Simulink creates twoBusobjects named after the corresponding buses,TopBusNestedBus. In the current folder, Simulink creates a function namedNonvirtualBusCreationFunction.m.

看到创建的Bus对象,打开Bus Editor by entering:

buseditor

Specify Nonvirtual Bus Outputs

In the model, double-click the Bus Creator1 block. In the dialog box, set the输出数据类型toBus: TopBus并选择作为非虚拟巴士的输出check box.

To identify the nonvirtual bus by line style, simulate the model.

The Bus Creator1 block output is a nonvirtual bus, while the Bus Creator block output remains a virtual bus.

双击公共汽车创建器块。在对话框中,设置输出数据类型to巴士:NestedBus并选择作为非虚拟巴士的输出check box.

To identify the new nonvirtual bus by line style, simulate the model.

为引用模型创建非虚拟总线输出

This example shows how to convert a virtual bus to a nonvirtual bus at the output port of a referenced model.

Open and simulate the example model, which references a model with a virtual bus output.

To define the model interface, the output port of the referenced model has aSimulink.Busobject as its data type. To create theBusobject in the base workspace when the referenced model is loaded, the referenced model uses a callback.

在参考模型中,双击Outport Block。在对话框中信号属性tab, select作为非虚拟巴士的输出in parent model, then click好的.

要更新行样式,请再次模拟模型。

The input to the Outport block remains a virtual bus.

The output of the Model block is now a nonvirtual bus.

Convert Virtual Bus to Nonvirtual Bus

This example shows how to convert a virtual bus to a nonvirtual bus within a model.

Open and simulate the example model, which references a model with a virtual bus output.

To define the model interface, the output port of the referenced model has aSimulink.Busobject as its data type. To create theBusobject in the base workspace when the referenced model is loaded, the referenced model uses a callback.

To convert the virtual bus output to a nonvirtual bus, add a To Nonvirtual Bus block between the Model block and Outport block. This block is a preconfigured version of the Signal Conversion block that has theOutput参数设置为Nonvirtual bus.

To identify the nonvirtual bus by line style, simulate the model.

See Also

Objects

相关话题