Overloading

The operators convert values to other data types, explicitly specifying only a target data type and no initial data type (data type of the operand) ("overloaded conversion").

Overcharges are not part of IEC 61131-3. If you want to program strictly according to IEC61131-3, please use the operators of the <type> _TO_ <another type> scheme described in the following sections.

Syntax:

<variable name> := <TO operator> ( <operand> );
<operand> = <variable name> | <literal>

Operators:

TO___UXINT
TO___XINT
TO___XWORD
TO_BIT
TO_BYTE
TO_BOOL
TO_DATE
TO_DINT
TO_DT
TO_DWORD
TO_INT
TO_LDATE
TO_LDT
TO_LINT
TO_LREAL
TO_LTIME
TO_LTOD
TO_LWORD
TO_REAL
TO_SINT
TO_STRING
TO_TIME
TO_TOD
TO_UDINT
TO_UINT
TO_ULINT
TO_USINT
TO_WORD
TO_WSTRING

The rules for typed conversions also apply to overloading.

Overloading 1:

If the input value of a type conversion operator is outside the value range of the output data type, the result of the operation is not defined and depends on the platform. This is the case, for example, if the input value for the conversion from LREAL to UDINT is negative.

Samples:

Implementation language ST:

VAR
    nNumber1 : INT;
    nNumber2 : INT;
    fNumber3 : REAL     := 123.456;
    bTruth   : BOOL;
    sText1   : STRING;
    sText2   : STRING   := 'Hello World!';
    wsText   : WSTRING;
    dEvent   : DATE     := D#2019-9-3;
    nEvent   : UINT;
    nData    : __UXINT;
END_VAR
nNumber1 := TO_INT(4.22);          // Result: 4
nNumber2 := TO_INT(fNumber1);      // Result: 123
bTruth   := TO_BOOL(1);            // Result: TRUE
sText1   := TO_STRING(342);        // Result: '342'
wsText   := TO_WSTRING(sText2);    // Result: "Hello World!"
nEvent   := TO_UINT(dEvent);       // Result: 44288
dEvent   := TO___UXINT(nNumber2);  // Result: 123

See also: