Skip to Main Content Skip to Search
Product Documentation

Avoiding Mux/Bus Mixtures

Introduction

You can use muxes and virtual buses interchangeably in a model if all constituent signals have the same attributes and the model has no nested buses. You can implement such a signal as either a mux or a virtual bus, and the Simulink software by default automatically converts between the two formats as needed. See Mux Signals for information about muxes.

Do not mix muxes and buses in new applications.

One way that such a mux/bus mixture occurs is when you use a Mux block to create a virtual bus, such as a Mux block that outputs to a Bus Selector. This kind of mixture does not support strong type checking and increases the likelihood of run-time errors. MathWorks discourages treating muxes and buses interchangeably. Mux/bus mixtures may become unsupported in the future. Simulink generates a warning for this kind of mux/bus mixture when you load a model created in a release prior to R2010a. For new models, Simulink generates an error. Do not create such mux/bus mixtures in new applications, and consider upgrading existing applications to avoid such mixtures. The Configuration Parameters > Diagnostics > Connectivity pane provides diagnostics that report cases where muxes and virtual buses are used interchangeably, and includes capabilities that you can use to upgrade a model to eliminate such mixtures. See Using Diagnostics for Mux/Bus Mixtures and Using the Model Advisor for Mux/Bus Mixtures for details.

Another way for a mux/bus mixture to occur is when a virtual bus signal is treated as a mux, such as a bus signal that inputs directly to a Gain block. To detect such mixtures, in the Configuration Parameters > Diagnostics > Connectivity pane, set the Bus signal treated as vector diagnostic to warning or error.

Using Diagnostics for Mux/Bus Mixtures

The Configuration Parameters > Diagnostics > Connectivity pane provides the following diagnostics to detect mux/bus mixtures.

DiagnosticDescription
Mux blocks used to create bus signalsDetect and correct muxes that are used as buses
Bus signal treated as vectorDetect and correct buses that are used as muxes (vectors)
Non-bus signals treated as bus signalsDetect when Simulink implicitly converts a non-bus signal to a bus signal

You can use these diagnostics as described in this section, or you can use the Model Advisor to perform the some of these checks and also to 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, in the Configuration Parameters > Diagnostics > Connectivity pane:

  1. Set Mux blocks used to create bus signals to warning or error.

  2. Set 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 in Mux blocks used to create bus signals.

  2. In the Configuration Parameters > Diagnostics > Connectivity pane, set Mux blocks used to create bus signals to error.

  3. In the same pane, set 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 Bus signal treated as vector.

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

Non-bus signals treated as bus signals

Detect when Simulink implicitly converts a non-bus signal to a bus signal:

  1. Correct any cases of Mux blocks used to create buses as described in Mux blocks used to create bus signals.

  2. In the Configuration Parameters > Diagnostics > Connectivity pane, set Mux blocks used to create bus signals to error.

  3. In the same pane, set Non-bus signals treated as bus signals 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 Non-bus signals treated as bus signals.

Using the Model Advisor for Mux/Bus Mixtures

The Model Advisor provides a convenient way to both run the diagnostics for mux/bus mixtures and obtain advice about corrections. To use the Model Advisor to detect and correct mux/bus mixtures:

  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 model uses a bus as a mux by inputting the bus to a Gain block. The Scope block shows the results.

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 Compatibility Issues

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.

In R2010a, if you load a model created in a prior release, you may get warning messages that you did not get before. To avoid getting Mux block-related warnings for existing models that you want to load in R2010a, use the slreplace_mux function to substitute Bus Creator blocks for any Mux blocks used to create buses signals.

Avoiding Mux/Bus Mixtures When Developing Models

MathWorks discourages the use of mux/bus mixtures, and may cease to support them at some future time. MathWorks, therefore, recommends upgrading existing models to eliminate any mux/bus mixtures, 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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