Intermixing Composite Signal Types

Differences Between Muxes and Buses

Muxes are implemented as indexed vectors, while buses are implemented as structures. Buses can do anything muxes can do and more. See Using Muxes and Using Buses for summaries of the two capabilities and their similarities and differences.

For convenience, muxes and virtual buses can by default be intermixed where automatic conversion is possible. Intermixed composite signals can occur only with muxes and virtual buses where all constituent signals have the same attributes and no nested buses exist. All intermixed composite signals fall into one of two categories:

Neither of these mixtures is compatible with strong type checking, so both increase the likelihood of run-time errors. You should not mix muxes and virtual buses in new applications, and you should upgrade existing applications to avoid such mixtures. Configuration Parameters diagnostics, Model Advisor checks, and other tools are provided for detecting and correcting intermixed composite signals.

Using Diagnostics for Mixed Composite Signals

Two controls are provided on the Diagnostics > Connectivity pane to detect mixed composite signals:

You can use these diagnostics as described in this section, or use the Model Advisor to perform the same checks and also obtain advice about corrections, as described in Consulting the Model Advisor. For complete information about the Connectivity pane, see Connectivity Diagnostics Overview.

Mux blocks used to create bus signals

To detect and correct muxes that are used as buses:

  1. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to warning or error.

  2. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Bus signal treated as vector to none.

  3. Click OK or Apply.

  4. Build the model.

  5. Replace blocks as needed to correct any cases of Mux blocks used to create buses. You can use the slreplace_mux function to replace all such Mux blocks in a single operation.

For complete information about this option, see the reference documentation for Mux blocks used to create bus signals.

Bus signal treated as vector

To detect and correct buses that are used as if they were muxes (vectors):

  1. Correct any cases of Mux blocks used to create buses as described above.

  2. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to error.

  3. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Bus signal treated as vector to warning or error.

  4. Click OK or Apply.

  5. Build the model.

  6. Correct the model where needed as described under Correcting Buses Used as Muxes.

For complete information about this option, see the reference documentation for Mux blocks used to create bus signals.

Equivalent Parameter Values

Due to the requirement that Mux blocks used to create bus signals be error before Bus signal treated as vector is enabled, one parameter, StrictBusMsg, can specify all permutations of the two controls. The parameter can have one of five values. The following table shows these values and the equivalent GUI control settings:

Value of StrictBusMsg (API) Mux blocks used to create bus signals (GUI)Bus signal treated as vector (GUI)
Nonenonenone
Warningwarningnone
ErrorLevel1errornone
WarnOnBusTreatedAsVectorerrorwarning
ErrorOnBusTreatedAsVectorerrorerror

Using the Model Advisor for Mixed Composite Signals

The Model Advisor provides a convenient way to run both composite signal diagnostics and obtain advice about corrections. To use the Model Advisor to detect and correct mixed composite signals:

  1. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to none.

  2. Click OK or Apply.

  3. Select and run the Model Advisor check Simulink > Check for proper bus usage.

    The Model Advisor reports any cases of Mux blocks used to create bus signals.

  4. Follow the Model Advisor's suggestions to correct any errors reported by the check. You can use the slreplace_mux function to replace all such errors in a single operation.

  5. Set Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to error.

  6. Set Configuration Parameters > Diagnostics > Connectivity > Bus signal treated as vector to none.

  7. Click OK or Apply.

  8. Again run the Model Advisor check Simulink > Check for proper bus usage.

    The Model Advisor reports any cases of bus signals treated as muxes (vectors).

  9. Follow the Model Advisor's suggestions and the information in Correcting Buses Used as Muxes to correct any errors discovered by the check.

Instructions for using the Model Advisor appear in Consulting the Model Advisor.

Correcting Buses Used as Muxes

When you discover a bus signal used as a mux, one answer is to reorganize the model by replacing blocks so that the mixture no longer occurs. Where that is undesirable or unfeasible, the Simulink® software provides two capabilities to address the problem:

For example, this figure shows a model that uses a bus as a mux by inputting the bus to a Gain block.

This figure shows the same model, rebuilt after inserting a Bus to Vector block into the bus.

Note that the results of simulation are the same in either case. The Bus to Vector block is virtual, and never affects simulation results, code generation, or performance. For more information, see the reference documentation for the Bus to Vector block and the Simulink.BlockDiagram.addBusToVector function.

Bus to Vector Block Backward Compatibility

If you use Save As to save a model in a version of the Simulink product before R2007a (V6.6), the following is done:

The resulting model specifies strong type checking for Mux blocks used to create buses. Before you can use the model, you must reconnect or otherwise correct each signal that contained a Bus to Vector block but is now interrupted by a null subsystem.

Avoiding Mixed Composite Signals When Developing Models

The MathWorks discourages the use of mixed composite signals, and may cease to support them at some future time. The MathWorks therefore recommends upgrading existing models to eliminate any mixed composite signals, and permanently setting Mux blocks used to create bus signals and Bus signal treated as vector to error in all new models and all existing models that may undergo further development.

  


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