Select value from one of two channels
With the first input variable (data type BOOL) of SEL you define which input variable is to be written into the output variable. If the Boolean value = 0 (FALSE), the input variable IN0 will be written into the output variable, otherwise IN1.
Input
1st input: selects between input value IN0 or IN1
2nd input: value is written into the output variable if G = FALSE
3rd input: value is written into the output variable if G = TRUE
Output
Result value as IN0 or IN1
When using the data type STRING with small PLCs like FP-e or FP0, make sure that the length of the result string is equal to or greater than the length of the source string.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
channel_select: BOOL:=FALSE;
channel_0: INT:=0;
channel_1: INT:=0;
output: INT:=0;
END_VAR
In this example the input variables (channel_select, channel_0 and channel_1) have been declared. Instead, you may enter a constant directly at the input contact of a function.
If channel_select has the value 0, channel_0 will be written into output, otherwise channel_1.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,SEL!,Instance,15,0,20,5,,?DG?DIN0?DIN1?C);
B(B_VARIN,,channel_0,13,2,15,4,);
B(B_VARIN,,channel_1,13,3,15,5,);
B(B_VAROUT,,output,20,1,22,3,);
B(B_CONTACT,,channel_select,7,1,9,3,);
L(1,2,7,2);
L(9,2,15,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
output := SEL(G := channel_select, IN0 := channel_0, IN1 := channel_1);
LD |
channel_select |
SEL |
channel_0,channel_1 |
ST |
output |