Simulink.BlockDiagram.addBusToVector - Add Bus to Vector blocks to convert virtual bus signals into vector signals

Syntax

[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector(model)
[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector(model, includeLibs)
[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector(model, includeLibs, reportOnly)

Arguments

model

Model name or handle

includeLibs

Boolean specifying whether to search library blocks. Default: false; the function does not search library blocks.

reportOnly

Boolean specifying whether to change the model or just generate a report. Default: true; the function just generates a report.

Returns

DstBlocks

An array of structures that contain information about blocks that are connected to buses but treat the buses as vectors. If no such blocks exist the array has 0 length. Each structure in the array contains the following fields:

BlockPath

A string specifying the path to the block to which the bus connects

InputPort

An integer specifying the input port to which the bus connects

LibPath

If the block is a library block instance, and includeLibs is true, the path to the source library block. Otherwise, LibPath is empty ([]).

BusToVectorBlocks

If reportOnly is false, and model contains any buses used as vectors, a cell array containing the path to each Bus to Vector block that was added to the model. Otherwise, BusToVectorBlocks is empty ([]).

Description

Simulink.BlockDiagram.addBusToVector reports whether a model contains any bus signals used implicitly as vectors, and optionally changes the model by inserting a Bus to Vector block into each such signal, replacing the implicit use with an explicit conversion. The report and any changes can be limited to the model itself, or can be extended to include any library block of which an instance appears in the model.

Before executing this function, you must do the following:

  1. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to error, or equivalently, execute set_param (model, 'StrictBusMsg', 'ErrorLevel1').

  2. Ensure that the model compiles without error.

  3. Save the model.

If includeLibs is false (the default), the function does not report on or change any blocks in libraries. If the argument is true, the function reports on and may change blocks in libraries.

If reportOnly is true (the default), the function does not change the model or any libraries, displays the number of buses used as vectors, and returns a report in DstBlocks.

If reportOnly is false, the function displays the number of buses used as vectors, returns a report in DstBlocks and BusToVectorBlocks, and inserts a Bus to Vector block into each bus that is used as a vector, in the model and optionally in any libraries. The signal's source and destination blocks are unchanged by this insertion.

The Bus to Vector block is intended only for use in existing models to facilitate the elimination of implicit conversion of buses into vectors. New models and new parts of existing models should avoid implicitly using buses as vectors, and should not use Bus to Vector blocks for any purpose. See Avoiding Mux/Bus Mixtures for more information about using Simulink.BlockDiagram.addBusToVector.

Example

The following model simulates correctly, but the input to the Gain block is a bus, while the output is a vector. Thus the Gain block uses a block as a vector.

If the model shown is open as the current model, you can eliminate the implicit conversion with the following command:

Simulink.BlockDiagram.addBusToVector(gcs, false, false)

Rebuilding and simulating the model then gives this result:

The Gain block no longer implicitly converts the bus to a vector; the inserted Bus to Vector block performs the conversion explicitly. Note that the results of simulation are the same for both models. The Bus to Vector block is virtual, and never affects simulation results, code generation, or performance.

See Also

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS