Identifiers are defined:
at the declaration of variables (variable name)
at the declaration of user-defined data types
at the creation of POUs (functions, function blocks, programs)
In addition to the general items to be considered when defining an identifier (refer to chapter General Information on variables declaration), consider the following in order to make the naming as unique as possible:
For naming variables in applications and libraries, follow the Hungarian notation as far as possible.
Find for each variable a meaningful, short description. This is used as the base name. Use a capital letter for each word of the base name. Use small letters for the rest (example: FileSize
).
Data Type |
Lower Limit |
Upper Limit |
Information Content |
Prefix |
Comment |
---|---|---|---|---|---|
BOOL |
FALSE |
TRUE |
1 bit |
|
– |
|
reserved |
||||
BYTE |
– |
– |
8 bit |
|
bit string, not for arithmetic operations |
WORD |
– |
– |
16 bit |
|
bit string, not for arithmetic operations |
DWORD |
– |
– |
32 bit |
|
bit string, not for arithmetic operations |
LWORD |
– |
– |
64 bit |
|
bit string, not for arithmetic operations |
SINT |
–128 |
127 |
8 bit |
|
arithmetic integer data type, 8-bit |
USINT |
0 |
255 |
8 bit |
|
arithmetic integer data type, 8-bit |
INT |
–32,768 |
32,767 |
16 bit |
|
arithmetic integer data type, 16-bit |
UINT |
0 |
65,535 |
16 bit |
|
arithmetic integer data type, 16-bit |
DINT |
–2,147,483,648 |
2,147,483,647 |
32 bit |
|
arithmetic integer data type, 32-bit |
UDINT |
0 |
4,294,967,295 |
32 bit |
|
arithmetic integer data type, 32-bit |
LINT |
–263 |
263-1 |
64 bit |
|
arithmetic integer data type, 64-bit |
ULINT |
0 |
264-1 |
64 bit |
|
arithmetic integer data type, 64-bit |
REAL |
– |
– |
32 bit |
|
arithmetic floating-point data type, 32-bit |
LREAL |
– |
– |
64 bit |
|
arithmetic floating-point data type, 64-bit |
STRING |
– |
– |
– |
|
Single-byte character string of variable length (default setting: 80 characters) |
WSTRING |
– |
– |
– |
|
Double-byte character string of variable length (default setting: 80 characters) |
TIME |
– |
– |
– |
|
time duration, 32-bit |
LTIME |
– |
– |
– |
|
time duration, 64-bit |
|
– |
– |
– |
|
time of day, 32-bit |
|
– |
– |
– |
|
time of day, 64-bit |
|
– |
– |
– |
|
date and time |
|
– |
– |
– |
|
– |
DATE |
– |
– |
– |
|
calendar date |
LDATE |
– |
– |
– |
|
calendar date |
Enumeration |
– |
– |
– |
|
– |
POINTER |
– |
– |
– |
|
– |
ARRAY |
– |
– |
– |
|
– |
Structure |
– |
– |
– |
|
– |
Function block |
– |
– |
– |
|
– |
Interface |
– |
– |
– |
|
– |
Union |
– |
– |
– |
|
– |
* intentionally for boolean variables x is chosen as a prefix in order to differentiate from BYTE and also in order to accommodate the perception of an IEC programmer (see addressing |
Simple declaration
Examples for simple declarations:
bySubIndex: BYTE;
sFileName: STRING;
udiCounter: UDINT;
Nested declaration
Example for a nested declaration where the prefixes are attached to each other in the order of the declarations:
pabyTelegramData: POINTER TO ARRAY [0..7] OF BYTE;
Function block instances and variables of user-defined data types
Function block instances and variables of user-defined data types get a shortcut for the function block or the data type name as a prefix (for example: stSDO
).
Example
stSDOReceivedTelegram: ST_SDOTelegram;
TYPE ST_SDOTelegram :
STRUCT
wIndex:WORD;
bySubIndex:BYTE;
byLen:BYTE;
aby: ARRAY [0..3] OF BYTE;
END_STRUCT
END_TYPE
Local constants
Local constants (c) start with prefix c
and an attached underscore, followed by the type prefix and the variable name.
Example
VAR CONSTANT
c_uiSyncID: UINT := 16#80;
END_VAR
Global variables and global constants
Global variables are prefixed by G_
(g_
) and global constants are prefixed by Gc_
(gc_
).
Example
VAR_GLOBAL
G_iTest: INT;
END_VAR
VAR_GLOBAL CONSTANT
Gc_dwExample: DWORD;
END_VAR
Structure
Basically, refer to the above description for variable names. Use the library namespace as prefix, when accessing a variable in your application code.
Example
G_iTest: INT; (declaration)
CAN.G_iTest (implementation, call in an application program
Structure
The name of each structure data type consists of the corresponding type prefix (also refer to POU Prefix) and a short, meaningful name (for example, ET_Day
) of the structure.
Example (in library with namespace CAL
):
TYPE ET_Day :(
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY);
Declaration:
etToday: CAL.ET_Day;
Use in application:
IF etToday = CAL.ET_Day.MONDAY THEN
The names of functions, function blocks, and programs consist of the corresponding type prefix (also refer to POU Prefix) and a short, meaningful name of the POU (for example, FB_SendTelegram
). As with variables, the first letter of a word of the POU name should be an uppercase letter whereas the others should be lowercase letters. For example, compose the name of the POU of a verb and a substantive to clearly indicate the operation of the function block.
Example
FUNCTION_BLOCK FB_SendTelegram
In the declaration part, provide a short description of the POU as a comment. Further on, the inputs and outputs should be provided with comments. In case of function blocks, insert the associated prefix for set-up instances directly after the name.
Actions
Actions do not get a prefix. Only those actions that are to be called only internally that is by the POU itself, start with prv_
.
Structure
For creating method names, the same rules apply as for actions. Enter comments for possible inputs of a method. Add a short description of a method to its declaration. Start interface names with prefix IF_
(I
); for example, IF_CANDevice
.