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 |
||||
|
|
|
|
||
|
reserved |
||||
|
reserved |
||||
|
reserved |
||||
|
8 |
|
Bitstring not intended for arithmetic operations |
||
|
16 |
|
Bitstring not intended for arithmetic operations |
||
|
32 |
|
Bitstring not intended for arithmetic operations |
||
|
64 |
|
Bitstring not intended for arithmetic operations |
||
|
32/64 |
|
Bitstring not intended for arithmetic operations |
||
|
32/64 |
|
|||
|
32/64 |
|
|||
|
-128 |
127 |
8 |
|
|
|
0 |
255 |
8 |
|
|
|
-32.768 |
32.767 |
16 |
|
|
|
0 |
65.535 |
16 |
|
|
|
-2.147.483.648 |
2.147.483.647 |
32 |
|
|
|
0 |
4.294.967.295 |
32 |
|
|
|
-9.223.372.036.854.775.808 |
9.223.372.036.854.775.807 |
64 |
|
|
|
0 |
18.446.744.073.709.551.615 |
64 |
|
|
|
Single-precision IEEE 754 |
32 |
|
||
|
Double-precision IEEE 754 |
64 |
|
||
|
8 Bit Zeichen |
|
|||
|
16 Bit Zeichen (UCS-2 Codierung) |
|
|||
|
T#0 |
T#49d17h2m37s295ms |
32 |
|
time base is a millisecond [ms] |
|
LTIME#0 |
LTIME#213503d23h34m33s709ms551us615ns |
64 |
|
time base is a nanosecond [ns] |
|
TOD#0:0:0.0 |
TOD#23:59:59.999 |
32 |
|
time base is a millisecond [ms] |
|
DT#1970-1-1-0:0:0 |
DT#2106-2-7-6:28:15 |
32 |
|
time base is a second [s] |
|
D#1970-1-1 |
D#2106-2-7 |
32 |
|
time base is 86400 seconds per day [s] |
|
e<variable> |
|
|||
|
I<Interface> |
|
|||
Interface Referenz |
itf<instance> |
|
|||
|
r<prefix><variable> |
|
|||
|
a<prefix><variable> |
|
|||
|
p<prefix><variable> |
|
Scope Marker¶
In addition to the type related prefixes there are some scope related prefixes defined:
- Constant VariablesSuch variables receive the prefix
c
- Global VariablesSuch variables receive the prefix
g
- Member VariablesSuch 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
rule set
is
included for automatically checking the naming convention described above.Footnotes