laitimes

Styled – How to standardize S7-1200/S7-1500 procedures?

author:Siemens Industry Support Center

Author: Pang Kaihang-Siemens Industrial Technical Support Center

1 The official documentation is coming

To meet the growing demand for standardization projects, Siemens has introduced the Programming Style Guide for SIMATIC S7-1200/S7-1500 (hereinafter referred to as the Guide).

The purpose of Siemens is to help developers design and develop programs according to a unified programming style, thinking, and habits. This improves the readability of the program and promotes the standardization of the project. The Guide also follows the trend of standardization and points a direction for teams that do not yet have their own development specifications, or have relatively simple specifications. This is not to say that all the norms in the Guide must be observed, but at least the list in the Guide is very informative and worthy of attention.

In addition, the Guidelines are an important part of Siemens' standardization system. After all, it is closely related to writing code, and as a developer, you also need to have an in-depth understanding and do a good job of standardizing knowledge.

The Guide divides the requirements into two categories: rules and recommendations:

  • Rules: Binding, generally need to be followed, essential for reusable programming, and violations need to be documented.
  • Recommendation: The requirements are lower than the rules, and it is recommended to comply.

By enforcing these rules and recommendations, the project can be effectively standardized, helping to unify the programming style of you and your team, and facilitate early project management and later development and maintenance work.

The following will briefly introduce some of the rules in the Guide so that you can have a basic understanding.

2 Record developer information

Usually, development engineers will add a description of the relevant paragraph before the statement of the network segment or SCL, which is definitely essential. But there is one more important note that engineers need to pay attention to. That is the title block of each block, where the most important information from the development process must be recorded. Why do you say that?

Generally, blocks are divided into two categories, the first is standard blocks, that is, general function blocks, which are used for direct calls. The second type is the block used to associate and call various standard blocks.

Although the former is a standard block, it is inevitable that there will be later changes such as program optimization, function upgrades, and adding alarms. Then the content of such version changes and personnel information must be clearly recorded. There are also function introductions, call environments, CPU requirements, etc., which also need to be recorded to avoid incorrect calls.

The latter is the block that needs to be changed frequently during debugging, and it is also necessary to record the reason for the modification, developer, and other information. This facilitates better traceability and provides a reference for future development. To this end, the Guide provides templates for editing and saving these contents. This is shown in Figure 1.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 1. SCL information template

Of course, unlike other programming languages, SCL templates are written in statements and cannot be displayed when blocks are protected by proprietary technology. Therefore, the contents of the template can be filled in the "Block Attribute > Information" as shown in Figure 2, so that various information about the block can be seen without entering a password, as shown in Figure 3.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 2. Fill in the block attribute information

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 3. SCL encryption block properties view

3 Use libraries for version control

As mentioned earlier, there may be program optimization, function upgrades, and additional alarms and other changes in the later stage, that is, version upgrades. If it is only a simple modification of the program to replace the program, it cannot play the function of version management and version control. For version management and control, we recommend that you use the type feature of the library.

The type function of the library can be versioned for standard blocks, including FB, FC, PLC data types (UDT), etc. Use the type function of the library to update the version number every time the program changes, and support editing the author, comments and other information. This is shown in Figure 4.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 4. Release type version

Note: Before adding a block to the type of library, it is recommended to set up the emulation function activation, auto-numbering function, know-how protection, etc. that need to be set. Because once the block is added to the library, these functions cannot be set up again.

For version numbers, there are generally the following requirements for reference:

  • The version number format is x.y.z
  • The starting version is 1.0.0
  • "z" means to fix the error, the function is not modified
  • "y" indicates that the function is extended, and when it is changed, "z" is cleared at the same time
  • "x" is a breaking change or a change that is incompatible with a previous version, and when changed, both "y" and "z" are cleared
  • "x", "y", "z" are between 0 - 999

For more information about how to change the version number, see the following table.

Styled – How to standardize S7-1200/S7-1500 procedures?

With this function, it is convenient to carry out version management in the project, and further can be made into an enterprise library or even a network library for global sharing, which is convenient for unified project planning.

4 Handling ENOs

If you write some alarm programs, every developer or company must have relevant experience, and the methods are also varied. But if it's just some alarms of the command, this may not be very familiar to everyone. Here is a little trick to achieve twice the effect with half the effort when dealing with the command alarm.

You may have noticed that many instructions, such as mathematical operations, conversions, etc., or FC, FB, will have an ENO on the right output. It is generally empty there, and there is no effect, or other blocks are connected in series later, and that's it.

In fact, the reason why I can't feel that it has any effect is because this function is not activated by default, that is, ENO has always been true. But in fact we can activate this function and let ENO determine whether the instruction or block is executed abnormally. At this time, the normal ENO output is calculated to be true, and the abnormal ENO output is calculated to be false.

Calculations such as overruns in instructions, or conversion errors can be judged. In addition, you can assign a value to ENO in a custom block to give or judge the ENO status by yourself.

So how can you activate the ENO of instructions and blocks?

Very simple, for the basic instructions called in LAD/FBD, you can generate an ENO directly in the context menu of the command, that is, activate the ENO. This is shown in Figure 5.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 5. Generate an ENO

If it is an SCL block, or if the SCL segment in the LAD/FBD block invokes the basic instruction to activate the ENO, it cannot be done in Figure 5. The setting needs to be activated in the block properties where it is located, as shown in the red box in Figure 6.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 6. SCL generates ENO

Of course, if it is a system instruction block or a user block, as long as the ENO is modified inside the block, then ENO = False may occur when calling the block.

Let's look at an example of the use of ENO in SCL, as shown in Figure 7. After reading this example, you should have a deeper understanding of EO.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 7. ENO example

In the above example, because the range of DINT is larger than that of INT, the conversion may fail, and once the range of the variable num exceeds the range of INT, then ENO will inevitably output False.

Therefore, with the function of EO, the program can be optimized.

5 Programming based on PLCopen templates

As mentioned earlier, the purpose of the Guidelines is to help developers unify programming styles and promote standardization of projects. For standardized programming, Siemens provides not only some rule suggestions, but also very useful programming templates. This template is a programming framework, with the framework just need to add the process logic content to it.

The SCL programming language-based template provided by Siemens that complies with the PLCopen standard is the General Function Library (LGF). Based on the General Function Library (LGF), it is easy to write FC and FB programs with a unified style and easy to read. The General Libraries (LGF) can be downloaded from the Siemens Industry Support website.

The latest version of TIA Portal library can be downloaded from the English page. If you have an older version of TIA Portal, you can currently download the library for the minimum V14SP1 version on the Chinese page. When the library is loaded into the TIA Portal, you can browse to the various templates (the Templates folder in the figure), as shown in Figure 8.

Styled – How to standardize S7-1200/S7-1500 procedures?

Figure 8. Template location

The template consists of the following parts from top to bottom:

  • PLC data types (UDTs) for diagnostics in function blocks for the following functions
  • Function block for Enable action: Asynchronous function block suitable for continuous execution, and the execution effect refers to the MC_MoveJog in motion control
  • Function block for Execute: Asynchronous function block suitable for single execution, and the execution effect refers to the MC_MoveVelocity in motion control
  • General functions and function block templates: including initialization segment, main program segment, output control section, output control section, output control generally also includes control of error bits and error codes

With these templates, we can build our own standardized blocks.

6 Videos are more intuitive

The text is not enough to see, the video is more intuitive. To learn more about programming specifications, check out the special video "Detailed Programming Guide" on the Siemens Industry Support Center platform. The video consists of 10 episodes, the content is as follows: 1. Programming guide summary and description; 2. TIA Portal software settings and language settings; 3. Naming conventions; 4. Precautions for general program programming settings; 5. How to ensure the security of the program; 6. Programming guide; 7. PLCOpen-based template; 8. How to improve the efficiency of program execution; 9. On the test suite; 10. Under the test suite.