PLC programming method based on C + + language

By using C++ language to write function blocks and programs in PLC programming configuration software, and calling C++ function blocks and programs in IEC61131-3 standard language user programs, the problem of lack of PLC programming methods based on C++ language in the existing technology is solved, complex logic processing and algorithm implementation is realized, the flexibility and practicality of the programming environment of the PLC programming configuration software is improved, user porting algorithms and logic are simplified, and the feasibility of rapid upgrading and transformation of the control system is improved.

CN119511931APending Publication Date: 2025-02-25NANDA AUTOMATION TECH JIANGSU CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411720924.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-28
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

The existing technology lacks PLC programming methods based on C++ language, making it difficult to implement complex logic processing and algorithms, which reduces the flexibility and practicality of the programming environment of the PLC programming configuration software, increases the difficulty of user transplantation algorithms and logic, and reduces the feasibility of rapid upgrade and transformation of the control system.

Method used

Provide a PLC programming method based on C++ language, including using C++ language to write function blocks and programs in PLC programming configuration software, and calling C++ function blocks and programs in IEC61131-3 standard language user program, generating a specified format file, downloading and executing the program.

Benefits of technology

The PLC programming method based on C++ language is implemented, which enriches the programming environment of the PLC programming configuration software, improves the flexibility and practicality of the software, can realize complex logic processing and algorithms, meets special application needs, simplifies users' rapid porting of algorithms and logic, and improves the feasibility of rapid upgrading and transformation of the control system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119511931A_ABST
    Figure CN119511931A_ABST
Patent Text Reader

Abstract

The invention discloses a PLC (Programmable Logic Controller) programming method based on a C + + language, relates to the technical field of textual programming of PLC programming software, and particularly relates to a method for programming a PLC program by using the C + + language to write functional blocks in PLC programming configuration software and using the C + + functional blocks in an IEC611131-3 standard language user program. In the process, functional blocks need to be defined and edited in the PLC programming configuration software, the functional blocks are imported into an IEC611131-3 standard language user program, programs of the functional blocks need to be written in the PLC programming configuration software, the programs are compiled into files in a specific format, the files are downloaded to a lower computer PLC equipment main controller module and executed on the lower computer PLC equipment main controller module, and the PLC equipment main controller module is connected with the PLC equipment main controller module. Therefore, the development of the PLC program becomes easier and more efficient, the time is saved, and the cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of text-based programming of PLC programming software, and in particular to a PLC programming method based on C++ language. Background Art

[0002] PLC refers to programmable logic controller, which is a general industrial automatic control device developed based on microprocessor and integrating computer technology, automatic control technology and communication technology. It has a series of advantages such as small size, powerful functions, simple program design, flexible and universal, easy maintenance, etc., especially its high reliability and strong ability to adapt to harsh industrial environment, which makes it widely used in various industrial fields.

[0003] The IEC61131-3 standard provides five standard programming languages ​​for PLC, including ladder diagram (LD), function block diagram (FBD), sequential function chart (SFC), structured text (ST), and instruction list (IL). In a modular programming environment, the program organization unit (POU) is the smallest, independent software unit in the user program. The IEC61131-3 standard defines three types of POUs, which are function (FUN), function block (FB), and program (PROG) in ascending order of their functions.

[0004] The five PLC programming languages ​​provided by the IEC61131-3 standard can meet the needs of users in most cases. However, when faced with application scenarios involving complex logic processing and algorithm implementation, conventional PLC programming languages ​​are difficult to complete all program writing. In comparison, C / C++ language is more flexible and powerful, with powerful computing power and rich library functions, which can implement complex logic processing and algorithms to meet special application requirements. Moreover, using C / C++ language can facilitate users to quickly transplant existing mature and reliable algorithms and logics to meet the rapid upgrade and transformation of control systems. Therefore, it is particularly important to invent a PLC programming method based on C++ language.

[0005] The prior art is as follows: "CN202410150287.X A method and device for extending C language functions in PLC programming configuration", which supports calling C language function methods in IEC61131-3 programs and running C language functions in PLC runtime. The method first creates a new user function of C language type, writes a specific implementation, allocates C language function numbers and generates codes for registering function addresses through pre-compilation, generates an extended C language function dynamic library through the cross-compilation tool chain during PLC runtime, and then calls the C language function in the user program of the PLC programming configuration software. After downloading the user program and the C language function dynamic library to the PLC main controller module, before the PLC program task is started, the PLC runtime initializes and loads the C language user function dynamic library, and calls the CLibInit function to register the user function number and address mapping table. When the PLC program task runs and executes the C language user function number call instruction, it first queries the address mapping table, and then jumps to the specific function address to execute the compiled C language user function.

[0006] The prior art also has the following defects, which are specifically reflected in: 1. The prior art lacks a PLC programming method based on C++ language, including a method for creating function blocks and programs based on C++ language, and a method for calling user programs and function blocks in IEC61131-3 standard language. 2. The existing technology lacks a C / C++ language-based PLC programming method that complies with the IEC61131-3 standard and is extended at the POU level of function blocks (FB) and programs (PROG), which reduces the programming environment of the PLC programming configuration software and reduces the flexibility and practicality of the software.

[0007] 3. The existing technology lacks a PLC programming method based on C++ language that can realize complex logic processing and algorithms, which makes it difficult to meet special application requirements, increases the difficulty for users to transplant existing mature and reliable algorithms and logic, and reduces the feasibility of rapid upgrading and transformation of control systems. Summary of the invention

[0008] The purpose of the present invention is to provide a PLC programming method based on C++ language, which solves the problems existing in the background technology.

[0009] To solve the above technical problems, the present invention adopts the following technical solution: The present invention provides a PLC programming method based on C++ language, comprising: Step 1, using C++ language to write function blocks in PLC programming configuration software.

[0010] Step 2: Use C++ function blocks in IEC61131-3 standard language user programs.

[0011] Step 3: Use C++ language to write programs in PLC programming configuration software.

[0012] Step 4: Call the C++ program in the IEC61131-3 standard language user program.

[0013] Step 5: Generate a file in the specified format.

[0014] Step 6: Download the program.

[0015] Step 7: Execute the program.

[0016] Preferably, the function blocks are written in C++ language in the PLC programming configuration software. The specific analysis method is: use C++ language to write function blocks in the PLC programming configuration software, create a new custom function block, select the type as C / C++, edit parameters and internal variables, define the function block, and after confirmation, automatically generate the basic framework code according to the configuration.

[0017] Preferably, the use of C++ function blocks in the IEC61131-3 standard language user program, the specific analysis method is: using the method of calling function block instances, supporting direct calling of C++ function blocks in the IEC61131-3 standard language user program, at this time a C++ function block instance will be created by default, and a unique instance name will be generated.

[0018] Preferably, the program is written in C++ language in the PLC programming configuration software, and the specific analysis method is: create a new user program, select the type as C / C++, edit the program name, the task or interrupt, the program description and other information, and after confirmation, automatically generate the basic framework code.

[0019] Preferably, the specific analysis method for calling the C++ program in the IEC61131-3 standard language user program is as follows: with the help of the CALL function block, when the program executes to call the function module CALL, the scan immediately enters the specified subroutine block, and after completing the scan of the subroutine, the program returns to the original calling point and continues to scan down.

[0020] Preferably, the specific analysis method for generating the specified format file is as follows: after all C++ programs and function blocks are edited, the IEC61131-3 standard language programs and function blocks need to be compiled by a customized compiler to generate a specified format file that can be recognized and run by the main controller module of the lower-level PLC device.

[0021] Preferably, the download program is specifically analyzed in the following way: after successful compilation, the IEC61131-3 standard language user program and function block are downloaded together with the C++ type user program and function block to the main controller module of the lower-level PLC device.

[0022] Preferably, the execution program is specifically analyzed in the following manner: when the main controller module of the lower-level PLC device is started, all programs and function blocks are loaded; when the program logic is executed to the C++ program or function block, it automatically jumps to the entry function of the C++ program or function block, and then executes the user logic written in C++ language; after the execution is completed, it returns to the original calling point to continue to execute the subsequent logic.

[0023] The beneficial effects of the present invention are: 1. The present invention realizes a PLC programming method based on C++ language, including a method for creating function blocks and programs based on C++ language, and a calling method in IEC61131-3 standard language user programs and function blocks.

[0024] 2. The present invention expands the PLC programming method based on C / C++ language that complies with the IEC61131-3 standard at the POU level of function block (FB) and program (PROG) types, enriches the programming environment of PLC programming configuration software, and improves software flexibility and practicality.

[0025] 3. The PLC programming method based on C++ language described in the present invention can realize complex logic processing and algorithms to meet special application requirements. The method described in the present invention can facilitate users to quickly transplant existing mature and reliable algorithms and logics to meet the rapid upgrade and transformation of the control system. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0027] Figure 1 It is a schematic diagram of the steps of the method of the present invention.

[0028] Figure 2 Example for C++ function block definition.

[0029] Figure 3 This is a C++ function block basic framework code example.

[0030] Figure 4 It is a C++ function block instance table. Figure 5 This is an example of calling C++ function blocks in IEC61131-3 standard language user program.

[0031] Figure 6 This is an example of calling a C++ function block from a user-defined function block in the IEC61131-3 standard language.

[0032] Figure 7 Create examples for C++ programs.

[0033] Figure 8 This is a code example of the basic framework of the C++ program.

[0034] Fig. 9 This is an example of calling a C++ program from a user program in the IEC61131-3 standard language.

[0035] Fig.10 Generates examples of files for C++ programs and function block compilation. DETAILED DESCRIPTION

[0036] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0037] Reference Figure 1 As shown, the present invention provides a PLC programming method based on C++ language, including: step 1, using C++ language to write function blocks in PLC programming configuration software.

[0038] In a specific embodiment, the C++ language is used to write the function block in the PLC programming configuration software. The specific analysis method is: create a new user-defined function block in the PLC programming configuration software, edit the function block name, as shown in the attached Figure 2 As shown in the figure, select the type as C / C++, edit the input parameters, output parameters, input and output parameters and internal variables as needed, and define the function block. The input enable and output enable are added by default and cannot be edited. After confirmation, as shown in the attached Figure 3 As shown, the basic framework code will be automatically generated according to the configuration. The basic framework code contains the function block entry function name, parameters, return value and reminder comments. Among them, the entry function name rule is the "DFB_" prefix plus the function block name, and the parameter type is converted and adjusted according to the built-in rules. The basic framework code is prohibited from being modified, otherwise the compilation will report an error. The user must use C++ language to write the specific implementation logic of the function block based on this framework code. Users are allowed to create multiple C++ type function blocks, and the rules for configuring and automatically generating basic framework codes are the same as above. Function block names are not allowed to be repeated. After the name is edited, conflict detection will be performed and text reminders will be given.

[0039] Step 2: Use C++ function blocks in IEC61131-3 standard language user programs.

[0040] In a specific embodiment, the C++ function block is used in the IEC61131-3 standard language user program. The specific analysis method is as follows: when the C++ function block is used in the IEC61131-3 standard language user program, as shown in the attached Figure 4 As shown in the figure, the method of calling the function block instance is adopted. Users can directly call the C++ function block in the IEC61131-3 standard language user program. At this time, a C++ function block instance will be created by default and a unique instance name will be generated. You can also manually create a C++ function block instance in advance and then call it in the IEC61131-3 standard language user program. After calling the C++ function block, as shown in the figure Figure 5 As shown, users need to edit parameters according to program logic. C++ function block instance names are not allowed to be repeated. A unique instance name will be generated when automatically generated. When manually edited, conflict detection will be performed and text reminders will be given. Users can switch the called function block instance in the IEC61131-3 standard language user program. In the IEC61131-3 standard ladder diagram (LD) program and function block diagram (FBD) program, double-click the instance name at the top of the called C++ function block to switch. In the IEC61131-3 standard structured text (ST) program and instruction list (IL) program, manually modify the called instance name. When deleting the call, the function block instance will not be deleted automatically, and it can continue to be reused in other IEC61131-3 standard language user programs. Users can manually delete the function block instance in the function block instance list. Allow users to call the same function block instance in different IEC61131-3 standard language user programs. Here, the IEC61131-3 standard language user program includes the IEC61131-3 standard ladder diagram (LD) program, function block diagram (FBD) program, structured text (ST) program and instruction list (IL) program. When calling a C++ function block in the instruction list (IL) program, the CAL instruction is required. The CAL instruction indicates an unconditional call to a program or function block. It supports calling a C++ function block in a user-defined function block in the IEC61131-3 standard language in the same way as above. After calling a C++ function block in a user-defined function block in the IEC61131-3 standard language, as shown in the attached figure Figure 6 As shown, the user needs to edit the parameters according to the program logic. Here, the IEC61131-3 standard language user-defined function blocks include the IEC61131-3 standard ladder diagram (LD) type function blocks, function block diagram (FBD) type function blocks and structured text (ST) type function blocks.

[0041] Step 3: Use C++ language to write programs in PLC programming configuration software.

[0042] In a specific embodiment, the program is written in C++ language in the PLC programming configuration software. The specific analysis method is: create a new user program in the PLC programming configuration software, as shown in the attached Figure 7 As shown, select the type as C / C++, edit the program name, the task or interrupt, program description and other information, and confirm, as shown in the attached Figure 8 As shown, the basic framework code will be automatically generated. The basic framework code contains the program entry function name, return value and reminder comments. Among them, the entry function name rule is "program_" prefix plus the program name, without parameters. The basic framework code is prohibited from being modified, otherwise the compilation will report an error. The user must use C++ language to write the specific implementation logic of the program based on this framework code. Users are allowed to create multiple C++ type programs, and the rules for automatically generating basic framework codes are the same as above. The program name is not allowed to be repeated. After the name is edited, a conflict detection will be performed and a text reminder will be given.

[0043] Step 4: Call the C++ program in the IEC61131-3 standard language user program.

[0044] In a specific embodiment, the C++ program is called in the IEC61131-3 standard language user program. The specific analysis method is as follows: Fig. 9 As shown in the figure, when calling a C++ program in the ladder diagram (LD) and function block diagram (FBD) user program of the IEC61131-3 standard, you need to use the CALL function block. The function of the CALL function block is that when the program executes to call the function module CALL, the scan immediately enters the specified subroutine block. After completing the scan of the subroutine, the program returns to the original call point and continues to scan. When calling a C++ program in the structured text (ST) user program of the IEC61131-3 standard, just write the program name plus parameters. When calling a C++ program in the instruction list (IL) user program of the IEC61131-3 standard, you need to use the CAL instruction. The CAL instruction indicates the unconditional call of a program or function block.

[0045] Step 5: Generate a file in the specified format.

[0046] In a specific embodiment, the specific analysis method for generating the specified format file is as follows: after all C++ programs and function blocks are edited, the same as IEC61131-3 standard language programs and function blocks, you need to click the compile button of the PLC programming configuration software, as shown in the attached Fig.10As shown, a specified format file that can be recognized and run by the main controller module of the lower-level PLC device is compiled by a customized compiler. The customized compiler here is the customized compiler attached to the PLC programming configuration software, which is not within the scope of discussion of this technical solution. The specified format file here refers to a file with the suffix .o, which is an agreed format between the upper-level PLC programming configuration software and the lower-level PLC device main controller. The IEC61131-3 standard language program and function block here include the IEC61131-3 standard ladder diagram (LD) program and function block, function block diagram (FBD) program and function block, structured text (ST) program and function block, instruction list (IL) program and function block.

[0047] Step 6: Download the program.

[0048] In a specific embodiment, the download program is specifically analyzed as follows: after successful compilation, the IEC61131-3 standard language user program and function block together with the C++ type user program and function block are downloaded to the main controller module of the lower-level PLC device through the download function of the PLC programming configuration software.

[0049] Step 7: Execute the program.

[0050] In a specific embodiment, the execution program is specifically analyzed as follows: when the main controller module of the lower-level PLC device is started, all programs and function blocks are loaded. When the program logic executes to the C++ program or function block, it automatically jumps to the entry function of the C++ program or function block, and then executes the user logic written in C++ language. After the execution is completed, it returns to the original calling point to continue executing the subsequent logic.

[0051] The invention realizes a PLC programming method based on C++ language, including a method for creating a function block and a program based on C++ language, and a method for calling a user program and a function block in an IEC61131-3 standard language.

[0052] The present invention expands the PLC programming method based on C / C++ language that complies with the IEC61131-3 standard at the POU level of function block (FB) and program (PROG) types, enriches the programming environment of PLC programming configuration software, and improves software flexibility and practicality.

[0053] The C++ language-based PLC programming method described in the present invention can realize complex logic processing and algorithms to meet special application requirements. The method described in the present invention can facilitate users to quickly transplant existing mature and reliable algorithms and logics to meet the rapid upgrade and transformation of the control system.

[0054] The above contents are merely examples and explanations of the concept of the present invention. Those skilled in the art may make various modifications or additions to the specific embodiments described or replace them in a similar manner. As long as they do not deviate from the concept of the invention or exceed the scope defined by the present invention, they shall all fall within the protection scope of the present invention.

Claims

1. A PLC programming method based on C++ language, characterized in that: include: Step 1: Use C++ language to write function blocks in PLC programming configuration software; Step 2: Use C++ function blocks in IEC61131-3 standard language user programs; Step 3: Use C++ language to write programs in PLC programming configuration software; Step 4: Call the C++ program in the IEC61131-3 standard language user program; Step 5: Generate a file in a specified format; Step 6: Download the program; Step 7: Execute the program.

2. A PLC programming method based on C++ language according to claim 1, characterized in that: The C++ language is used to write function blocks in the PLC programming configuration software. The specific analysis method is as follows: Use C++ language to write function blocks in PLC programming configuration software, create a new custom function block, select type as C / C++, edit parameters and internal variables, define the function block, and after confirmation, automatically generate the basic framework code according to the configuration.

3. A PLC programming method based on C++ language according to claim 1, characterized in that: The specific analysis method of using C++ function blocks in the IEC61131-3 standard language user program is as follows: By calling the function block instance, it supports directly calling the C++ function block in the IEC61131-3 standard language user program. At this time, a C++ function block instance will be created by default and a unique instance name will be generated.

4. A PLC programming method based on C++ language according to claim 1, characterized in that: The program is written in C++ language in the PLC programming configuration software. The specific analysis method is as follows: Create a new user program, select the type as C / C++, edit the program name, task or interrupt, program description and other information, and after confirmation, the basic framework code will be automatically generated.

5. A PLC programming method based on C++ language according to claim 1, characterized in that: The specific analysis method of calling the C++ program in the IEC61131-3 standard language user program is as follows: With the help of the CALL function block, when the program executes to call the function module CALL, the scan immediately enters the specified subroutine block. After completing the scan of the subroutine, the program returns to the original calling point and continues scanning.

6. A PLC programming method based on C++ language according to claim 1, characterized in that: The specific analysis method for generating a specified format file is as follows: After all C++ programs and function blocks are edited, they need to be compiled by a customized compiler to generate files in a specified format that can be recognized and run by the main controller module of the lower-level PLC device, just like IEC61131-3 standard language programs and function blocks.

7. A PLC programming method based on C++ language according to claim 1, characterized in that: The specific analysis method of the download program is as follows: After successful compilation, the IEC61131-3 standard language user program and function blocks together with the C++ type user program and function blocks are downloaded to the main controller module of the lower-level PLC device.

8. A PLC programming method based on C++ language according to claim 1, characterized in that: The specific analysis method of the execution program is as follows: When the main controller module of the lower-level PLC device is started, all programs and function blocks are loaded. When the program logic executes to the C++ program or function block, it automatically jumps to the entry function of the C++ program or function block, and then executes the user logic written in C++ language. After execution is completed, it returns to the original call point to continue executing subsequent logic.

Citation Information

Patent Citations

  • Method and device for expanding C language function through PLC programming configuration

    CN118778536A