USINT_TO_LREALEX

USINT_TO_LREALEX 1:

In TwinCAT 2 auf ARM-Plattform wird die Konvertierung der vorzeichenlosen Zahlen in Fließkommezahlen von Typ: LREAL nicht unterstützt. Vorzeichenlose Zahlen mit einem gesetzten höchstwertigen Bit werden möglicherweise implizit in negative Fließkommazahlen konvertiert. Die hier beschriebene Funktion erlaubt in TwinCAT 2 eine explizite Konvertierung  vom Typ USINT in eine positive Fließkommazahl vom Typ LREAL (auch wenn das höchstwertige Bit gesetzt wurde und ohne Compiler-Warnung). In TwinCAT 3 werden vorzeichnlose Zahlen von Typ USINT immer (implizit und explizit) in eine positive Fließkommazahl konvertiert.

FUNCTION USINT_TO_LREALEX : LREAL

VAR_INPUT
    in      : USINT;
END_VAR

in: Die zu konvertierende Zahl.

Beispiel:

PROGRAM MAIN
VAR
    nUsint : USINT := 16#FF;
    fLreal : LREAL := 0.0;
END_VAR

fLreal value

Tc2.x ARM

Tc2.x X86

Tc3.x ARM, X86, X64

fLreal := nUsint

+255, Warning 1105*

+255

+255

fLreal := USINT_TO_LREAL( nUsint )

+255, Warning 1105*

+255

+255

fLreal := USINT#16#FF

+255, Warning 1105*

+255

+255

fLreal := 16#FF

+255

+255

+255

fLreal := USINT_TO_LREALEX( nUsint )

+255

+255

+255

fLreal := USINT_TO_LREALEX( USINT#16#FF )

+255

+255

+255

fLreal := USINT_TO_LREALEX( 16#FF )

+255

+255

+255

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

Voraussetzungen

Entwicklungsumgebung

Zielplattform

Einzubindende SPS Bibliotheken

TwinCAT v2.11.0 Build >= 2255

PC or CX (x86, ARM)

TcUtilities.Lib