WORD_TO_LREALEX

WORD_TO_LREALEX 1:

The conversion of unsigned numbers into floating point numbers of the type LREAL is not supported in TwinCAT 2 on the ARM platform. Unsigned numbers with the highest significant bit set may possibly be implicitly converted into negative floating point numbers. The function described here allows the explicit conversion of the type WORD into a positive floating point number of the type LREAL in TwinCAT 2 (even if the highest significant bit was set and without compiler warning). Unsigned numbers of the type WORD are always (implicitly and explicitly) converted into positive floating point numbers in TwinCAT3.

FUNCTION WORD_TO_LREALEX : LREAL

VAR_INPUT
    in      : WORD;
END_VAR

in: Number to be converted.

Sample:

PROGRAM MAIN
VAR
    nWord  : WORD := 16#FFFF;
    fLreal : LREAL := 0.0;
END_VAR

fLreal value

Tc2.x ARM

Tc2.x X86

Tc3.x ARM, X86, X64

fLreal := nWord

+65535, Warning 1105*

+65535

+65535

fLreal := WORD_TO_LREAL( nUsint )

+65535, Warning 1105*

+65535

+65535

fLreal := WORD16#FFFF

+65535, Warning 1105*

+65535

+65535

fLreal := 16#FFFF

+65535

+65535

+65535

fLreal := WORD_TO_LREALEX( nWord )

+65535

+65535

+65535

fLreal := WORD_TO_LREALEX( WORD#16#FFFF )

+65535

+65535

+65535

fLreal := WORD_TO_LREALEX( 16#FFFF )

+65535

+65535

+65535

* Conversion of unsigned integer to LREAL is not supported. The value is used as signed instead.

Requirements

Development environment

Target platform

PLC libraries to be linked

TwinCAT v2.11.0 Build >= 2255

PC or CX (x86, ARM)

TcUtilities.Lib

 

H