Method, device and equipment for compiling and executing PLC ladder diagram program
By translating the PLC ladder diagram program into virtual machine code and obtaining the virtual machine interpreter according to the target operating environment, the problem of low compilation and execution of PLC ladder diagram program in the prior art is solved, and efficient cross-platform compilation and execution are achieved.
Patent Information
- Application Number
- CN202510064920.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, the compilation and execution of PLC ladder diagram programs need to be compiled one by one for different operating systems and chip instruction sets, resulting in low compilation efficiency and execution efficiency.
Cross-platform compilation and execution are achieved by translating the PLC ladder program into an executor based on the virtual machine machine code, and obtaining a matching virtual machine interpreter based on the target operating environment, interpreting and executing the virtual machine machine code.
It improves the compilation efficiency and execution efficiency of PLC ladder diagram programs, avoids the problem of compilation one by one due to different operating environments, and realizes efficient development and execution on different platforms.
Smart Images

Figure CN119883281A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device and equipment for compiling and executing a PLC ladder diagram program. Background Art
[0002] In the process of developing the PLC ladder diagram program, the PLC ladder diagram program is compiled based on the operating environment to realize the execution of the PLC ladder diagram program in the specified operating environment.
[0003] However, in the related art, the compilation and execution of the PLC ladder diagram program needs to be compiled one by one for different operating systems and different chip instruction sets, which greatly reduces the compilation efficiency and execution efficiency of the PLC ladder diagram program. Summary of the invention
[0004] The present invention provides a method, device, equipment and storage medium for compiling and executing a PLC ladder diagram program, which are used to improve the compiling efficiency and execution efficiency of the PLC ladder diagram program.
[0005] In a first aspect, the present invention provides a method for compiling and executing a PLC ladder diagram program, the method comprising: Based on compiling a preset PLC ladder diagram program, a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program is obtained; Determine the target operating environment of the PLC ladder diagram program, obtain the target virtual machine interpreter that matches the target operating environment, and interpret and execute the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter.
[0006] In a second aspect, the present invention provides a compiling and executing device for a PLC ladder diagram program, the device comprising: A compiling module, for compiling a preset PLC ladder diagram program to obtain a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program; An execution module is used to determine the target operating environment of the PLC ladder diagram program, obtain a target virtual machine interpreter that matches the target operating environment, and interpret and execute the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter.
[0007] In a third aspect, the present invention provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the above steps when executing the computer program.
[0008] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the above steps when executed by a processor.
[0009] In the technical solution provided by the present invention, firstly, based on the translation and compilation of the preset PLC ladder diagram program, a PLC execution program based on the virtual machine machine code is obtained, so that the universality of the PLC ladder diagram program based on the compilation expression level is realized according to the virtual machine machine code; secondly, the target operating environment of the PLC ladder diagram program is determined, and the target virtual machine interpreter matching the target operating environment is obtained, and then based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter, the PLC execution program based on the virtual machine machine code is interpreted and executed, so that the environmental applicability of the PLC ladder diagram program in the interpretation process and the execution process is realized based on the specified operating environment; based on this, there is no need to compile the PLC ladder diagram program one by one according to different operating environments, and only the virtual machine interpreter needs to be environmentally adapted based on different operating environments, so that the compilation and execution of the virtual machine machine code corresponding to the PLC ladder diagram program in different operating environments can be efficiently realized, thereby improving the compilation efficiency and execution efficiency of the PLC ladder diagram program. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 A schematic diagram of an embodiment of a method for compiling and executing a PLC ladder diagram program in an embodiment of the present invention; Figure 2 It is another embodiment schematic diagram of the method for compiling and executing a PLC ladder diagram program in an embodiment of the present invention; Figure 3 The figure is a schematic diagram of an embodiment of a device for compiling and executing a PLC ladder diagram program in an embodiment of the present invention. DETAILED DESCRIPTION
[0011] The embodiment of the present invention provides a method, device, equipment and storage medium for compiling and executing a PLC ladder diagram program, which is used to improve the compiling efficiency and execution efficiency of the PLC ladder diagram program. The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described here can be implemented in an order other than the content illustrated or described here. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0012] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 In an embodiment of the present invention, a method for compiling and executing a PLC ladder diagram program is provided. The method is described by taking the application of the method to a terminal or a server as an example. The method includes steps S101 to S102.
[0013] S101. Based on the compilation of a preset PLC ladder diagram program, a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program is obtained.
[0014] Among them, PLC (Programmable Logic Controller) is a digital industrial control device used to control various mechanical or system equipment in the field of industrial automation; PLC ladder diagram program is a PLC workflow diagram drawn manually or by computer equipment; PLC execution program is a software program compiled from PLC ladder diagram program, running on PLC equipment, used to perform specific control tasks, and can be represented in machine code form or virtual machine machine code form.
[0015] Among them, a virtual machine is a software-simulated computer system that provides a virtual operating environment for running virtualized programs so that the programs can run on different hardware platforms without modification; the virtual machine machine code is a low-level instruction set designed for the virtual machine, which can be converted by the virtual machine through an interpreter or a just-in-time compiler into operations executable by the actual hardware.
[0016] Exemplarily, after the PLC ladder diagram program is written by a high-level language or a graphical tool (such as a ladder diagram, a function block diagram, etc.), a written PLC ladder diagram program is obtained, and then the written PLC ladder diagram program is converted into a low-level instruction set, which is a machine code for the virtual machine to run, rather than instructions directly for physical hardware.
[0017] Optionally, the PLC ladder diagram program can be written by a high-level language or a graphical tool (such as a ladder diagram, a function block diagram, etc.) to obtain a written PLC ladder diagram program, and then the written PLC ladder diagram program can be converted into an intermediate virtual machine language script, and then the intermediate virtual machine language script can be compiled into a virtual machine low-level instruction set.
[0018] S102, determining the target operating environment of the PLC ladder diagram program, obtaining a target virtual machine interpreter that matches the target operating environment, and interpreting and executing a PLC execution program based on the virtual machine machine code based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter.
[0019] Among them, the target operating environment of the PLC ladder diagram program represents the environment that supports the operation of the PLC executive program; the target operating environment of the PLC ladder diagram program can represent the hardware environment that supports the operation of the PLC executive program, such as the chip instruction set, which defines the executable instructions based on the configured chip at the hardware level; the target operating environment of the PLC ladder diagram program can also represent the software environment that supports the operation of the PLC executive program, such as the operating system, which defines the system resources based on the configured operating system at the software level.
[0020] The target virtual machine interpreter refers to a program that reads, interprets, and executes the virtual machine code to convert the virtual machine code into operations that can be executed on the target operating environment.
[0021] Exemplarily, parsing logic, rules or algorithms for interpreting and executing virtual machine code can be configured in the virtual machine interpreter based on the data content, structural characteristics and other information of the virtual machine code, so that the virtual machine interpreter can gradually identify the virtual machine code according to the corresponding interpretation logic.
[0022] In an embodiment of the present invention, firstly, based on the translation and compilation of a preset PLC ladder diagram program, a PLC execution program based on a virtual machine machine code is obtained, thereby realizing the universality of the PLC ladder diagram program based on the compilation expression level according to the virtual machine machine code; secondly, the target operating environment of the PLC ladder diagram program is determined, and by obtaining a target virtual machine interpreter that matches the target operating environment, the PLC execution program based on the virtual machine machine code is interpreted and executed based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter, thereby realizing the environmental applicability of the PLC ladder diagram program in the interpretation process and the execution process based on the specified operating environment; based on this, there is no need to compile the PLC ladder diagram program one by one according to different operating environments, and only the virtual machine interpreter needs to be environmentally adapted based on different operating environments, so that the compilation and execution of the virtual machine code corresponding to the PLC ladder diagram program in different operating environments can be efficiently realized, thereby improving the compilation efficiency and execution efficiency of the PLC ladder diagram program.
[0023] See also Figure 2 In another embodiment of the method for compiling and executing a PLC ladder diagram program in an embodiment of the present invention, based on compiling a preset PLC ladder diagram program, a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program is obtained, including steps S201 to S202.
[0024] S201. Based on a preset intermediate virtual machine development language, the PLC ladder diagram program is translated to obtain an intermediate virtual machine development language script corresponding to the PLC ladder diagram program.
[0025] Among them, the intermediate virtual machine development language represents a high-level scripting language for virtual machine execution, which is between the PLC ladder diagram programming language and the underlying machine code. It describes the program logic through the intermediate representation so that it can be subsequently compiled into machine-recognizable code.
[0026] Among them, the intermediate virtual machine development language script represents a script file based on the virtual machine, which is written in the intermediate virtual machine development language and can be directly interpreted by the virtual machine or further compiled into machine code for execution.
[0027] Exemplarily, a set of intermediate virtual machine development languages and their grammatical rules are designed in advance. This language should have the ability to describe the logic of the PLC ladder diagram program, such as input / output processing, logical operations, and timer and counter functions; the PLC ladder diagram program is parsed into a corresponding logical structure according to the grammatical rules of the intermediate virtual machine development language, and then the logical structure is translated into a script that conforms to the grammatical rules of the intermediate virtual machine development language.
[0028] Exemplarily, the intermediate virtual machine development language may represent an interpreted language such as Lua, Python, or other scripting languages that support hardware resources, or may represent a self-developed intermediate language.
[0029] S202. Based on a preset machine code compilation logic, the intermediate virtual machine development language script is compiled to obtain a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program.
[0030] Among them, the machine code compilation logic represents a set of rules or algorithms for translating high-level languages or intermediate representations (such as intermediate virtual machine development languages) into low-level machine codes. After compilation, the instructions can be directly run on the virtual machine.
[0031] Exemplarily, an intermediate virtual machine development language script is read, and according to the grammatical semantic rules of the intermediate virtual machine development language and the machine code compilation logic, the high-level structure in the intermediate virtual machine development language script is parsed into a low-level operation instruction set one by one, so as to output a PLC execution program based on the virtual machine machine code represented by binary code.
[0032] Optionally, the translation process of the PLC ladder diagram program based on the intermediate virtual machine development language may be skipped, and the PLC execution program based on the virtual machine machine code may be directly compiled from the PLC ladder diagram program.
[0033] In the embodiments of the present invention, on the one hand, based on the intermediate virtual machine development language, the PLC ladder diagram program is translated into an intermediate virtual machine development language script, which provides a standardized and modular representation and improves the portability and code reusability of the PLC ladder diagram program; on the other hand, based on the machine code compilation logic, the intermediate virtual machine development language script is compiled into a PLC execution program based on the virtual machine machine code, and the generated PLC execution program based on the virtual machine machine code has cross-platform capabilities, further improving the portability and code reusability of the PLC ladder diagram program.
[0034] In another embodiment of the method for compiling and executing a PLC ladder diagram program in an embodiment of the present invention, the PLC ladder diagram program is translated based on a preset intermediate virtual machine development language to obtain an intermediate virtual machine development language script corresponding to the PLC ladder diagram program, including steps S301 to S302.
[0035] S301. Based on the syntax analysis of the PLC ladder diagram program, determine the various logical structures of the PLC ladder diagram program.
[0036] Exemplarily, the grammatical structure in the PLC ladder diagram program code is analyzed to understand its code composition and format, and the various logical structures in the PLC ladder diagram program code are identified and extracted, such as logical function modules such as logical AND / OR operations, conditional judgments, and loop structures.
[0037] S302, converting each logical structure of the PLC ladder diagram program into an expression based on the intermediate virtual machine development language, and obtaining an intermediate virtual machine development language script corresponding to the PLC ladder diagram program.
[0038] Exemplarily, each logical structure of the PLC ladder diagram program is mapped to an expression corresponding to the intermediate virtual machine development language. For example, the "logical and / or" operation is mapped to a Boolean operation expression of the intermediate virtual machine development language, and the loop structure is converted into a loop control expression of the intermediate virtual machine development language. Based on this, by traversing each logical structure of the PLC ladder diagram program, the intermediate virtual machine development language script corresponding to the PLC ladder diagram program is gradually generated.
[0039] In an embodiment of the present invention, in the process of converting the logic of a PLC-specific language into a universal expression of an intermediate virtual machine development language, the logical structure of the PLC ladder diagram program is parsed by parsing the syntax of the PLC ladder diagram program, and the program is understood in a modular manner, providing a basis for subsequent optimization and translation, and then the various logical structures of the PLC ladder diagram program are converted into expressions based on the intermediate virtual machine development language, thereby improving the accuracy of language translation.
[0040] In another embodiment of the method for compiling and executing a PLC ladder diagram program in an embodiment of the present invention, based on a preset machine code compilation logic, an intermediate virtual machine development language script is compiled to obtain a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program, including steps S401 to S402.
[0041] S401. Determine each statement structure of the intermediate virtual machine development language script based on a syntax analysis of the intermediate virtual machine development language script.
[0042] Exemplarily, according to the grammatical rules of the intermediate virtual machine development language, the intermediate virtual machine development language script is subjected to grammatical analysis, and the contents and structures of various statements in the intermediate virtual machine development language script are gradually decomposed. For example, the statement contents in the intermediate virtual machine development language script are first identified and classified, such as identifying and classifying different statement contents such as variable definitions, operation instructions, and logical judgments, and then further identifying and parsing the hierarchical structure relationship between different statement contents and within the same statement.
[0043] S402, converting each text structure of the intermediate virtual machine development language script into an expression based on machine code compilation logic, and obtaining a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program.
[0044] Exemplarily, based on the machine code compilation logic, the content and structure of each statement of the intermediate virtual machine development language script are gradually converted into the expression of the machine code compilation logic. For example, the assignment operation in the intermediate virtual machine development language script is converted into the memory operation instruction in the virtual machine, and the loop structure in the intermediate virtual machine development language script is converted into the jump instruction in the virtual machine.
[0045] In an embodiment of the present invention, in the process of converting the intermediate virtual machine development language into a universal expression of the virtual machine machine code, based on the syntax analysis of the intermediate virtual machine development language script, the various statement structures of the intermediate virtual machine development language script are efficiently and accurately determined, and then the various statement structures of the intermediate virtual machine development language script are respectively converted into expressions based on the machine code compilation logic, so as to efficiently and accurately obtain the PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program; based on this, the operation logic, instruction calls and other contents in the intermediate virtual machine development language script are efficiently and accurately mapped to the operation mechanism of the virtual machine.
[0046] In another embodiment of the compilation and execution method of the PLC ladder diagram program in the embodiment of the present invention, the target operating environment includes a target operating system and a target chip instruction set, a target virtual machine interpreter matching the target operating environment is obtained, and based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter, a PLC execution program based on the virtual machine machine code is interpreted and executed, including step S501.
[0047] S501, obtaining a target virtual machine interpreter that matches the target operating system and the target chip instruction set, and interpreting and executing a PLC execution program based on the virtual machine machine code based on the target virtual machine interpreter.
[0048] Among them, the target operating system refers to the operating system that supports the operation of the PLC execution program compiled from the PLC ladder diagram program; the target chip instruction set refers to the chip instruction set that supports the operation of the PLC execution program.
[0049] Exemplarily, a target virtual machine interpreter that matches the target operating system and the target chip instruction set may represent a program that can read, interpret, and execute virtual machine machine code to convert the virtual machine code into operations that can be executed simultaneously on the target operating system and the target chip instruction set.
[0050] In an embodiment of the present invention, in a target operating environment, a target virtual machine interpreter based on a target operating system and a target chip instruction set that match the same is interpreted and executed, thereby achieving environmental applicability of the PLC ladder diagram program for interpretation and execution in a specified operating system and a specified chip instruction set.
[0051] In another embodiment of the method for compiling and executing a PLC ladder diagram program in the embodiment of the present invention, before obtaining the target virtual machine interpreter that matches the target operating environment, the method further includes steps S601 to S602.
[0052] S601. In different operating systems and different chip instruction sets, different operating environment combination pairs are obtained according to each operating system and the chip instruction set matched to each operating system.
[0053] Exemplarily, a list of available operating systems and a list of chip instruction sets are collected, and the chip instruction sets supported by each operating system are analyzed, so that the chip instruction set supported by any operating system is used as the chip instruction set that matches the operating system, thereby forming an operating environment combination pair with any operating system and the matching chip instruction set.
[0054] Exemplarily, the operating system may represent desktop operating systems such as Windows, MacOS, and Linux, mobile operating systems such as Android, IOS, and HarmonyOS, or embedded operating systems such as RTOS.
[0055] Exemplarily, the chip instruction set may represent the x86 instruction set for Intel and AMD processors, the ARM instruction set for mobile devices, the RISC-V instruction set for open source and modular design, or the LoongISA instruction set for Loongson processors.
[0056] S602: Obtain an initial virtual machine interpreter, and determine virtual machine interpreters corresponding to each operating environment combination pair based on the initial virtual machine interpreter according to differences between different operating environment combination pairs.
[0057] The initial virtual machine interpreter refers to a virtual machine interpreter in an initial state that is not written for a specified operating environment.
[0058] Exemplarily, first, based on the structure of the initial virtual machine interpreter, the coupling points between the initial virtual machine interpreter and each operating system and each chip instruction set are determined, such as the system call processing method or the underlying instruction translation logic; secondly, based on different operating environment combination pairs, the coupling points of the initial virtual machine interpreter are modified in a targeted manner, for example, the initial virtual machine interpreter is adjusted in functions such as file management and process scheduling to adapt to the execution logic of different operating systems and different chip instruction sets; finally, based on the adjustment and modification of the initial virtual machine interpreter, a suitable virtual machine interpreter is generated for each operating environment combination pair.
[0059] In the embodiment of the present invention, based on different operating systems and different chip instruction sets, a customized and adapted virtual machine interpreter is combined for each operating environment, so that the virtual machine machine code can be interpreted and executed by different versions of virtual machine interpreters, thereby improving the flexibility and adaptability of PLC ladder diagram programs in developing and executing on different platforms, and greatly reducing development costs.
[0060] In another embodiment of the compilation and execution method of the PLC ladder diagram program in the embodiment of the present invention, a target virtual machine interpreter matching the target operating environment is obtained, and based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter, a PLC execution program based on the virtual machine machine code is interpreted and executed, including steps S701 to S702.
[0061] S701. Obtain a PLC controller corresponding to the target operating environment, and load the target virtual machine interpreter into the PLC controller.
[0062] Exemplarily, according to the performance characteristics and resource configuration of the target operating environment, the PLC controller is adapted to obtain a PLC controller corresponding to the target operating environment; a target virtual machine interpreter suitable for the target operating environment is obtained, and the target virtual machine interpreter is downloaded to the storage of the PLC controller through a specified communication method (such as wired communication, wireless communication, etc.).
[0063] S702: Based on the target virtual machine interpreter, interpret and execute the PLC execution program based on the virtual machine machine code in the PLC controller.
[0064] Exemplarily, based on the virtual machine interpreter loaded into the PLC controller, a PLC execution program based on the virtual machine machine code is parsed and executed. During this operation, the received virtual machine machine code is gradually identified by the virtual machine interpreter and interpreted as instructions that can be directly executed by the PLC controller.
[0065] In an embodiment of the present invention, a virtual machine interpreter is loaded into a PLC controller and a PLC execution program based on a virtual machine machine code is interpreted and executed, that is, different virtual machine machine codes can be run on the same type of controller through a virtual machine interpreter without the need to develop hardware adaptation codes separately for different tasks or systems, thereby reducing development complexity and cost.
[0066] Based on the same inventive concept, an embodiment of the present invention further provides a PLC ladder program compiling and executing device for implementing the above-mentioned PLC ladder program compiling and executing method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in the embodiments of the compiling and executing device for one or more PLC ladder programs provided below can refer to the limitations of the compiling and executing method for PLC ladder programs above, and will not be repeated here.
[0067] In some embodiments, see Figure 3 In an embodiment of the present invention, a compiling and executing device for a PLC ladder diagram program is provided, including a compiling module 301 and an executing module 302 .
[0068] The compiling module 301 is used to compile a preset PLC ladder diagram program to obtain a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program.
[0069] The execution module 302 is used to determine the target operating environment of the PLC ladder diagram program, obtain the target virtual machine interpreter that matches the target operating environment, and interpret and execute the PLC execution program based on the virtual machine machine code based on the parsing logic corresponding to the virtual machine machine code in the target virtual machine interpreter.
[0070] In some embodiments, the compilation module 301 is also used to: translate the PLC ladder diagram program based on a preset intermediate virtual machine development language to obtain an intermediate virtual machine development language script corresponding to the PLC ladder diagram program; compile the intermediate virtual machine development language script based on a preset machine code compilation logic to obtain a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program.
[0071] In some embodiments, the compilation module 301 is also used to: determine the various logical structures of the PLC ladder diagram program based on the syntax analysis of the PLC ladder diagram program; convert the various logical structures of the PLC ladder diagram program into expressions based on the intermediate virtual machine development language, and obtain the intermediate virtual machine development language script corresponding to the PLC ladder diagram program.
[0072] In some embodiments, the compilation module 301 is also used to: determine the various text structures of the intermediate virtual machine development language script based on the syntax analysis of the intermediate virtual machine development language script; convert the various text structures of the intermediate virtual machine development language script into expressions based on machine code compilation logic, and obtain a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program.
[0073] In some embodiments, the execution module 302 is further used to: obtain a target virtual machine interpreter that matches the target operating system and the target chip instruction set, and interpret and execute a PLC execution program based on the virtual machine machine code based on the target virtual machine interpreter.
[0074] In some embodiments, the device also includes a determination module, which is also used to: obtain different operating environment combination pairs in different operating systems and different chip instruction sets according to each operating system and the chip instruction set that matches each operating system respectively; obtain the initial virtual machine interpreter, and determine the virtual machine interpreters corresponding to each operating environment combination pair based on the initial virtual machine interpreter according to the differences between different operating environment combination pairs.
[0075] In some embodiments, the execution module 302 is also used to: obtain a PLC controller corresponding to the target operating environment, load the target virtual machine interpreter into the PLC controller; based on the target virtual machine interpreter, interpret and execute a PLC execution program based on the virtual machine machine code in the PLC controller.
[0076] Each module in the above-mentioned PLC ladder program compilation and execution device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.
[0077] In some embodiments, a computer device is provided, which may be a server. The computer device includes a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data related to the compilation and execution of the PLC ladder diagram program. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, the steps in the above-mentioned defect image generation method are implemented.
[0078] In some embodiments, a computer device is provided, which may be a terminal. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, the steps in the compilation and execution method of the above-mentioned PLC ladder diagram program are implemented. The display unit of the computer device is used to form a visually visible picture, which may be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen; the input device of the computer device can be a touch layer covering the display screen, or a key, trackball or touchpad provided on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0079] In some embodiments, the present invention provides a computer device, which includes a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0080] In some embodiments, the present invention provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above method embodiments are implemented.
[0081] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0082] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0083] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for compiling and executing a PLC ladder diagram program, characterized in that: The method comprises: Based on compiling a preset PLC ladder diagram program, a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program is obtained; Determine the target operating environment of the PLC ladder diagram program, obtain the target virtual machine interpreter that matches the target operating environment, and interpret and execute the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter.
2. The method according to claim 1, characterized in that The method of compiling a preset PLC ladder diagram program to obtain a PLC execution program based on a virtual machine code corresponding to the PLC ladder diagram program includes: Based on a preset intermediate virtual machine development language, the PLC ladder diagram program is translated to obtain an intermediate virtual machine development language script corresponding to the PLC ladder diagram program; Based on the preset machine code compilation logic, the intermediate virtual machine development language script is compiled to obtain a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program.
3. The method according to claim 2, characterized in that The method of translating the PLC ladder diagram program based on the preset intermediate virtual machine development language to obtain the intermediate virtual machine development language script corresponding to the PLC ladder diagram program includes: Based on the syntax analysis of the PLC ladder diagram program, determining each logical structure of the PLC ladder diagram program; Each logical structure of the PLC ladder diagram program is converted into an expression based on the intermediate virtual machine development language to obtain an intermediate virtual machine development language script corresponding to the PLC ladder diagram program.
4. The method according to claim 2, characterized in that: The method of compiling the intermediate virtual machine development language script based on the preset machine code compilation logic to obtain a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program includes: Determine each statement structure of the intermediate virtual machine development language script based on the syntax analysis of the intermediate virtual machine development language script; Each statement structure of the intermediate virtual machine development language script is converted into an expression based on the machine code compilation logic to obtain a PLC execution program based on the virtual machine machine code corresponding to the PLC ladder diagram program.
5. The method according to claim 1, characterized in that The target operating environment includes a target operating system and a target chip instruction set, and obtaining a target virtual machine interpreter that matches the target operating environment, and interpreting and executing the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter, includes: A target virtual machine interpreter that matches the target operating system and the target chip instruction set is obtained, and the PLC execution program based on the virtual machine machine code is interpreted and executed based on the target virtual machine interpreter.
6. The method according to claim 1, characterized in that Before obtaining the target virtual machine interpreter matching the target operating environment, the method further includes: In different operating systems and different chip instruction sets, different operating environment combination pairs are obtained according to each operating system and the chip instruction set matched to each operating system; An initial virtual machine interpreter is obtained, and according to the differences between different operating environment combination pairs, virtual machine interpreters corresponding to each operating environment combination pair based on the initial virtual machine interpreter are determined.
7. The method according to claim 1, characterized in that The step of obtaining a target virtual machine interpreter matched with the target operating environment, and interpreting and executing the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter, comprises: Obtaining a PLC controller corresponding to the target operating environment, and loading the target virtual machine interpreter into the PLC controller; Based on the target virtual machine interpreter, the PLC execution program based on the virtual machine machine code is interpreted and executed in the PLC controller.
8. A compiling and executing device for a PLC ladder diagram program, characterized in that: The device comprises: A compiling module, for compiling a preset PLC ladder diagram program to obtain a PLC execution program based on a virtual machine machine code corresponding to the PLC ladder diagram program; An execution module is used to determine the target operating environment of the PLC ladder diagram program, obtain a target virtual machine interpreter that matches the target operating environment, and interpret and execute the PLC execution program based on the virtual machine code based on the parsing logic corresponding to the virtual machine code in the target virtual machine interpreter.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Compiling method and device of PLC ladder diagram, computer equipment and medium
CN120353468A