Code Checker
The Code Checker tool performs a scan of the project declarations and programs, in order to check conformity to a set of rules, motivated by integrity, safety and portability of the code. It is run from the "Code Checker" tab of the Output window.
Use the "Settings" button to select/configure the rules to be checked for violations.
Use the "Scan" button to start analysis. The project must be compiled without errors before being checked.
Double-click on a violation report line in the output enables you to navigate to the corresponding location of the source code.
Use commands of the contextual popup menu to copy or export the report.
Note: an option is available in the "Compiler" section of the "Project Settings" box to systematically run the Code Checker after any successful build.
Rules configuration
Use the "Configure" button to select and configure rules to be checked. This is also available from the main tab of the "Project Settings" box. Rules are shown in a tree including check boxes. Unchecked rules will be skipped during scan. Double-click on a rule to configure it.
You can select for each rule a severity level: "Not checked" or "Info" or "Warning" or "Error" or "Fatal". You can also enter for each rule a text reference that will be displayed in reports.
For rules referring to metrics (e.g. name length) you can enter a minimum and maximum value.
For rules concerning variables, you can specify a filter based on the "User's group" column of the variable editor: either check only in some user's groups, or check except in some user's groups. Please enter one user's group name per line
For rule 1.4, you have to enter in the "Data" box the list of forbidden names. Please enter one name per line.
In addition the rules configuration box enables you to export or import the configuration as XML file.
Rules
1.1 |
IO channels (%...) must have an alias |
Default level = ERROR
Accept filtering by user’s group
All I/O board channels ("%..." variables created from the IO board editor) must have a readable alias defined in the variable editor. The "%..." names cannot be used in programs. Programs must always refer to aliases.
1.2 |
IO channels (%...) aliases should not reflect the hardware location |
Default level = WARNING
Accept filtering by user’s group
Aliases of I/O board channels should not reflect the hardware location. For instance an alias for channel "%IX0.1" cannot be "DI0_1".
1.3 |
Names must respect a minimum and a maximum length |
Default level = INFO
Accept filtering by user’s group in case of variables
Minimum and maximum values configurable
This applies to any declared variable or POU.
1.4 |
Names used during debug should not remain in the project |
Default level = WARNING
Accept filtering by user’s group in case of variables
Data = list of forbidden names, separated by comas.
The dummy variables used during debugging should be removed from the final project. The user should enter the list of forbidden names for this rule.
1.5 |
All given names must be conform to IEC standard |
Default level = ERROR
Accept filtering by user’s group in case of variables
The Workbench Studio proposes an option in order to accept variable names not compliant with the IEC standard (with punctuation, accents, spaces ). This option should not be used. Symbols of all variables and POUs are checked.
1.6 |
Names reserved for keywords should not be used |
Default level = FATAL
Accept filtering by user’s group in case of variables
Reserved keywords from the IEC standard should not be used for naming variables, whatever is the programming language. For instance, the name "STEP" cannot be used.
1.7 |
POU information should be filled |
Default level = WARNING
Does not accept filtering by user’s group
In the "POU Information" box, the items "Author", "Security Class" and "Project No" must be filled.
1.8 |
The case of variable names must be respected |
Default level = INFO
Accept filtering by user’s group in case of variables
When a variable is used in programs, it must have exactly the same case as its declared name.
2.1 |
All declared objects must have a comment |
Default level = ERROR
Accept filtering by user’s group in case of variables
This applies to all declared variables and POUs.
2.2 |
Comments must respect a minimum length |
Default level = ERROR
Accept filtering by user’s group in case of variables
Minimum and maximum values configurable for the length
This applies to all declared variables and POUs.
2.3 |
The percentage of comments should be sufficient |
Default level = WARNING
Accept filtering by user’s group in case of variables
Minimum value configurable as percent
This is the percentage of comments entered within the code of POU, whatever is the programming language. This percentage is tested individually for each POU and applies only to the code. Comments entered for local variables are not counted here.
2.4 |
Comments should not contain special characters |
Default level = WARNING
Accept filtering by user’s group in case of variables
Minimum value configurable as percent
Characters with ASCII code greater than 127 (accents, special characters) should not be used in comments. This applies to both declared objects and comments entered in POUs.
3.x |
XXX language should not be used for main programs |
Default level = FATAL for IL – NOT CHECKED for others
Does not accept filtering by user’s group
This rule is derived for: IL, ST, LD, FBD and SFC languages
3.x |
XXX language should not be used for UDFBs |
Default level = FATAL for IL – NOT CHECKED for others
Does not accept filtering by user’s group
This rule is derived for: IL, ST, LD, FBD and SFC languages
3.x |
XXX language should not be used for sub-programs |
Default level = FATAL for IL – NOT CHECKED for others
Does not accept filtering by user’s group
This rule is derived for: IL, ST, LD and FBD languages.
4.1 |
All input parameters must be read out |
Default level = FATAL
Accept filtering by user’s group in case of variables
Any IN parameter of a UDFB or sub-program must be read in its implementation.
4.2 |
All output parameters must be written before they are read out |
Default level = FATAL
Accept filtering by user’s group in case of variables
Any OUT parameter of a UDFB or sub-program must be written in its implementation. It can be read, but only if it was written before.
4.3 |
All INOUT parameters must be written and read out |
Default level = FATAL
Accept filtering by user’s group in case of variables
Any INOUT parameter of a UDFB or sub-program must be read and written in its implementation.
4.4 |
Forward and backward jumps should not be used |
Default level = ERROR
Does not accept filtering by user’s group
This applies to jump and return instructions in LD, FBD and IL, plus RETURN, EXIT and GOTO statements in ST.
4.5 |
ST expressions should not be used in LD and FBD |
Default level = FATAL
Does not accept filtering by user’s group
Text associated to graphic items in LD and FBD programs should not be complex expressions. For instance, associating "IntVar > iMax" to a LD contact is not accepted.
4.6 |
LD coils should be aligned on the right |
Default level = WARNING
Does not accept filtering by user’s group
4.7 |
IF structures should include an ELSE section |
Default level = WARNING
Does not accept filtering by user’s group
This applies to both "IF" and "CASE" statements in ST language.
4.8 |
There should not be dead code (uncalled UDFB or sub-program) |
Default level = ERROR
Does not accept filtering by user’s group
Any declared UDFB or sub-program must be used at least once in the project. Conditional compiling is forbidden.
4.9 |
Equality tests should not be used with REAL and LREAL |
Default level = FATAL
Does not accept filtering by user’s group
The option "Forbid equality tests between reals" must be checked in the "Compiler" section of the "Project Settings" box.
4.10 |
Nesting of ST structure should not exceed a complexity level |
Default level = INFO
Does not accept filtering by user’s group
Maximum value configurable
This applies to nesting of any IF, WHILE, REPEAT, FOR, CASE structure in ST language.
4.11 |
The "WAIT" instructions of the ST language should not be used |
Default level = ERROR
Does not accept filtering by user’s group
The instructions "WAIT", "WAIT_TIME" and "DO_WAIT" should not be used in ST.
4.12 |
The loop instructions of the ST language should not be used |
Default level = ERROR
Does not accept filtering by user’s group
The instructions "WHILE", "REPEAT" and "FOR" should not be used in ST.
4.13 |
All block inputs should be connected in FBD diagrams |
Default level = ERROR
Does not accept filtering by user’s group
This refers to an option in the "Project Settings" box. In the "Advanced" category, the "Deny unwired inputs in FBD" should be checked.
4.14 |
POUs in ST or IL should not exceed a number of lines |
Default level = WARNING
Does not accept filtering by user’s group
Maximum value configurable
This applies to the entire POU contents, including comments and empty lines.
4.15 |
POUs in LD should not exceed a number of rungs |
Default level = WARNING
Does not accept filtering by user’s group
Maximum value configurable
4.16 |
POUs in LD or FBD should not exceed a number of blocks |
Default level = WARNING
Does not accept filtering by user’s group
Maximum value configurable
Any function, operator or function block inserted in the diagram is counted.
4.17 |
POUs in SFC should not exceed a number of steps |
Default level = WARNING
Does not accept filtering by user’s group
Maximum value configurable
4.18 |
SFC transitions should have a condition |
Default level = WARNING
Does not accept filtering by user’s group
The IEC standard considers that a SFC step without any condition is considered as always TRUE. In order to comply to this Code Checker rule, you should explicitly enter "TRUE" in the condition of such a transition.
5.1 |
All declared variables must be used in programs |
Default level = ERROR
Accept filtering by user’s group in case of variables
Unused variables should not remain in the project.
5.2 |
Arrays of structures should not be used |
Default level = WARNING
Accept filtering by user’s group in case of variables
5.3 |
All variables must be written before they are read out |
Default level = ERROR
Accept filtering by user’s group in case of variables
This also applies to global variables read or written among several POUs, according to their execution order. This rule is not applied to variables declared as "Read only".
5.4 |
An instance of FB should be called only once |
Default level = FATAL
Accept filtering by user’s group in case of variables
This regards calling of the same declared instance of the same function block.
You should check the project settings option: "Check multiple calls to FB instances"
5.5 |
A global variable should be written in only one POU |
Default level = ERROR
Accept filtering by user’s group in case of variables
It is allowed that the global variable is read in other POUs.
5.6 |
A variable should be written only once among programs |
Default level = FATAL
Accept filtering by user’s group in case of variables
This applies to both local variables used within one POU and global variables used in several POUs of the project.
5.7 |
Arrays should not be used |
Default level = WARNING
Accept filtering by user’s group in case of variables
5.8 |
Parallel branches should not be used in SFC |
Default level = WARNING
Does not accept filtering by user’s group
The use of parallel branches (AND divergences) in SFC programs is not allowed.
5.9 |
SFC charts should be checked |
Default level = FATAL
Does not accept filtering by user’s group
In the "Project Settings" box, the compiling option "Check safety of SFC charts" must be enabled.
5.10 |
All declared variables with single data type must have an initial value |
Default level = INFO
Accept filtering by user’s group in case of variables
This rule does not apply to: channels of an input board (%), arrays, structures, instances of function block, input or output parameters of UDFBs and sub-programs.
6.1 |
The code should not be built with debugging options checked |
Default level = FATAL
Does not accept filtering by user’s group
This rule refers to compiling options set from the "Project Settings" box. The code should not be compiled in DEBUG mode. The "Variable Locking" feature should not be enabled. Online Change should not be enabled.
6.2 |
Arrays indexes should be checked at Runtime Service |
Default level = FATAL
Does not accept filtering by user’s group
This rule refers to compiling options set from the "Project Settings" box. The compiling option "Check array indexes at Runtime Service" should be checked.
6.3 |
Dynamic memory allocation should be configured with limited size |
Default level = FATAL
Does not accept filtering by user’s group
This rule refers to compiling options set from the "Project Settings" box. In the settings of the "Enable Dynamic memory allocation" or the "Runtime Service" memory should not be configured to use Operating System dynamic memory.
Code Checker |
IEC 61131-3 Automation platform > IEC 61131-3 Programming Environment > Tools > Code Checker |
Created with the Personal Edition of HelpNDoc: Full-featured multi-format Help generator