TO_DINT block

Short summary

Name

TO_DINT

→POU type

→function

Category

IEC-block, Convert, block with internal error diagnostic

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg implementer-specific realization; see " Functionality "

and

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

Graphical interface

images/download/thumbnails/414781093/TO_DINT-version-1-modificationdate-1534929722192-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.0.1 (for library Standard) – enhancement: STRING (with character _) and CHAR for IN, internal error diagnostic

  • version 3.1.0 (for library Standard) – For inputs of data type REAL, the optimized float variant of the C-runtime is used. Compared to previous versions , it is possible that (marginal) other results are returned within the threshold range of the block.

Functionality

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

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

Implementer-specific realization

The IEC-standard defines that it is an error when the connected value is not within the range of values overlapping for the data type of the input and for the data type of the return value as well as that the behavior in the case of such an error is implementer specific. The general behavior of the conversion blocks in logi.CAD 3 is as follows: The non-overlapping value range is not considered to be an error. Moreover, the following is valid:

  • If the connected value is of a data type not being REAL or LREAL: T he higher bytes (= bytes not within the range of values) are truncated.

  • If the connected value is of the data type REAL or LREAL: The return value of the block depends on the compiler and target system (see "Effects of the compiler settings on the execution" for details).

Observe as well:

  • If a REAL value with more than 6 digits before the decimal point is converted, the result might be inexact. Example: For REAL#4_294_967_290.0, the block returns the value 0. The reason is the number of significant digits of REAL (details: see "Supported data types (in ST) " the note 3 and the note 4 after the table).

  • If converting data types to the TIME data type and vice versa, the conversion is always based on seconds.

  • If a value of data type STRING is connected to the input, the value is converted to a decimal value (base: 10, allowed digits: 0 to 9) and then this decimal value is converted to a value according to the target data type . The following special cases might occur (see under "Example for usage within ST-editor" ) :

    • If the value starts with the character + , with blanks or tabs (= so-called whitespace) and the value is within the range of values for the target data type, the value is converted to a positive decimal value (without these characters). In this case, the output ENO is set to value TRUE .
      Details on this conversion: The character + as prefix for the value is ignored, blanks and tabs (= so-called whitespace) are ignored as well.

    • If the value starts with the character and the value is within the range of values for the target data type, the value is converted to a negative decimal value. In this case, the output ENO is set to value TRUE as well.

    • If the value contains an invalid character, the block returns the value 0. In this case, the output ENO is set to value FALSE .

      Valid characters

      invalid characters

      digits (base: 10, numbers: 0 to 9)
      Example for value with valid character: '7'

      other characters such as letters
      Example for value with invalid character: '12a3', 'a123'

      one character + or as a prefix of the value
      Example for value with valid character: +2 or –3

      repetitions of + or at the beginning of the value, the character + or within the value
      Example for value with invalid character: '++1', '1–3'

      single underscore characters _ within the value
      Example for value with valid character: 1_2 or 1_2_3

      underscore character _ at the beginning or the end of the value, several characters _ behind one another
      Example for value with invalid character: _12, 12_ or 1__2

    • If the STRING value to be converted exceeds the upper limit of the target data type, the block returns the upper limit of the target data type. In this case, the output ENO is set to value FALSE as well.

    • If the STRING value to be converted is below the lower limit of the target data type, the block returns the lower limit of the target data type. In this case, the output ENO is set to value FALSE as well.

  • If a value of data type CHAR is connected to the input, the conversion is analogous to a STRING value. But different to the STRING conversion, the CHAR conversion supports single digits digits 0 to 9 only. For all other characters (letters, the characters +, - and _), the block returns the value 0 and the output ENO is set to value FALSE .

It is possible that the block does not behave as expected when there is a nested usage together with other blocks. This behavior is caused due to the typing using to the lowest common data type (see under "Typing of expressions" for details).

Explicit conversion according to IEC-standard

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

LREAL, REAL, LINT, INT, SINT, ULINT, UDINT, UINT, USINT, LWORD, DWORD, WORD, BYTE, BOOL

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 :

DINT


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

See:

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. (Moreover for this case, the block returns the value 0.)

  • A STRING value exceeds the upper limit of the target data type. (Moreover for this case, the block returns the upper limit of the target data type.)

  • A STRING value is below the lower limit of the target data type. (Moreover for this case, the block returns the lower limit of the target data type.)

  • The CHAR value is an invalid character. (Moreover for this case, the block returns the value 0.)

Example for usage within ST-editor

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

See under "TO_INT block" for appropriate examples with STRING values. However, because of the different target data type of this block, a different upper/lower limit is valid for this block (see "Supported data types (in ST)" for the upper and lower limit per data type).

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.