PLC programming conventions

In the world of programming languages, there are several conventions that are observed depending on the tooling, focus and origin of the programming language, as well as the industry in which the application is used.

Based on the generally accepted programming guidelines (such as the MISRA C++ 2008 guidelines[...], the Java code conventions, the C# programming guide or PLCopen), the following section contains further programming information, which facilitates the creation of optimum, functional PLC program code.

Follow PLC programming conventions to achieve the following benefits:

New Beckhoff TwinCAT 3 PLC libraries, program samples and applications follow these "TwinCAT 3 PLC programming conventions".

Exceptions:

Classification

The PLC programming conventions are divided into the following chapters:

Within each chapter there are subchapters, which in turn contain a listing of topics.

The individual topics are classified as

You must implement topics classified as regulations. Recommendations should always be implemented, if possible, because they are advisable for several reasons.

Static code analysis

To reduce the risk of runtime errors, the code should at least be checked using the free variant of static code analysis (Static Analysis Light). This is included from TwinCAT 3.1 Build 4018 and contains a minimal scope for code review. With the help of the full range of functions of TE1200 PLC Static Analysis, a more detailed review of the programming conventions is also possible (see the following section).

Verification of programming conventions with the help of TE1200 PLC Static Analysis

TE1200 PLC Static Analysis offers the possibility of versatile checks of PLC program code. With the help of these functionalities, compliance with many regulations, recommendations and naming conventions of the PLC programming conventions can be checked.

Subchapter Programming

Where available, each regulation/recommendation is accompanied by the corresponding rule from Static Analysis that can be used to verify compliance with the regulation/recommendation.

See also:

Subchapter Naming conventions

If available, the ID of the Static Analysis configuration field is given for each naming convention, in which the respective recommended name prefix must be entered. This allows most of the recommended prefixes for POUs, DUTs, variables and instances to be checked by Static Analysis.

See also:

Pragmas and attributes

Also note the possibility to disable Static Analysis rules and naming conventions locally via pragma or attribute for checked locations where a specific rule/naming convention should no longer be reported (see also: chapter Pragmas and Attributes in TE1200 PLC Static Analysis). Ideally, you should comment on local deactivation with an appropriate explanation.

Download Static Analysis configuration file

1) Regulations and recommendations

The following link allows you to download a pre-built Static Analysis configuration file with the regulations [++] and recommendations [+] of the programming conventions enabled as rules. A violation of a regulation is output as an error after execution of the Static Analysis, a violation of a recommendation is classified as a warning.

TE1200_PrgConv_Rules.zip

2) Regulations, recommendations and naming conventions

The following link allows you to download a pre-built Static Analysis configuration file with the regulations [++], recommendations [+] and naming conventions of the programming conventions enabled as rules. A violation of a regulation or a naming convention is output as an error after execution of the Static Analysis, a violation of a recommendation is classified as a warning.

TE1200_PrgConv_RulesPlusNamingConv.zip

More rules

In addition to the rules that are explicitly mentioned within the following programming conventions, the TE1200 provides many other useful rules that can be used to detect careless errors or general programming errors at an early stage. These include, but are not limited to, the following rules.