SEL¶
Binary selection — selects one of two inputs based on a Boolean selector.
Signature¶
┌─────────┐
G ─┤ │
IN0 ─┤ SEL ├─ OUT
IN1 ─┤ │
└─────────┘
FUNCTION SEL : ANY
VAR_INPUT
G : BOOL;
IN0 : ANY;
IN1 : ANY;
END_VAR
END_FUNCTION
The return type matches the type of IN0 and IN1, which must be the
same. SEL is polymorphic over any data type.
Inputs
Name |
Type |
Description |
|---|---|---|
|
|
Selector. FALSE selects IN0; TRUE selects IN1. |
|
|
Value returned when G is FALSE. |
|
|
Value returned when G is TRUE. |
Outputs
Name |
Type |
Description |
|---|---|---|
Return value |
|
IN0 if G is FALSE, IN1 if G is TRUE. Same type as IN0 and IN1. |
Description¶
SEL(G, IN0, IN1) returns IN0 if G is FALSE, or IN1 if
G is TRUE. The types of IN0 and IN1 must be the same, and
the return type matches the input type.
This function is polymorphic: it works with any data type for the selected inputs.
Example¶
result := SEL(TRUE, 10, 20); (* result = 20 *)
result := SEL(FALSE, 10, 20); (* result = 10 *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.5