Configuration and programming
CODESYS Safety programming guidelines > Language-specific programming guidelines
Keyword
STRING
REAL
Table 12: Complex data types
Keyword
ARRAY
STRUCT
Listing types
Subrange types
POINTER
The following rules must be followed when complex data types are used:
●
For complex data types we recommend using type declarations
●
Before each access to an array an explicit range check of the index should be carried out. In
the event of a violation that cannot be explained through the application, the control system
should be switched to a safe state.
4.4.3.7
Blocks
All IEC 61131-3 block types are suitable for creating safety applications:
●
PROGRAM
●
FUNCTION
●
FUNCTION_BLOCK
If blocks are used, the following programming guidelines should be followed:
●
Functions and function blocks must not affect global application states. This can be
achieved through write access to global data and by calling system components.
●
Explicit parameter transfer is preferable for calling programs and function blocks.
Bad:
Inst.Param1 := 7;
Inst.Param2 := 3;
Inst();
X := (Inst.Out1 AND A) OR B;
Good:
Inst(Param1 := 7, Param2 := 3, Out => Result);
X := (Result AND A) OR B;
●
All input parameters should be assigned for a call.
176
Suitable (yes / to a limited extent / no) (comment)
To a limited extent. (Technically possible, although it makes little sense due to the
lack of safety input/output devices.)
To a limited extent. (Prone to error through rounding errors, therefore no query
with EQ operator; check for invalid operations such as division by zero, square
root of a negative number, logarithm of a negative number.)
Suitable (yes / to a limited extent / no) (comment)
To a limited extent. (Only with explicit range check, otherwise too prone to errors.)
Yes
Yes
Yes
To a limited extent. (Recommended measures: no pointer arithmetic, range check,
new allocation of pointer value at the start of each cycle.)
DANGER!
The memory access using POINTERs (e.g., ADR function) is error-prone and is
generally not recommended. If used in safety applications, then the responsi-
bility for correct usage of these and related functions lies entirely with the organ-
ization and persons who use those functions in AC500-S safety PLC.
3ADR025091M0208, 12, en_US
2020/06/19