This example shows how to use Variant Source blocks to provide Variant selection on sensors.
This model illustrates how you can use multiple Variant Source blocks to provide variant selection on sensors. In this model, multiple Variant Source blocks are used to create hierarchical nesting of variant choices. Choices are first grouped by series: A Series, B Series, and C Series. A combination of one or more series is provided as input for a device model. The resulting device model is provided as input to the vendor by including or excluding a sensor selection. In this model, a constant block is masked as a place holder for analog-to-digital converter (A/D) blocks. This model shows variation of sensor inputs. Alternatively, you may use Variant Sink blocks to create variation of actuator outputs. The variant control variables that parameterize the Variant Source blocks are defined in the
Consider this model with Variant Source blocks.
In this model, the Variant Source block "Vendor" gets inputs from Variant Source blocks "X Sensor" and "Device Model" blocks. The "X Sensor" block gets inputs from constants AD7 and AD8. The "Device Model" block gets inputs from Variant Source blocks "A Series", "B Series", and "C Series". The Variant Source blocks "A Series", "B Series", and "C Series" get inputs from Constant blocks.
Now simulate the model.
When you simulate the model, the constant block AD5 is active. The Variant Source block "Vendor" selects between two vendors, VENDOR==1 or VENDOR==2 and in the base workspace, VENDOR is a Simulink.Parameter with VENDOR.Value=1. The Variant Source block "Device Model" selects between DEVICE_MODEL==1, DEVICE_MODEL==2, or DEVICE_MODEL==3 and in the base workspace, DEVICE_MODEL.Value=3. The Variant Source block "C Series" selects between C_SERIES==1 and C_SERIES==2 and in the base workspace, C_SERIES.Value=2.
You can use Simulink Coder to generate code from a model containing Variant Subsystem blocks. By default, the generated code contains only the active variant. Alternatively, you can generate code for all variants guarded by C preprocessor conditionals (#if, #elif, #endif) when using the Embedded Coder.