beckhoff TwinCAT 2 PLC Control — 10.5.9.4 TO_STRING conversions

Appendix Example in ST: bOFF AT%QX10.1 : BOOL; iBitAdr : BYTE; iBitAdr := BITADR( bOFF ); (* returns 81 *) 10.5.9 Type Converting Operators 10.5.9.1 BOOL_TO conversions Converting from the BOOL type variable to a different type: For number type variables the result is 1 when the operand is TRUE and 0 when the operand is FALSE. The result is "TRUE" or "FALSE" respectively for STRING type variables. Examples in ST:

i:=BOOL_TO_INT(TRUE); (* Result is 1 *) str:=BOOL_TO_STRING(TRUE); (* Result is 'TRUE' *) t:=BOOL_TO_TIME(TRUE); (* Result is T#1ms *) tof:=BOOL_TO_TOD(TRUE); (* Result is TOD#00:00:00.001 *) dat:=BOOL_TO_DATE(FALSE); (* Result is D#1970-01-01 *) dandt:=BOOL_TO_DT(TRUE); (* Result is DT#1970-01-01-00:00:01 *) 10.5.9.2 TO_BOOL conversions Conversion from another variable type to BOOL:The result is TRUE when the operand is not equal to 0. The result is FALSE when the operand is equal to 0. The result is true for STRING type variables when the operand is "TRUE", otherwise the result is FALSE. Examples in ST:

b := BYTE_TO_BOOL(2#11010101); (* Result is TRUE *) b := INT_TO_BOOL(0); (* Result is FALSE *) b := TIME_TO_BOOL(T#5ms); (* Result is TRUE *) b := STRING_TO_BOOL('TRUE'); (* Result is TRUE *) 10.5.9.3 STRING_TO conversions Converting from the variable type STRING to a different type: The operand from the STRING type variable must contain a value that is valid in the target variable type, otherwise the result will be 0. Examples in ST: b :=STRING_TO_BOOL('TRUE'); (* Result is TRUE *) w :=STRING_TO_WORD('abc34'); (* Result is 0 *) t :=STRING_TO_TIME('T#127ms'); (* Result is T#127ms *) 10.5.9.4 TO_STRING conversions Conversions from different type to STRING. Examples in ST:

TwinCAT 2 PLC Control 326 Version: 1.0