laitimes

Sharing of standardized design methods for PLC function blocks

author:A sprouted potato

The standardization of PLC procedures mainly includes four aspects:

1. PLC programming technology foundation, ISA-88 international standard and naming rules.

2. PLC program architecture design.

3. Design of functional blocks of foundation and process.

4. Build the whole program instance.

The design of the function block is the core part of PLC standardization, and some engineers have exchanged the design method of the function block, today I will share my ideas and methods, welcome interested friends to discuss and exchange.

First, the principle of basic design

1. It is recommended to write in ST (SCL) language.

2. It is recommended to use local variables.

3. Use multiple instances instead of single instances.

4. Use Region for intra-block program partitioning.

2. API naming conventions

Sharing of standardized design methods for PLC function blocks

Variable naming conventions

Sharing of standardized design methods for PLC function blocks

Yali standard type variable nomenclature prefix

Sharing of standardized design methods for PLC function blocks

Nomenclature for programs, function blocks, functions, etc

3. Basic Principles of Programming

The programming guidelines contain 4 1s and 7 requirements and 4 prohibitions. The red part must be followed, and the black part should be carried out as agreed as far as possible. 1. Guiding ideology

1 variable does only 1 thing;

1 function/method/action implements only 1 function;

Only one naming style is allowed for 1 project;

There is only one statement in line 1.

2. Programming conventions

The loop complexity of the new function is required to be no more than 15 (the number of logical branches), which can be simply understood as the number of conditional logical branches in the function should not exceed 15;

The number of parameters of the new function is required to be no more than 6, and the function blocks are not included.

The number of lines of code required for the new function to be no more than 200;

Require no more than 5 layers of code nesting for new functions;

Different types of variables are required to be assigned, which must be explicitly converted;

The number of single-line operators in a single conditional statement is required to be no more than 4;

Require the code to be indented by 4 spaces.

It is forbidden to use magic numbers directly;

It is forbidden to keep useless code variables in the program;

Prohibit the abuse of comments and keep them consistent with the code style;

No duplication codes are allowed to exceed 8 lines.

Note: Programming conventions also apply to Methods for Program Organizational Units (POUs).

3. Design constraints

PLCopen 库禁止绑定PLC。

The PLCopen library prohibits binding to the operating system.

The PLCopen library prohibits dependencies on unofficially published libraries.

After the standardized technical route is clear, the PLC program architecture and process model can be constructed, and the model can be continuously optimized. In the case of a standardized method, the general engineer has designed the program model after about 1 year of optimization, it can be said that the PLC program standardization has been completed as a whole, and the subsequent work needs to be continuously optimized.

Read on