Program structure

Topics:

  1. Object-orientated programming [+]
  2. Structure of program elements [+]
  3. Structure of text blocks [+]
  4. Comments [+]

Object-orientated programming

To take advantage of object-oriented programming, you should structure the PLC program in classes. Instead of a large number of function blocks, a selection of classes used with appropriate methods is used.

The benefits and user-friendliness of an object-oriented implementation should be assessed on an individual basis.

Structure of program elements

See: Structure of program elements

Structure of text blocks

See: Structure of text blocks

Comments

Avoid unnecessary comments as much as possible. Instead, the naming and program code should be self-explanatory, if possible, so that no further commenting is necessary. If a comment is required because it contributes significantly to understanding (e.g. units), note the following points:

Comments are intended to describe the use, benefits and content of program elements and their components and thus make programs quickly and easily understandable. They show up when viewing the program element and are also displayed in the form of a tooltip.

Comment place

If a comment is provided, it is located in the following places:

Comment operator

Sample

// This function block represents an axis
FUNCTION_BLOCK FB_Axis
VAR_INPUT
     bExecution    : BOOL;     // Rising edge starts the execution process
END_VAR
VAR_OUTPUT
     bError        : BOOL;     // Is TRUE when an error occurred during execution
     nErrorID      : UDINT;    // Error ID of execution process
END_VAR
Program structure 1: