Overview

With the integration of the static code analysis, a further programming tool is available in TwinCAT 3.1 that supports the PLC software development process. The tool is integrated in TwinCAT 3 PLC and can be seen as a supplement to the compiler.

Function overview

Static Analysis implements more than 100 coding rules, some of which can be parameterized and combined to create individual rule sets. The rule sets defined in "PLCopen Coding Guidelines" are taken into account in some rules. For example, it can report if a pointer variable has not been checked for nonzero before dereferencing. As a result, the user's attention is drawn to possibly inadvertent and erroneous implementations, so that these program points can be optimized at an early stage.

You can also define a naming convention for each possible data type, which is then checked for compliance. In addition, over 20 metrics are available to analyze and characterize the underlying source code. When calculated regularly, the metrics can indicate negative trends and deviations from quality targets. The key figures therefore represent an indicator for assessing software quality. For example, the tabular output contains metrics for the number of statements or the proportion of comments.

The Static Analysis can be triggered manually or performed automatically during the code generation. TwinCAT outputs the result of the analysis, i.e. messages regarding deviations from the specifications and rules, in the message window. In the PLC project properties you can define the parameters to be checked in detail. When configuring the rules, you can also define whether a rule violation is to be output as an error or a warning. You can use pragma statements to exclude particular parts of the code from the check. For errors reported by Static Analysis based on precompile information, there is support in the ST Editor for immediate troubleshooting (QuickFix/Precompile).

Advantage

Static Analysis helps to write code that is easier to read and to identify potential sources of error during programming. On the one hand, this increases code quality and, on the other, saves a lot of time when developing applications and troubleshooting.

Failure to observe a coding rule generally indicates an implementation weakness; correcting it enables early troubleshooting or error avoidance. The automatic control of the user-specific naming conventions also ensures that the control programs can be developed in a standardized manner with regard to type and variable names. This gives different PLC projects implemented on the basis of the same naming conventions a uniform look and feel, which greatly improves the readability of programs. In addition, the metrics provide an indication of the software quality.

Functionalities

An overview of the functionalities of "TwinCAT 3 PLC Static Analysis" is provided below:

Alternatively, there is an option to use a license-free version of Static Analysis that provides a very much reduced range of functions. A detailed comparison of the functions of the license-free and the licensed version of Static Analysis can be found in chapter Installation.

Further information on installation, configuration and execution of the "Static Analysis" can be found on the following pages:

Overview 1:

Libraries

TwinCAT only analyzes the application code of the current PLC project; the referenced libraries are ignored!

If you have opened the library project, however, you can check the elements it contains with the help of the command Command 'Run static analysis [Check all objects]'.

Overview 2:

Punctual disablement of checks

Pragmas and attributes can be used to disable checks for certain parts of the code.

Overview 3:

Static Analysis via the Automation Interface

Static Analysis can be operated via the Automation Interface (see Automation Interface support).