Introduction
Data conversion instructions help change data from one type to another so the PLC can understand and use it correctly.
CONVERT_TYPE(Source, Destination) Example: INT_TO_REAL(MyInt, MyReal)
INT_TO_REAL(MyInt, MyReal)
REAL_TO_INT(MyReal, MyInt)
STRING_TO_INT(MyString, MyInt)
INT_TO_STRING(MyInt, MyString)
PROGRAM DataConversionExample VAR MyInt : INT := 123; MyReal : REAL; MyString : STRING(10); END_VAR // Convert integer to real INT_TO_REAL(MyInt, MyReal); // Convert integer to string INT_TO_STRING(MyInt, MyString); // Output results // (Assuming a debug or print function available) Print('Integer value: ' + TO_STRING(MyInt)); Print('Converted to real: ' + TO_STRING(MyReal)); Print('Converted to string: ' + MyString); END_PROGRAM
INT_VAR := 1234; REAL_VAR := INT_TO_REAL(INT_VAR); INT_CONV := REAL_TO_INT(REAL_VAR);
INT_CONV after execution?REAL_VAR := 12.7; INT_VAR := REAL_TO_INT(REAL_VAR); BOOL_VAR := INT_TO_BOOL(REAL_VAR);
Pass the test and this pattern moves unknown