MUX¶
Multiplexer — selects one of several inputs by index.
Signature¶
┌─────────┐
K ─┤ │
IN0 ─┤ │
IN1 ─┤ MUX ├─ OUT
IN2 ─┤ │
... ─┤ │
└─────────┘
FUNCTION MUX : ANY
VAR_INPUT
K : INT;
IN0 : ANY;
IN1 : ANY;
(* ... up to IN15 ... *)
END_VAR
END_FUNCTION
The return type matches the input type. All INn inputs must share
the same type. MUX is polymorphic over any data type.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Zero-based selector. Selects which input is returned. |
|
|
The candidate values. The number of inputs matches the value range of K (2 to 16). All inputs must share the same type. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
The input selected by K. Same type as the INn inputs. |
Description¶
MUX(K, IN0, IN1, ...) returns the input selected by the zero-based
index K. The number of inputs is variable, and all inputs must be
the same type.
If K = 0, returns IN0
If K = 1, returns IN1
And so on
If K is out of range, the value is clamped: negative K selects IN0, and K greater than or equal to the number of inputs selects the last input. Supports 2 to 16 input values.
This function is polymorphic: it works with any data type for the selected inputs.
Example¶
result := MUX(0, 10, 20, 30); (* result = 10 *)
result := MUX(2, 10, 20, 30); (* result = 30 *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.5