This page will contain assorted parts of the main IEC_61131-3 page as I work on them

Data types

edit

A range of data types, referred to as elementary data types, are defined within IEC 1131-3. These can form the basis of user-defined data types, referred to as derived data types.

Elementary data types

edit

Elementary data types are classified as bit strings, integers, real numbers, times, and dates/times of day.

Bit Strings represent groups of on/off values.

Data type Size
BIT 1 bit
BYTE 8 bit (1 byte)
WORD 16 bit (2 byte)
DWORD 32 bit (4 byte)
LWORD 64 bit (8 byte)

Integers represent whole numbers. The table below lists signed integer types only, the equivalent unsigned types have a U prefixed to the name.

Data type Size
SINT (signed short integer) 1 byte
INT (signed integer) 2 byte
DINT (signed double integer) 4 byte
LINT (signed long integer) 8 byte

Real numbers represent floating point numbers in IEC 60559 format, which is the same as IEEE 754-2008.

Data type Size
REAL 4 byte
LREAL 8 byte

Time values (the TIME data type) represent a duration, for example for use with calculations related to timers.

Date and time of day values represent a specific moment in time. The data types in this category are DATE, TIME_OF_DAY, and DATE_AND_TIME (which is a combination of the previous two).

Escape sequences
Escape sequence Produces
$$ $
$' '
$L linefeed
$N newline
$P page (form feed)
$R return
$T tab
$xx hex value

Strings contain character strings and are typed as literals by surrounding the value with single quotes. Escaped characters are preceded by a dollar sign (see the Escape sequences table to the right). There are two types of string available: STRING and WSTRING for single-byte and multi-byte character strings respectively.

  • Arrays - multiple values stored in the same variable.
  • Sub Ranges - puts limits on value i.e., (4-20) for current

Derived data types

edit

Type derived from one of the above types.

  • TYPE - single type
  • STRUCT - composite of several variables and types.

Data type hierarchy

edit

A series of generic data types form a hierarchy in which the elementary and derived types are placed. These generic data types may be used in the specification of inputs and outputs for standard functions and function blocks. They cannot be used in user-declared POUs. The purpose of these data types is to allow a function to accept a set of related data types if there is no need for a specific type. For example, the SHR function will accept any of the data types below ANY_BIT in the hierarchy for its IN parameter.

  • ANY
    • ANY_DERIVED
    • ANY_ELEMENTARY
      • ANY_MAGNITUDE
        • ANY_NUM
          • ANY_REAL
            • REAL, LREAL
          • ANY_INT
            • SINT, INT, DINT, LINT, USINT, UINT, UDINT, ULINT
        • TIME
      • ANY_BIT
        • BOOL, BYTE, WORD, DWORD, LWORD
      • ANY_STRING
        • STRING, WSTRING
      • ANY_DATE
        • DATE_AND_TIME (DT), DATE, TIME_OF_DAY (TOD)