Operator ‘MUX’ΒΆ

This IEC operator is used as a multiplexer.

OUT := MUX(K, IN0,...,INn)

Means: OUT = IN_K

Permitted data type for K: BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, LINT, ULINT, oUDINT.

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).

Hint

For runtime optimization, CODESYS computes only the expression that precedes IN_K. However, CODESYS computes all branches in simulation mode.

Examples

Result in Var1 is 30.

ST:

Var1 := MUX(0,30,40,50,60,70,80);