BOOL into STRING
The function BOOL_TO_STRING converts a value of the data type BOOL into a value of the data type STRING[2]. The resulting string is represented by ' 0' or ' 1'.
Input
Output
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
input_value: BOOL:=FALSE;
result_string: STRING;
END_VAR
The input variable input_value of the data type BOOL is intialized by the value TRUE. The output variable result_string is of the data type STRING[2]. It can store a maximum of two characters. You can declare a character string that has more than one character, e.g. STRING[5]. From the 5 characters reserved, only 2 are used.
Instead of using the variable input_value, you can write the constants TRUE or FALSE directly to the function’s input contact in the body.
The input_value of the data type BOOL is converted into STRING[2]. The converted value is written to result_string. When the variable input_value = TRUE, result_string shows ' 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,BOOL_TO_STRING!,Instance,9,1,19,3,,?D?C);
B(B_VARIN,,input_value,7,1,9,3,);
B(B_VAROUT,,result_string,19,1,21,3,);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
IF Boolean_value then
output_value:=BOOL_TO_STRING(input_value);
END_IF;
If you wish to have the result 'TRUE' or 'FALSE' instead of ' 0' or ' 1', you cannot use the function BOOL_TO_STRING. This example illustrates how you create a STRING[5] that contains the characters 'TRUE' or 'FALSE' from an input value of the data type BOOL.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
input_value: BOOL:=TRUE;
(*example value*)
result_string: STRING[5]:='';
(*result: here TRUE*)
@'': @'';
@'': @'';
END_VAR
In this example, both an input variable input_value of the data type BOOL and an output variable result_string of the data type STRING[5] are declared.
In order to realize the intended operation, the standard function MOVE is used. It assigns the value of its input to its output unchanged. At the input, the STRING constant 'TRUE' or 'FALSE' is attached. In essence a "BOOL to STRING" conversion occurs, since the Boolian variable input_variable at the enable input (EN) contact decides the output of STRING.
BODY
WOKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORRKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 8 ;
NETWORK_BODY
B(B_CONTACT,,input_value,3,1,5,3,);
B(B_F,E_MOVE!,Instanz,11,0,17,4,,?DEN?D?AENO?C);
B(B_VARIN,,'TRUE',9,2,11,4,);
B(B_VAROUT,,result_string,17,2,19,4,);
B(B_F,E_MOVE!,Instanz,11,4,17,8,N,?DEN?D?AENO?C);
B(B_VARIN,,'FALSE',9,6,11,8,);
B(B_VAROUT,,result_string,17,6,19,8,);
L(1,2,3,2);
L(5,2,11,2);
L(1,0,1,8);
L(6,2,6,6);
L(6,6,11,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY