Mux 4 with Fallback
medium
Route one of four inputs by select value, falling back to a safe default and raising a fault flag when the select is out of range.
What it teaches
Defensive routing — real selector values come from HMIs and networks and can be garbage. In range, behave like Mux 4; out of range, route the configured fallback value and raise a fault flag instead of acting on a stale or random source. The validate-then-act guard that wraps every external command in production code.
Inputs and outputs
| Tag | Type | Default | Description |
|---|---|---|---|
| In_Select | DINT | 0 | Selector index |
| In_Source0 | REAL | 5 | First input value |
| In_Source1 | REAL | 10 | Second input value |
| In_Source2 | REAL | 20 | Third input value |
| In_Source3 | REAL | 30 | Fourth input value |
| Cfg_Fallback | REAL | -99 | Safe default value routed when selector is out of range |
| Out_Selected | REAL | — | Routed value |
| Sts_Fault | BOOL | — | Out of range fault flag |
Required behavior
- Out_Selected equals In_Source0 when In_Select is 0.
- Out_Selected equals In_Source1 when In_Select is 1.
- Out_Selected equals In_Source2 when In_Select is 2.
- Out_Selected equals In_Source3 when In_Select is 3.
- Out_Selected equals Cfg_Fallback when In_Select is less than 0 or greater than 3.
- Sts_Fault is 1 when In_Select is less than 0 or greater than 3.
- Sts_Fault is 0 when In_Select is between 0 and 3 inclusive.