Object-oriented programming of Siemens PLC - Solutions - Huaqiang

Probe domestic switch needle KG-300K needle head diameter is 3.0mm normally open switch needle
Photocoupler

Object-oriented programming is an advanced programming mode for computer high-level languages. This design idea can also be used in the industrial control system plc program, although we can not achieve many excellent features of object-oriented such as "inheritance", even its fundamental There is no such thing as an object-oriented programming language, but the basic concept of object-oriented programming is an instance of a class and a class (ie, an object). We only need to use this concept. In computer programming, we need to abstract and generalize some things in order to write classes. In industrial control systems, control objects such as motors, valves, etc. are obvious control categories, and they can be clearly targeted without abstraction. To write a class, the following will use Siemens' Step7 programming language and Schneider's Unity programming language to solve the object-oriented programming of PLC.

First, the way to achieve

Object-oriented programming uses the function block (ie FB) programming in Step7. When you talk about it, you will think of the modular programming proposed by Siemens. It is good, this is modular programming, but Siemens proposes modular, background data blocks, multiple Nouns such as backgrounds do not allow everyone to understand and use this excellent design concept. If you understand from the perspective of object-oriented programming, you can understand this design pattern very well. The "FB block" is treated as a "class", which can be thought of as a code summary for similar control objects. For example, the MM block can be programmed with the FB block: MtrMM440, which is called "class" in object-oriented programming. When you need to program and control a specific motor, you can assign it a background DB block, called class implementation in object-oriented programming (that is, create an instance of the class: object), when you need to control multiple motors, you can assign different The background DB to this FB block, that is, create multiple instances of the class. In Step 7, there is another block, FC block. FC block-based programming is called structured programming in Siemens. It can also be analogized to process-oriented programming in computer programming, that is, purely function-based programming. .

Schneider's Unity software programming provides a better understanding of object-oriented programming. Its DFB definition contains input/output parameters, private/common variables, and code implementations, which are the basic elements of a "class" in computer object-oriented programming, and creating instances of objects (objects) is like creating ordinary ones. Like the "Boolean" variable, you only need to define this "class" variable in "Function Blocks".

Both Step 7 and Unity can adopt process-oriented and object-oriented programming. The difference between the two programming methods is similar to the difference between C language and C++ language programming in computer high-level languages.

The following explanation will refer to the FB in Step7 and the DFB in Unity as "class". The FB+ background DB in Step7 and the instance of DFB in Unity are called "objects".

Second, object-oriented programming architecture

The above explanation is the implementation details, and the programming idea is built on the program architecture. It is not a partial use of the object-oriented approach, it can be called this kind of programming is object-oriented programming. This kind of programming needs to start from the following aspects:

1. Structure of circuit design.

Here mainly introduces the automatic line, which can be its simplified structure for a single machine.

<1>, automatic line layer: This is the highest level, it has a main PLC, control for each area below it

<2>, engineering layer: has an independent distribution system, but no PLC, only distributed modules, controlled by automatic lines. As the name implies, it has greater independence and can be designed and manufactured as a separate engineering project. When the automatic line is small, the level can be omitted.

<3>, function group layer: According to the process division, the segment device that realizes a certain process function is divided into a function group, which belongs to the engineering layer, and belongs to the automatic line layer when the engineering layer is omitted.

Object-oriented programming does not necessarily require the use of the above structure, but a good electrical structure is more conducive to object-oriented programming.

2. Any control object logic is implemented in a "class".

In order to do this, it is necessary to analyze the information related to the control object. For example, for a motor, the following related information needs to be considered:

Enter information:

<1>, circuit protection information, such as motor air switch, thermal relay, etc.

<2>, function protection information, such as the limit switch of the motion motor, the wind pressure switch of the fan, the oil level switch of the oil pump, etc.

<3>, start and stop conditions, the above circuit protection and functional protection may cause the motor to terminate, reset may also cause a restart, but the conditions here refer to the start and end conditions of normal operation, such as the sequence control process step.

<4>, control mode: such as manual and automatic.

<5>, fault reset: restart by resetting the information.

Output information:

<1>, control output, such as the main contactor of the control motor.

<2>, status information output

<3>, fault output

.........

Status storage information:

Intermediate variables for code implementation and state variables that can be read by the human machine interface

Integrate the above information into a single class and try to standardize the parameters of the class. However, there are some differences in high-level programming languages. For Step 7, the standard should be followed: the program structure is implemented by FC, and the object control is implemented by FB. The following structure (the electrical structure is from the above introduction): It is just a rough PLC program architecture system, and the good architecture should be more complete and scientific.

3. Plan the data structure

The definition of the data structure is very important, and try to unify these structures, do not worry about storage space, today's PLC memory is enough to hold a large amount of data. One point to note is that in Step 7, try not to define the data structure (UDT) outside the class, but to define it in the class. Although it will result in the repetitive definition of the same structure in different classes, it will improve the independence of the class.

Third, superiority

1. Standardization

Using this design pattern, programming can be divided into two phases, namely standard library, basic architecture development, and practical application level design. The standard library and basic architecture are the basis for standardization of the program, and the application layer design is for specific control engineering programming. This can divide the programmer into two categories, one is standard development, the senior programmer is responsible, and the other is Application design (where program debugging planning to application design) is completed by general programmers who have been trained in standardization. Through this distribution, the embarrassing situation in China's industrial automation can be solved. The traditional Chinese control industry, a program is designed by one person, so he must also be responsible for on-site debugging, and the experienced programmer is usually 30 years old, when he has become a family, and obviously long-term business trip is not good for the family, Many good programmers have to change their careers for family considerations, either to management positions or to manufacturing factories for equipment maintenance. This is a serious loss of resources. Undoubtedly, using the above design flow, we can let experienced programmers engage in the design of standard libraries and architectures, and let the young people who have just stepped into the industry engage in application design and debugging, which can not only let the old programmers Continue his own work without affecting the family. He can also let young programmers participate in on-site debugging, cultivate their own experience and increase their income.

This may cause some people to worry that young programmers can participate in on-site debugging? What is certain is that programs that do not have standardized support are not only not available to young programmers, but also have a lot of problems in on-site debugging. But with good standardization, programmers with more than a year and a half of work experience should be able to face the automatic line independently.

The core of object-oriented programming in PLC is black box programming. For Step7, we use FB to realize the control of each object. The control logic, alarm processing and signal exchange are all in FB. For application designers, you don't need to understand the code inside. Implementation, you only need to understand the function of the FB and how to use it, so the programming ability requirements for the application personnel are greatly reduced. For programming, it only follows the architecture, copy the code, and change the input and output conditions.

So what about debugging? Many people think that the biggest trouble with FB programming is that after FB's multiple calls, it is impossible to diagnose the code at all. From a technical point of view, we can't see it after it is called many times, except that it is viewed from the background DB. Monitoring the code, but I have already said that this is black box programming, we do not need to diagnose the code, just need to know what kind of input, what kind of parameter setting leads to what kind of output, the logic and function of the code is good or bad. It is the responsibility of the standard library developer, which requires the standard developer to perform different tests on the function blocks he designed under different conditions, and it is guaranteed to be correct. It is also necessary to write a complete and detailed function description document for the application designer. Understand these blocks, the standard architecture is not formulated once and for all, for the ever-changing project, it needs to be constantly improved and revised, which is also a place where engineering companies can actually accumulate knowledge.

The program needs to be used not only by the debugger, but also by the user (equipment maintenance personnel). If the complete standard library document is given to the user, the technology may be leaked. If not, it may be difficult for them to diagnose the device. This requires the standard developer to create another document, the equipment maintenance document, whose knowledge is limited to the user's ability to use the program for diagnosis.

2, reusability and easy management

The advantages of computer object-oriented programming are also reusable and manageable. It has also been used in PLC. Take Step7 as an example. It is necessary to discuss the difference between FC and FB. Observing the data type, FB is only one more "STAT" type than FC. In use, FB needs background DB, FC does not need it, but this difference causes FB to have its own independent data storage space, while FC data storage must rely on Public variables (such as intermediate variables M or shared DBs) have such a rule that the stronger the independence of the block, the better its reusability, and the less likely it is to create data access conflicts, making it easier to manage. Some companies produce PLCs whose programming language does not have this FB-like feature. At this time, an alternative solution like "FC+Shared DB" can be used, but its independence has been greatly reduced.

The independence of the same code is an important part of the standard setting. It is hard to imagine that a function block that is inextricably linked with other function blocks can be effectively reused as a standard block in different projects.

Throughout the development of computer language, the initial programming is horrible, and today's programming makes people get a lot of relief. There are many ready-made standard libraries, and people can put more programming effort into it. In terms of function itself, plc programming should also develop in this direction. More people should be engaged in application-level design. Those standard function blocks should not be repeatedly developed by different people, although major PLC factories have developed a large number of libraries. However, industrial control objects are diverse, and different industries should have their own libraries, and the reusability of code is the key to evaluating the quality of these functional blocks. #p#分页头#e#

3. Advancement of design ideas

In the circuit diagram design, we have already used the drawing method for the control object. After the basic main distribution circuit and PLC configuration are completed, we will draw a circuit diagram for each field control object such as motor, valve, cylinder and other control objects. Their power supply comes from the main distribution circuit, control and feedback are connected with the PLC, the hardware chain is adjusted according to the actual situation, and the control objects are organized and stacked like the building blocks. Similarly, the programming is also used for the control objects. The standard control block implementation can be implemented, the program control details are effectively encapsulated, making the program look simple and easy to maintain, and a good design can be a good association between the schematic and the program, even one-to-one The relationship, such as a control object in the schematic can be found in the program corresponding FB call corresponding to it, truly oriented to control object programming.

Some people may doubt that PLC programming is mostly step programming. This standard block is for the control object. How is the control order implemented? This requires writing a special sequence control FB block, or using Siemens' ready-made Graph7, which is no different from general programming.

Conclusion: There are many programmers in the field of industrial control. They are proficient in algorithms and have their own programming ideas. When I discuss standardization with some people, they realize the efficiency of standardization, but think that this can not reflect their own programming level. Yes, as described above, the application level is not a high level of programming, but think about it, can one person go to the field for debugging all his life? If you want to reflect your value, you can do standard programming. I also hope that they can spend a little time researching the program architecture, all walks of life, the real master is the system architecture designer, programming tips are just to add to the good architecture.

I hope that China's industrial automation can get rid of the era of small workshops as soon as possible!

Compact Temperature Sensor

Compact Temperature Sensor We have many products in marine temperature sensors, and our small marine temperature sensors have been traveling in various oceans. Our sensors are not only used in ship mechanical equipment, but also used in freight yards. Our small marine temperature sensor can be used to monitor the marine mechanical equipment and the temperature and humidity in the warehouse. Moreover, our sensor has been used in the oil separator module for a long time, and its performance is very stable.

Compact Temperature Sensor,Small Temperature And Humidity Sensor,Smart Temperature Sensor,Hydraulic Temperature Sensor

Taizhou Jiabo Instrument Technology Co., Ltd. , https://www.taizhoujiabo.com