The IEC operator is used as a multiplexer.
OUT := MUX(K, IN0,...,INn)
That means: OUT = IN_K
Permitted data types for K
: BYTE
, WORD
, DWORD
, LWORD
, SINT
, USINT
, INT
, UINT
, DINT
, LINT
, ULINT
UDINT
IN0
, …, INn
and OUT
: any identical data type
Make sure that variables of the identical type are used at all three positions, especially when using user-defined data types. The compiler checks for type identity and returns any compile errors. The assignment of function block instances to interface variables is specifically not supported.
MUX
selects the K-th value from a set of values. The first value is K=0. If K
is greater than the number of other inputs (n), then CODESYS passes on the last value (INn
).




NOTICE

For runtime optimization, CODESYS computes only the expression which precedes IN_K
. However, in simulation mode, CODESYS computes all branches.
Examples
Result in Var1
: 30
ST
Var1 := MUX(0,30,40,50,60,70,80);