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
IEC 61131-3 declares each INn input as any type (ANY).
IronPLC selects between integers, reals, bit strings, BOOL, times and
dates, enumerations, subranges, strings, structures and arrays. Every input is
evaluated, including the ones not selected. A selection of strings, structures
or arrays is supported where it is the whole value assigned, and each input is
a literal or a variable. Selecting inside an expression, such as an argument
of CONCAT, or between inputs that call a function or use a computed array
index, is not yet supported.
The return type is the type that every compared or selected input widens to.
The compiler converts a narrower input to that type first, so an INT and a
LINT give a LINT. When no input’s type holds every other input, as with
a DINT and a UDINT, the call is an error
(P4049).
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). |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
The input selected by K. |
Description¶
MUX(K, IN0, IN1, ...) returns the input selected by the zero-based
index K. The number of inputs is variable.
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.
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