TO_LREAL block

Short summary

Name

TO_LREAL

→POU type

→function

Category

IEC-block, Convert, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg more possible than defined in IEC-standard and
images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/error.svg currently restricted ;
see "
Explicit conversion according to IEC-standard"

Graphical interface

images/download/thumbnails/414781123/TO_LREAL-version-1-modificationdate-1534929837010-api-v2.png

Available since

  • version 1.0.0 (for logi.CAD 3) – initial variant

  • version 1.90.0 (for logi.CAD 3) – enhancement: TIME_OF_DAY for IN

  • version 3.2.0 (for library Standard) – enhancement: STRING and CHAR for IN, internal error diagnostic

Functionality

The blocks serves for explicitly converting the value connected to input IN into a value of data type LREAL.

If the connected value is within the range of values overlapping for the data type of the input and for the result value LREAL, the blocks returns this value.

Observe:

  • If a value of data type STRING is connected to the input and this value is a valid real literal (see the following table for examples), the value is converted accordingly. In this case, the output ENO is set to value TRUE .
    In case of other values, the block returns the value 0.0. In this case, the output ENO is set to value FALSE . Special case: If the connected value starts with a valid real literal and other characters follow (egB. ' 3.14159_26' , STRING#'1.5 E10' , '-INFxxx' ) , the block returns the starting value as it is supported (hence: 3.14159 , 1.5 , -INF ) and the output ENO is set to value FALSE.

    Description

    Examples for values of data type STRING that correspond to a valid real literals

    Real literal

    '0', '0.0', '0.4560', '3.1415926', '-123456789',
    STRING#'0', STRING#'0.0', STRING#'0.4560', STRING#'3.1415926', STRING#'-123456789'

    Real literal with exponent

    '-1.34E-12', '-1.34e-12', '1.0E+6', '1.0e+6, 1E+6', '1.234E6', '1.234e6',STRING#'-1.34E-12', STRING#'-1.34e-12', STRING#'1.0E+6', STRING#'1.0e+6, STRING#1E+6', STRING#'1.234E6', STRING#'1.234e6',' 987e-3', ' +2.5E30',STRING#' 987e-3', STRING#' +2.5E30'

    "Not a Number" or infinite

    'Nan', 'INF', '-INF'

    Typed real literals (specifying the type REAL or LREAL) are invalid real literals.
    Examples for values of data type STRING that correspond to an in valid real literal : 'REAL#0.0' or 'LREAL#0.0'

  • If a value of data type CHAR is connected to the input and this value is a valid real literal (e.g. '0', CHAR#'9'), the value is converted accordingly (hence: 0.0, 9.0). In this case, the output ENO is set to value TRUE .
    In case of other values (e.g. '+', CHAR#A) , the block returns the value 0.0. In this case, the output ENO is set to value FALSE.

Explicit conversion according to IEC-standard

The IEC-standard defines an explicit conversion of the following data types to LREAL:

REAL, LINT, DINT, INT, SINT, ULINT, UDINT, UINT, USINT, LWORD

The IEC-standard (Edition 3.0) defines a binary transfer for the following data types of the input . But contrary to this, the appropriate value is converted according to the IEC-standard (Edition 2.0).

LWORD

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

REAL, LREAL, USINT, UINT, UDINT, ULINT, SINT, INT, DINT, LINT, TIME, BOOL, BYTE, WORD, DWORD, LWORD, STRING, CHAR or TIME_OF_DAY

value to be converted

Return value:

LREAL


Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

Internal error diagnostic for block

The block checks the value connected to the input. The output ENO of the block is set to value FALSE (or an equivalent) in the following cases:

  • A STRING value contains an invalid character. (The value returned by the block depends on the position of the invalid characters. See the description under "Functionality" above.)

  • A CHAR value contains an invalid character. (Moreover for this case, the block returns the value 0.0.)

Example for usage within ST-editor

PROGRAM Test
VAR
result : LREAL;
END_VAR
result := TO_LREAL(IN := SINT#12); (* The variable 'result' evaluates to value '12.0 of LREAL. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.