A ladder program compiling method

By adopting the QT platform and a top-down, left-to-right compilation principle in the PLC configuration software, combined with syntax and semantic checking, the shortcomings of traditional PLC configuration software in cross-platform adaptation are solved, and rapid compilation of ladder diagram programs and a smooth human-machine interface are achieved.

CN115509173BActive Publication Date: 2026-02-03NANDA AUTOMATION TECH JIANGSU CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211213883.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-30
Publication Date
2026-02-03
Estimated Expiration
2042-09-30

AI Technical Summary

Technical Problem

Traditional PLC configuration software has shortcomings in cross-platform compatibility, unsatisfactory compilation efficiency, especially when the ladder diagram program has many lines of code, the compilation time is too long, and it lacks sufficient code architecture design.

Method used

The PLC configuration software is built using the QT platform. By analyzing the direction of signal transmission in the wiring, the ladder diagram program is compiled according to the principle of top to bottom and left to right. The specific responsibilities of the module compilation function are assigned to each module class, and the syntax and semantic checking function is used to achieve fast compilation.

Benefits of technology

The system enables efficient compilation of ladder diagram programs on different platforms, simplifies the compilation process, improves compilation speed and the smoothness of the human-computer interface, and meets the operational requirements of multiple systems and platforms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509173B_ABST
    Figure CN115509173B_ABST
Patent Text Reader

Abstract

The application discloses a ladder diagram program compiling method, relates to the field of programmable logic controller (PLC) ladder diagram program compiling in the industrial control field, and aims to improve the efficiency of ladder diagram program compiling. Step 1, Links sorting, analyzing the transmission direction of the connected signal, and sorting all the connections; step 2, allocating the number for items and sorting according to the number; step 3, syntax and semantic checking; step 3.1, module syntax and semantic checking; step 3.2, syntax and semantic checking of input pins; step 3.3, syntax and semantic checking of output pins; step 4, giving a prompt in the case of error in the above syntax and semantic checking, and entering the intermediate program generation stage in the case of no error, generating intermediate files ldo and.c files, and finally calling gcc to compile into machine recognizable.o files. The application avoids the long module type judgment and the compiling process in the traditional compiling process, lets each module object realize the compiling function by itself, does not compile the unused module, and clearly distributes the responsibilities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of ladder diagram program compilation technology for programmable logic controllers (PLCs) in industrial control. Background Technology

[0002] Programmable Logic Controllers (PLCs) are widely used in various scenarios in industrial control. To fully utilize the functions of a PLC, configuration software compatible with the PLC is required. This software is used to perform functions such as hardware configuration, ladder diagram programming and compilation, and program downloading. Ladder diagram compilation is one of the important functions of configuration software.

[0003] Traditional configuration software adapted for the Windows platform is developed based on the MFC class library. Its software framework depends on the Windows operating system. Furthermore, the MFC class library is relatively complex to use and learn. When used on the Linux platform, configuration software with the same functionality needs to be redesigned and implemented. Therefore, software compatibility issues arise in multi-platform applications due to operating system inconsistencies. Thus, ladder diagram compilation design needs to consider the differences in platform class libraries and make corresponding optimizations.

[0004] For a long time, the mainstream PLC market has been monopolized by manufacturers such as Siemens, Mitsubishi, and Omron. International manufacturers' PLC programming software not only boasts strong cross-platform compatibility but also features excellent human-machine interfaces and software functionality designed to meet the usage habits of different customers. In contrast, domestic manufacturers have not placed sufficient emphasis on software design, resulting in a significant gap. Furthermore, configuration software based on the traditional Windows platform's MFC class library suffers from insufficient cross-platform compatibility and unsatisfactory compilation efficiency, failing to meet the needs of multi-system, multi-platform operation.

[0005] Traditional configuration software suffers from excessively long compilation times in ladder diagram programming, especially when there are many ladder diagram modules and lines of code. This is mainly due to deficiencies in the design of the ladder diagram program's traversal functionality and a lack of sufficient code architecture design.

[0006] Traditional Windows platform configuration software has readily available cross-compilers on x86 platforms. For the x86 platform Linux operating system, GNU gcc can well meet various needs. For MIPS platforms, such as the Loongson platform, cross-compilation tools can be downloaded from the Loongson open-source community, which includes detailed environment configuration instructions. Similar solutions exist for other platforms.

[0007] Cross-compilers can be adapted using cross-compilation tools, so improving compilation efficiency requires focusing on the cross-compiler's input. The importance of a compiler lies in its ability to free most computer users from machine-related complexities, making programmers and program design experts independent of the machine. Improving compilation efficiency is key to increasing user satisfaction with PLC configuration software. Summary of the Invention

[0008] To address the above problems, this invention proposes a ladder diagram program compilation method aimed at improving the compilation efficiency of ladder diagram programs. It assigns specific responsibilities for module compilation functions to each module class, resulting in clearer responsibility division, faster compilation speed, and a smoother human-computer interface. Simultaneously, it optimizes the methods and steps for syntax and semantic checking, and optimizes the algorithm for assigning numbers to primitives through the collection and sorting of links data, facilitating LD to LDO conversion and LDO to C conversion, thereby achieving rapid compilation.

[0009] The technical solution of this invention is as follows: It is carried out according to the following steps:

[0010] Step 1: Links sorting. Analyze the transmission direction of the connection signals and sort all the connections.

[0011] Step 2: Assign numbers to items and sort them according to the numbers, using the recursive function analysisExeNo as the sorting algorithm;

[0012] Step 3: Syntax and semantic check;

[0013] Step 3.1: Module syntax and semantics check. The functions involved in the syntax and semantics check are syntax() and semantics().

[0014] Step 3.2: Syntax and semantic check of input pins;

[0015] Step 3.3: Syntax and semantic check of output pins;

[0016] Step 4: If there are any errors in the syntax and semantics check mentioned above, a prompt will be given. If there are no errors, the intermediate program generation stage will proceed, generating intermediate files ldo and .c files. Finally, gcc will be called to compile the intermediate program into a machine-readable .o file.

[0017] Furthermore, in step 1, the Links sorting, or connection sorting, first analyzes the transmission direction of the connection signals and sorts all the connections. The sorting principle is from top to bottom and from left to right. Specifically, starting from the left bus, the elements connected to it are sorted from top to bottom according to their vertical coordinates, and then the elements connected to the right bus are sorted from top to bottom.

[0018] Further, step 2 assigns numbers to items, that is, assigns numbers to graphic elements, and sorts them according to the numbers, using the recursive function analysisExeNo as the sorting algorithm; this is carried out in the following steps:

[0019] Step 2.1: Determine whether the current graphic element has been assigned a number. If not, proceed with the following steps. If yes, traverse the next graphic element until all graphic elements have been assigned numbers.

[0020] Step 2.2: Process the input pins and determine whether the connections that the input pins depend on have been checked.

[0021] If the inspection has been completed, a number is assigned, the input pin of the current graphic element has been processed, and the process proceeds to the next step.

[0022] If not, search for the associated graphic elements in sequence and return to step 2.1 to process the associated graphic elements first;

[0023] Step 2.3: Process the output pins; check whether any dependent connections of the output pins have been checked.

[0024] If the inspection has been completed, assign a number, the output pin of the current graphic element has been processed, and return to step 2.1;

[0025] If not, search for the associated graphic elements in sequence and return to step 2.1 to process the associated graphic elements first.

[0026] Furthermore, the syntax check process in step 3.1 is as follows: traverse all primitives, perform syntax and semantic checks according to the type of primitive, check whether the input and output pins of the primitives are empty, check whether the data types of the pins match, and check whether the pin parameter names conflict.

[0027] Furthermore, step 3.2 specifically includes:

[0028] Step 3.2.1: Begin traversing the primitive input pins;

[0029] Step 3.2.2: Determine whether the syntax check of the current input pin has been completed. If it has been completed, return to step 3.2.1 and continue to check the next input pin; if it has not been completed, proceed to the next step.

[0030] Step 3.2.3: Traverse the primitives containing the associated input pins and output pins, and perform a syntax check based on the data type. If an invalid data type is found, output an error message. If a valid data type is found, continue checking whether all associated pins have been checked. If not, continue traversing the next associated primitive; if all are checked, the syntax check is successful.

[0031] Furthermore, step 3.3 specifically includes:

[0032] Step 3.3.1: Begin traversing the primitive output pins;

[0033] Step 3.3.2: Determine whether the current output pin has completed the syntax check. If it has, return to step 3.3.1 and continue checking the next output pin; if it has not, proceed to the next step.

[0034] Step 3.3.3: Traverse the primitives containing the associated input pins and output pins, and perform a syntax check based on the data type. If an invalid data type is found, output an error message. If a valid data type is found, continue checking whether all associated pins have been checked. If not, continue traversing the next associated primitive; if all are checked, the syntax check is successful.

[0035] This invention utilizes PLC configuration software built on the QT platform to realize a ladder diagram compilation method that can run on different platforms, which can meet the usage requirements of different projects and facilitate different projects on WINDOWS and LINUXS. It solves the drawback that the original MFC configuration software could only meet the needs of projects developed on the WINDOWS platform.

[0036] During ladder diagram compilation, the direction of signal transmission is analyzed, and the ladder diagram program is transformed and compiled according to the principle of top-down and left-to-right, thereby converting the ladder diagram program into a program that can run on the underlying embedded hardware. Simultaneously, this invention assigns specific responsibilities for module compilation functions to each module class, resulting in clearer division of responsibilities, faster compilation speed, and a smoother human-machine interface, providing a better user experience.

[0037] This invention avoids the lengthy module type checks and compilation process of traditional compilation. Through the syntax() and semantics() functions, each module object implements its own compilation functionality, with unused modules not being compiled, resulting in a clear allocation of responsibilities. Errors in syntax and semantic checks are flagged; otherwise, the process proceeds to the intermediate program generation stage, producing intermediate files (.do) and .c files. Finally, gcc is called to compile the program into a machine-readable .o file. Attached Figure Description

[0038] Figure 1 It is a schematic diagram of the program compilation process.

[0039] Figure 2a This is a schematic diagram of ladder diagram elements for coils and electric shocks.

[0040] Figure 2b This is a schematic diagram of the ladder diagram elements of the basic functional modules.

[0041] Figure 2cThis is a schematic diagram of the trapezoidal primitives connected by lines.

[0042] Figure 2d This is a schematic diagram of the primitive class design;

[0043] Figure 3 This is a diagram illustrating the ladder diagram compilation process.

[0044] Figure 4 This is a diagram illustrating the compiler number allocation.

[0045] Figure 5 This is a flowchart of the numbering assignment process.

[0046] Figure 6 It is a process of checking and organizing syntax and semantics.

[0047] Figure 7 This is the input pin syntax and semantic checking process.

[0048] Figure 8 This is the output pin syntax and semantic checking process. Detailed Implementation

[0049] To clearly illustrate the technical features of this patent, the following detailed description is provided through specific embodiments and in conjunction with the accompanying drawings.

[0050] A compiler is one of the fundamental components of a modern computer system. Functionally, a compiler is a language translator. It translates a program written in one language (called the source language) into an equivalent program in another language (called the target language). Since computer hardware only understands its own instruction set—that is, it can only execute programs written in the corresponding machine language, and cannot directly execute programs written in high-level languages ​​or assembly languages—a compiler is necessary to implement any programming language other than machine language on a computer and make that source language recognizable by the computer. Compilation occurs in two ways: one is to translate the program; the other is to interpret the program.

[0051] The importance of a compiler lies in its ability to free most computer users from the complexities of machine-related details, making programmers and program design experts independent of the machine. The general process of transforming a complete program into machine-executable object code is as follows: Figure 1 As shown in the diagram, the compilation process is divided into six stages: lexical analysis, syntax analysis, semantic analysis, intermediate code generation, code optimization, and target code generation. The other two important aspects, worksheet management and error handling, are related to the above six stages.

[0052] During the compilation process, various information about the source program is stored in different tables. Each stage of compilation involves constructing, searching, or updating relevant tables, thus requiring table management. If an error is found in the source program during compilation, the compilation process should report the nature and location of the error and limit its impact to the smallest possible extent so that other parts of the source program can continue to be compiled.

[0053] This invention primarily addresses the work performed before generating intermediate code, including determining the execution order and the syntax and semantics checking process.

[0054] Regarding trapezoidal primitives

[0055] Based on their function and classification, the primitives of a ladder diagram are mainly divided into the following categories: Figures 2a-2d As shown:

[0056] 1) The QCoil class, derived from QLd, serves as the base class for all specific coil module classes. It completes the common functions of the coil modules. The specific coils include coil, reverse coil, positive conversion induction coil, negative conversion induction coil, etc.

[0057] 2) The QContact contact class, derived from QLd, serves as the base class for all specific contact module classes. It completes the common functions of the contact modules. The specific contacts include normally open contacts, normally closed contacts, positive changeover sensing contacts, and negative changeover sensing contacts, etc.

[0058] 3) The wall classes on both sides of the QBus ladder diagram programming interface serve as the starting signal position and ending signal receiving position for each line of the ladder diagram program.

[0059] 4) Basic functional modules, directly derived from QLd, include mathematical operation modules such as QAdd, QSub, and QDiv; statistical operation modules such as QMin, QMax, and QAve; and logical operation modules such as QAnd, QOr, and QNot. Other basic functional modules include relational operation modules, data transformation modules, data movement modules, and timer modules, which will not be described in detail here.

[0060] 5) QLine connection class, responsible for connecting modules and transmitting signals from the start of the connection to the module at the end of the connection. Connection class is further divided into three types: horizontal line, left vertical line, and right vertical line.

[0061] a) Horizontal line: such as Figure 2c As shown, the horizontal line connects the output pin to the input pin;

[0062] b) Left vertical line: Input pin connected to input pin;

[0063] c) Right vertical line: Output pin connected to output pin.

[0064] like Figure 2d As shown, the ladder diagram contains primitive classes, which all contain syntax checking functions syntax() and semantic checking functions semantics(). This allows us to call these primitives' own checking functions to perform syntax and language checks during the compilation process.

[0065] Regarding the compilation order of ladder diagrams

[0066] During ladder diagram compilation, the direction of signal transmission is analyzed, and the ladder diagram program is transformed and compiled according to the principle of top-down and left-to-right, thereby converting the ladder diagram program into a program that can run on the underlying embedded hardware. Determining the compilation order is particularly important in this process.

[0067] To avoid the lengthy module type checks and compilation processes of traditional compilation, a syntax check function `syntax()` and a semantic check function `semantics()` were designed to implement the compilation functionality of ladder diagrams. Each module object implements its own compilation function, and unused modules are not compiled, ensuring clear allocation of responsibilities. Through the logical implementation of each function, after writing a correct ladder diagram program, it can be configured and compiled to ensure the correct execution of the ladder diagram program on the hardware.

[0068] Regarding the ladder diagram compilation process

[0069] During ladder diagram compilation, the direction of signal transmission is analyzed, and the ladder diagram program is transformed and compiled according to the principle of top-down and left-to-right, thereby converting the ladder diagram program into a program that can run on the underlying embedded hardware. Determining the compilation order is particularly important in this process.

[0070] The LD program compilation flowchart is as follows: Figure 3 As shown, this invention completes the work before generating the intermediate program, that is, the work before converting LD to LDO.

[0071] The development platform for this invention is Qt. The custom scene class QLdScene is a container for the primitive ladder diagram module QLd and its related derived class objects. All primitives in the ladder diagram are obtained through QLdScene. These primitives include wires, coils, contacts, and functional blocks. All primitive classes are derived from the QLd base class. The QLd design includes primitive sorting, syntax and semantic checking, and pin maintenance. Specific responsibilities for module compilation are assigned to each module class, resulting in clearer division of responsibilities, faster compilation speed, and a smoother user interface.

[0072] Step 1: Links Sorting. First, analyze the direction of signal transmission in the links and sort all the links. The sorting principle is from top to bottom and from left to right. Specifically, start with the left bus and sort the connected elements according to their vertical coordinates from top to bottom. Then, sort the elements 1-6 connected to the right bus from top to bottom. See below. Figure 4 As shown, after compilation, the element numbers in the ladder diagram program indicate the signal transmission order.

[0073] Step 2: Assign numbers to items, that is, assign numbers to graphic elements and sort them according to the numbers;

[0074] The recursive function `analysisExeNo` is a sorting algorithm. For example... Figure 5 As shown, the algorithm is as follows:

[0075] Step 2.1: Determine whether the current graphic element has been assigned a number. If not, proceed with the following steps. If yes, traverse the next graphic element until all graphic elements have been assigned numbers.

[0076] Step 2.2: Process the input pins and determine whether the connections that the input pins depend on have been checked.

[0077] If the inspection has been completed, a number is assigned, the input pin of the current graphic element has been processed, and the process proceeds to the next step.

[0078] If not, then sequentially search for the associated primitives (including the primitives where the associated output pins are located and the primitives where the associated left vertical line is located), and return to step 2.1 to process the associated primitives first.

[0079] Step 2.3: Process the output pins; check whether any dependent connections of the output pins have been checked.

[0080] If the inspection has been completed, assign a number, the output pin of the current graphic element has been processed, and return to step 2.1;

[0081] If not, then sequentially search for the associated primitives (including the primitives where the associated input pins are located and the primitives where the associated right vertical line is located), and return to step 2.1 to process the associated primitives first.

[0082] Step 3, syntax and semantic checks, such as Figure 6 As shown.

[0083] Step 3.1: Module Syntax and Semantics Check. This check covers custom function blocks, system-provided function blocks, coils, wires, and contacts. All these modules are derived from the QLd class and can call the same syntax and semantics check function. The syntax and semantics check is performed based on different types of primitives. For example, for contacts and coils, the syntax check checks if their pins are not empty. The functions involved in the syntax and semantics check are syntax() and semantics().

[0084] The syntax checking process is as follows:

[0085] Iterate through all primitives and perform syntax and semantic checks based on the primitive type. Check if the primitive's input / output pins are empty, if the pin data types match, and if there are any conflicts in the pin parameter names, etc.

[0086] There can be several ladder diagram programs, each containing hundreds or thousands of primitives. Each primitive has its own syntax checking function, which can greatly improve efficiency.

[0087] Step 3.2, the syntax and semantic check process for input pins is as follows: Figure 7 As shown:

[0088] Step 3.2.1: Begin traversing the primitive input pins;

[0089] Step 3.2.2: Determine whether the syntax check of the current input pin has been completed. If it has been completed, return to step 3.2.1 and continue to check the next input pin; if it has not been completed, proceed to the next step.

[0090] Step 3.2.3: Traverse the primitives containing the associated input pins and output pins, and perform a syntax check based on the data type. If an invalid data type is found, output an error message. If a valid data type is found, continue checking whether all associated pins have been checked. If not, continue traversing the next associated primitive; if all are checked, the syntax check is successful.

[0091] Step 3.3, the syntax and semantic check process for the output pins is as follows: Figure 8 As shown:

[0092] Step 3.3.1: Begin traversing the primitive output pins;

[0093] Step 3.3.2: Determine whether the current output pin has completed the syntax check. If it has, return to step 3.3.1 and continue checking the next output pin; if it has not, proceed to the next step.

[0094] Step 3.3.3: Traverse the primitives containing the associated input pins and output pins, and perform a syntax check based on the data type. If an invalid data type is found, output an error message. If a valid data type is found, continue checking whether all associated pins have been checked. If not, continue traversing the next associated primitive; if all are checked, the syntax check is successful.

[0095] In the above, if there is an error in the syntax and semantics check, the compiler will stop compiling after outputting the error message. After the user corrects the error, the syntax and semantics check will be performed again. Only after all the syntax and semantics checks are passed will the actual compilation stage begin. The syntax and semantics check is to ensure that the content passed to the compiler is legal.

[0096] Step 4: If errors are found during the syntax and semantic checks described above, a warning will be given. If no errors are found, the process proceeds to the intermediate program generation stage, generating intermediate files (.do) and .c files. Finally, gcc is called to compile the intermediate program into a machine-readable .o file. This avoids the lengthy module type checks and compilation process in traditional compilation. By using the syntax check function `syntax()` and the semantic check function `semantics()`, each module object can implement its own compilation function. Unused modules are not compiled, resulting in a clear allocation of responsibilities.

[0097] There are many specific ways to implement this invention. The above description is only a preferred embodiment of this invention. It should be noted that for those skilled in the art, several improvements can be made without departing from the principle of this invention, and these improvements should also be considered within the scope of protection of this invention.

Claims

1. A ladder diagram program compilation method based on Qt, characterized in that, Includes the following steps: (1) Obtain all primitive objects in the ladder diagram scene containing left and right buses and vertical lines, wherein the primitives inherit from the base class QLd; (2) First, sort all connections by signal flow, using the following sorting principle: Starting from the left bus, sort the elements connected to the left bus and their connections from top to bottom according to the vertical axis; then sort the elements connected to the right bus and their connections from top to bottom according to the vertical axis. (3) Based on the connection sorting result of step (2), an execution sequence number exeno is assigned to each graphic element by the recursive function analysisExeNo(). The recursive function includes: traversing the input pins of the current graphic element; if the graphic element that the input pin depends on has not been assigned exeno, then recursively calling analysisExeNo() to process the dependent graphic element; after all input dependencies have been processed, an exeno is assigned to the current graphic element. (4) Call the syntax() and semantics() methods of each graphic element in the order of exeno to perform pin-level syntax and semantic checks; (5) After the check passes, intermediate code files .ldo and .c are generated, and gcc is called to compile them into .o object files.

2. The method according to claim 1, characterized in that, The compilation method is based on the Qt framework to achieve cross-platform operation. The same source code can be compiled and executed on Windows and Linux operating systems without modification.

3. The ladder diagram program compilation method based on Qt according to claim 1, characterized in that, The pin-level syntax and semantic check in step (4) includes: Check if the input pin is empty; Recursively check whether the data types of the output pins associated with the input pins are compatible; Check for pin parameter name conflicts.

4. The ladder diagram program compilation method based on Qt according to claim 1, characterized in that, Unused primitives are not included in the compilation process; compilation is performed on demand through the syntax() and semantics() methods implemented by each primitive itself.

5. The ladder diagram program compilation method based on Qt according to claim 1, characterized in that, In step (2), the line sorting prioritizes horizontal lines, followed by left and right perpendicular lines.

6. The ladder diagram program compilation method based on Qt according to claim 1, characterized in that, The intermediate code file .ldo contains primitive execution sequence numbers and pin connection relationships, which are used for subsequent C code generation.

7. A computer device, characterized in that, It includes a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the method of any one of claims 1-6.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method of any one of claims 1-6.

Citation Information

Patent Citations

  • Graphic language cross compiling method and cross compiler

    CN109976760A