MUX

Overview

IEC selection operator for multiplexing operation.

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

OUT := INk

IN0, ...,INn and OUT can be any identical data type. Make sure that variables of the identical data type are used at these positions, especially when using user-defined data types. The compiler verifies the identity of the types and returns compiler errors. Assigning function block instances to interface variables is not supported.

K has to be BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, LINT, ULINT or UDINT.

MUX selects the Kth value from among a group of values.

Example in IL

Result is 30

LD     0
MUX    30     ,
       40     ,
       50     ,
       60     ,
       70     ,
       80
ST     Var1

Example in ST

Var1:=MUX(0,30,40,50,60,70,80); (* Result is 30 *);
NOTE: A textual expression occurring ahead of an input other than INk will not be processed.

In graphical programming languages, where a Box, Jump, Return, Line Branch, or Edge Detection is connected to IN0 or INn, these statements will always be computed, independently of the input K. This may have an impact on the amount of executed code and thus on the performance. Verify your code carefully to see whether the expressions connected to the inputs IN0, INn should always be executed or only depending on the input K.

For an example illustrating this issue, refer to the SEL operator.