SEL

The IEC operator is used for bitwise selection.

Syntax:

OUT := SEL(G, IN0, IN1) means:

OUT := IN0; if G = FALSE

OUT := IN1; if G = TRUE

Permitted data types:

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 assignment of instances of a function block to interface (variables) is not supported.

G: BOOL

SEL 1:

TwinCAT does not compute an expression that precedes IN0 if G = TRUE. TwinCAT does not compute an expression that precedes IN1 if G = FALSE.

With graphical programming languages, the expressions at IN0 and IN1 are calculated independently of the input G if a function block, a jump, a return, a branch or an edge detection is connected upstream.

Samples:

ST:

nVar1 := SEL(TRUE,3,4); (*Result: 4*) 

FBD:

SEL 2: