Naming Conventions

These rules propose a kind of Hungarian notation. It’s an identifier naming convention in which the name of a variable indicates its type. Hungarian notation provides the programmer with explicit knowledge of each variable’s data type. After the prefix the variable name should be formatted following the PascalCase rule.

Standard Data Types

These data types are originally from the IEC 61131-3 standard. The extra-wide data types (64-bit) are CODESYS specific extensions.

Data type

Range limits

Length

Prefix

Note

Lower limit

Upper limit

BOOL

TRUE

FALSE

x [1]

b

reserved

n

reserved

f

reserved

BYTE

8

by

Bitstring not intended for arithmetic operations

WORD

16

w

Bitstring not intended for arithmetic operations

DWORD

32

dw

Bitstring not intended for arithmetic operations

LWORD

64

lw

Bitstring not intended for arithmetic operations

__XWORD

32/64

xw

Bitstring not intended for arithmetic operations

__UXINT

32/64

uxi

__XINT

32/64

xi

SINT

-128

127

8

si

USINT

0

255

8

usi

INT

-32.768

32.767

16

i

UINT

0

65.535

16

ui

DINT

-2.147.483.648

2.147.483.647

32

di

UDINT

0

4.294.967.295

32

udi

LINT

-9.223.372.036.854.775.808

9.223.372.036.854.775.807

64

li

ULINT

0

18.446.744.073.709.551.615

64

uli

REAL

Single-precision IEEE 754

32

r

LREAL

Double-precision IEEE 754

64

lr

STRING

8 Bit Zeichen

s

WSTRING [2]

16 Bit Zeichen (UCS-2 Codierung)

ws

TIME

T#0

T#49d17h2m37s295ms

32

t

time base is a millisecond [ms]

LTIME

LTIME#0

LTIME#213503d23h34m33s709ms551us615ns

64

lt

time base is a nanosecond [ns]

TIME_OF_DAY / TOD

TOD#0:0:0.0

TOD#23:59:59.999

32

tod

time base is a millisecond [ms]

DATE_AND_TIME / DT

DT#1970-1-1-0:0:0

DT#2106-2-7-6:28:15

32

dt

time base is a second [s]

DATE

D#1970-1-1

D#2106-2-7

32

dat

time base is 86400 seconds per day [s]

ENUM

e<variable>

e

INTERFACE

I<Interface>

I

Interface Referenz

itf<instance>

itf

REFERENCE

r<prefix><variable>

r

ARRAY

a<prefix><variable>

a

POINTER

p<prefix><variable>

p

Scope Marker

In addition to the type related prefixes there are some scope related prefixes defined:

  • Constant Variables
    Such variables receive the prefix c
  • Global Variables
    Such variables receive the prefix g
  • Member Variables
    Such variables receive the prefix _

Some examples of possible combinations:

FUNCTION_BLOCK SendData
VAR
    _pabyTelegramData: POINTER TO ARRAY [0..7] OF BYTE;
END_VAR

VAR CONSTANT
    c_uiSyncID: UINT := 16#80;
END_VAR

VAR_GLOBAL
    g_iTest: INT;
END_VAR

VAR_GLOBAL CONSTANT
    gc_dwExample: DWORD := DWORD#16#12345678;
END_VAR

Safety Data Types

From the first part of the PLCopen document of the Technical Committee 5, titled “Concepts and Function Blocks for Safety Functions”, the following conventions for Safety-relevant variables as well as for Safety-relevant in-/outputs of functions and function blocks are taken and applied CODESYS-specifically. The main prefix “S_”, prescribed by PLCopen, is supplemented by the prefix of the base data type - taken from the table above - to the recommended CODESYS Safety prefix.

Data type

Range limits

Length

Prefix

Note

lower limit

upper limit

SAFEBOOL

TRUE

FALSE

S_x

SAFEBYTE

8

S_by

Bitstring not intended for arithmetic operations

SAFEWORD

16

S_w

Bitstring not intended for arithmetic operations

SAFEDWORD

32

S_dw

Bitstring not intended for arithmetic operations

SAFELWORD

64

S_lw

Bitstring not intended for arithmetic operations

SAFESINT

-128

127

8

S_si

SAFEUSINT

0

255

8

S_ui

SAFEINT

-32.768

32.767

16

S_i

SAFEUINT

0

65.535

16

S_ui

SAFEDINT

-2.147.483.648

2.147.483.647

32

S_di

SAFEUDINT

0

4.294.967.295

32

S_udi

SAFELINT

-9.223.372.036.854.775.808

9.223.372.036.854.775.807

64

S_li

SAFEULINT

0

18.446.744.073.709.551.615

64

S_uli

SAFETIME

T#0

T#49d17h2m37s295m

S_t

time base is a millisecond [ms]

Note

The CODESYS Professional Developer Edition provides a tool called Static Code Analysis. A rule set is included for automatically checking the naming convention described above.

Footnotes