MUX

The IEC operator is used as a multiplexer.

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

This 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 with the same type are used at all three positions, especially when using user-defined data types. The compiler checks the type equality and issues compilation errors. In particular, the allocation of instances of a function block to interface (variables) is not supported.

MUX selects the K-th value from a set of values. The first value corresponds to K=0. If K is greater than the number of additional inputs (n), TwinCAT passes on the last value (INn).

MUX 1:

For the purpose of run-time optimization, TwinCAT only calculates the expression with which you have preceded IN_K.

Examples:

Result: nVar is 30.

ST:

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

FBD:

MUX 2: