



NOTICE

String manipulation when converting to STRING
or WSTRING
When converting the type to STRING
or WSTRING
, the typed value is left-aligned as a character string and truncated if it is too
long. Therefore, declare the return variable for the type conversion operators <>_TO_STRING
and <>_TO_WSTRING
long enough that the character string has enough space without any manipulation.
The operators convert a Boolean value into the specified data types and return a type-converted value.
Call syntax
<variable name> := <BOOL to operator> ( <operand> ); <operand> = <variable name> | <literal>
Operators
BOOL_TO___UXINT BOOL_TO___XINT BOOL_TO___XWORD BOOL_TO_BIT BOOL_TO_BYTE BOOL_TO_DATE BOOL_TO_DINT BOOL_TO_DT BOOL_TO_DWORD BOOL_TO_INT BOOL_TO_LDATE BOOL_TO_LDT BOOL_TO_LINT BOOL_TO_LREAL BOOL_TO_LTIME BOOL_TO_LTOD BOOL_TO_LWORD BOOL_TO_REAL BOOL_TO_SINT BOOL_TO_STRING BOOL_TO_TIME BOOL_TO_TOD BOOL_TO_UDINT BOOL_TO_UINT BOOL_TO_ULINT BOOL_TO_USINT BOOL_TO_WORD BOOL_TO_WSTRING
When the operand value is TRUE
, the following typed values are returned:
-
BOOL_TO_DATE
:D#1970-1-1 // The zeroth bit is set, but does not effect the display.
-
BOOL_TO_DT
:DT#1970-01-01-0:0:1
-
BOOL_TO_LTIME
:LTIME#1NS
-
BOOL_TO_REAL
:'1'
-
BOOL_TO_STRING
:'TRUE'
-
BOOL_TO_TOD
:TOD#0:0:0.001
-
BOOL_TO_TIME
:T#1MS
-
BOOL_TO_WSTRING
:"TRUE"
When the operand value is FALSE
, the following typed values are returned:
-
BOOL_TO_DATE
:D#1970-1-1
-
BOOL_TO_DT
:DT#1970-01-01-00:00:00
-
BOOL_TO_LTIME
:LTIME#0NS
-
BOOL_TO_REAL
:'0.0'
-
BOOL_TO_STRING
:'FALSE'
-
BOOL_TO_TOD
:TOD#0:0:0
-
BOOL_TO_TIME
:T#0MS
-
BOOL_TO_WSTRING
:"FALSE"
Examples
ST implementation language
FUNCTION_BLOCK FB_ConvertFromBool VAR VAR uxiReturn_1: __UXINT; uxiReturn_10: __UXINT; iReturn_2: __XINT; iReturn_20: __XINT; xwReturn_3: __XWORD; xwReturn_30: __XWORD; bitReturn_4: BOOL; bitReturn_40: BOOL; bReturn_6: BYTE; bReturn_60: BYTE; dateReturn_7: DATE; dateReturn_70: DATE; dtReturn_8: DATE_AND_TIME; dtReturn_80: DATE_AND_TIME; diReturn_9: DINT; diReturn_90: DINT; dtReturn_10: DATE_AND_TIME; dtReturn_100: DATE_AND_TIME; dwReturn_11: DWORD; dwReturn_110: DWORD; iReturn_12: INT; iReturn_120: INT; liReturn_13: LINT; liReturn_130: LINT; lrReturn_14: LREAL; lrReturn_140: LREAL; lwReturn_15: LWORD; lwReturn_150: LWORD; rReturn_16: REAL; rReturn_160: REAL; siReturn_17: SINT; siReturn_170: SINT; sReturn_18: STRING; sReturn_180: STRING; todReturn_19: TIME_OF_DAY; todReturn_190: TIME_OF_DAY; timReturn_20: TIME; timReturn_200: TIME; todReturn_21: TIME_OF_DAY; todReturn_210: TIME_OF_DAY; udiReturn_22: UDINT; udiReturn_220: UDINT; uiReturn_23: UINT; uiReturn_230: UINT; uliReturn_24: ULINT; uliReturn_240: ULINT; usiReturn_25: USINT; usiReturn_250: USINT; wReturn_26: WORD; wReturn_260: WORD; wsReturn_27: WSTRING; wsReturn_270: WSTRING; END_VAR // Return value of operand = TRUE or FALSE uxiReturn_1 := BOOL_TO___UXINT(TRUE); uxiReturn_10 := BOOL_TO___UXINT(FALSE); iReturn_2 := BOOL_TO___XINT(TRUE); iReturn_20 := BOOL_TO___XINT(FALSE); xwReturn_3 := BOOL_TO___XWORD(TRUE); xwReturn_30 := BOOL_TO___XWORD(FALSE); bitReturn_4 := BOOL_TO_BIT(TRUE); bitReturn_40 := BOOL_TO_BIT(FALSE); bReturn_6 := BOOL_TO_BYTE(TRUE); bReturn_60 := BOOL_TO_BYTE(FALSE); dateReturn_7 := BOOL_TO_DATE(TRUE); dateReturn_70 := BOOL_TO_DATE(FALSE); dtReturn_8 := BOOL_TO_DT(TRUE); dtReturn_80 := BOOL_TO_DT(FALSE); diReturn_9 := BOOL_TO_DINT(TRUE); diReturn_90 := BOOL_TO_DINT(FALSE); dwReturn_11 := BOOL_TO_DWORD(TRUE); dwReturn_110 := BOOL_TO_DWORD(FALSE); iReturn_12 := BOOL_TO_INT(TRUE); iReturn_120 := BOOL_TO_INT(FALSE); liReturn_13 := BOOL_TO_LINT(TRUE); liReturn_130 := BOOL_TO_LINT(FALSE); lrReturn_14 := BOOL_TO_LREAL(TRUE); lrReturn_140 := BOOL_TO_LREAL(FALSE); lwReturn_15 := BOOL_TO_LWORD(TRUE); lwReturn_150 := BOOL_TO_LWORD(FALSE); rReturn_16 := BOOL_TO_REAL(TRUE); rReturn_160 := BOOL_TO_REAL(FALSE); siReturn_17 := BOOL_TO_SINT(TRUE); siReturn_170 := BOOL_TO_SINT(FALSE); sReturn_18 := BOOL_TO_STRING(TRUE); sReturn_180 := BOOL_TO_STRING(FALSE); timReturn_20 := BOOL_TO_TIME(TRUE); timReturn_200 := BOOL_TO_TIME(FALSE); todReturn_21 := BOOL_TO_TOD(TRUE); todReturn_210 := BOOL_TO_TOD(FALSE); udiReturn_22 := BOOL_TO_UDINT(TRUE); udiReturn_220 := BOOL_TO_UDINT(FALSE); uiReturn_23 := BOOL_TO_UINT(TRUE); uiReturn_230 := BOOL_TO_UINT(FALSE); uliReturn_24 := BOOL_TO_ULINT(TRUE); uliReturn_240 := BOOL_TO_ULINT(FALSE); usiReturn_25 := BOOL_TO_USINT(TRUE); usiReturn_250 := BOOL_TO_USINT(FALSE); wReturn_26 := BOOL_TO_WORD(TRUE); wReturn_260 := BOOL_TO_WORD(FALSE); wsReturn_27 := BOOL_TO_WSTRING(TRUE); wsReturn_270 := BOOL_TO_WSTRING(FALSE);

FBD implementation language
