Skip to main content

Data types

In CODESYS Safety Extension, a distinction is made between non-safety-oriented data (the IEC standard data types) and safety-oriented data (with the prefix SAFE). When mapping input and output channels, those of safe field devices always have the type SAFExxx and those of non-safe field devices always have a non-SAFE type. The checking of the PLCopen linking rules for SAFEBOOL data and analogous linking rules for the other SAFEXXX data types is part of the check for error conditions in the programming system.

Table 7. IEC standard data types

Data Type

Bit Length

Value Range

Description

BOOL

1

0,1

0 corresponds to FALSE

1 corresponds to TRUE

DINT

32

-2,147,483,648 … 2,147,483,647

INT

16

-32,768 … 32,767

TIME

32

0 … 2,147,483,647 s

Duration

WORD

16

0 … 65,535

(16#00 … 16#FFFF)



Tip

The BYTE, DWORD, SAFEBYTE, and SAFEDWORD data types can appear only in the logical I/Os and can be used in Extended level programs as channel variables (category: global variables, declaration as VAR_EXTERNAL).

Table 8. SAFE data types

Data Type

Bit Length

Value Range

Description

SAFEBOOL

1

0,1

0 corresponds to FALSE

1 corresponds to TRUE

SAFEDINT

32

-2,147,483,648 … 2,147,483,647

SAFEINT

16

-32,768 … 32,767

SAFETIME

32

0 … 2,147,483,647 s

SAFEWORD

16

0 … 65,535

(16#00 … 16#FFFF)



Tip

The REAL data type is not permissible in Safety programming. If it is nevertheless used, this causes a translation error.

User-defined data types

The User-defined Types data type category contains function blocks of the safety application and the libraries. This category can be selected in the Input Assistant, which is opened in the Insert Variable Declaration dialog by clicking the SafetyEllipsesButton.png button. In the case of already declared variables the Input Assistant of the data type is opened as follows:

  1. In the declaration window, select the type cell of the corresponding variable.

  2. In the list box, click the ... symbol.

Figure 47. Declaration view: Drop-down list of the type
Declaration view: Drop-down list of the type


General rules for typification

INT polymorphism

A value of the type INT or SAFEINT always has the type DINT or SAFEDINT as well. The linkage of INT and DINT leads to a DINT value (int + dint has the type DINT).

SAFE polymorphism

A value of the type SAFEXXX always has the type XXX as well; i.e. a value of high integrity can always also be used as a value of low integrity. This means that the conversion function SAFEBOOL_TO_BOOL mentioned in PLCopen is implicit in CODESYS Safety Extension and is not explicitly written.

SAFE constants

Constants are always values of the highest integrity (i.e. SAFEXXX). Due to the SAFE polymorphism they can still serve as normal values. One thus saves having two different kinds of values (safebool#1 as well as bool#1).bool#1 is SAFEBOOL (and BOOL); the same applies to the other literal constants.

SAFE downgrade

The general rule for linking values is as follows: if and only if all operands have a SAFE type, then the result has a SAFE type.

Exception: SAFEBOOL AND BOOL have the value SAFEBOOL.