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
IEC 61131-3 declares IN0 and IN1 as any type (ANY).
IronPLC selects between integers, reals, bit strings, BOOL, times and
dates, enumerations, subranges, strings, structures and arrays. Every input is
evaluated, including the ones not selected. A selection of strings, structures
or arrays is supported where it is the whole value assigned, and each input is
a literal or a variable. Selecting inside an expression, such as an argument
of CONCAT, or between inputs that call a function or use a computed array
index, is not yet supported.
The return type is the type that every compared or selected input widens to.
The compiler converts a narrower input to that type first, so an INT and a
LINT give a LINT. When no input’s type holds every other input, as with
a DINT and a UDINT, the call is an error
(P4049).
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. |
Description¶
SEL(G, IN0, IN1) returns IN0 if G is FALSE, or IN1 if
G is TRUE.
Example¶
result := SEL(TRUE, 10, 20); (* result = 20 *)
result := SEL(FALSE, 10, 20); (* result = 10 *)
The inputs can be of any of the supported types, such as durations:
delay := SEL(fast, T#5s, T#1s); (* delay = T#5s *)
See Also¶
References¶
IEC 61131-3 §2.5.1.5.5