A PLC program generation method, device and electronic device for online updating
By compiling and updating WebAssembly code in PLC program, the problem of online update of PLC program is solved, efficient online update of PLC program is achieved, and production costs and downtime are reduced.
Patent Information
- Application Number
- CN202310960437.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2023-07-18
- Filing Date
- 2023-08-01
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2043-08-01
AI Technical Summary
The prior art is difficult to achieve online update of PLC programs, resulting in increased production line downtime, reduced production efficiency and increased costs.
By obtaining the source code of the new version of PLC program, compiling it into WebAssembly code, and adding or replacing the corresponding code blocks in the old version of WebAssembly code, ensuring that the data structure layout of the new version of the code block is consistent with the old version of the code block, thereby realizing online updates.
The online update of PLC programs is realized, reducing production line downtime, improving production efficiency, and reducing production costs.
Smart Images

Figure CN117762466B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the fields of industrial control technology and computer technology, and in particular to a PLC program generation method, device and electronic equipment for online updating. Background Art
[0002] PLC (Programmable Logic Controller) is widely used in the field of industrial control. Industrial PLC is an important component of industrial automation control systems. When running, PLC will continuously read the input signal status, process it according to the logic of the currently running PLC program, and finally output the corresponding results.
[0003] Because it can perform real-time control, management and monitoring data to ensure the accurate operation and efficient performance of the production line, the reliability of PLC has an important impact on the normal operation of the production line and the production efficiency of the enterprise. In modern industrial production, there is a need for continuous upgrading and improvement, so industrial PLC products that support online modification of PLC programs without stopping the machine have high practical value:
[0004] Ensure the continuous operation of the production line: PLC is one of the core technologies in industrial automation control systems. It can monitor and control the operation of industrial equipment to ensure that the equipment always runs in the best condition, thereby ensuring the continuity and stability of the entire production line.
[0005] Reduce industrial downtime: A high-performance, reliable PLC system can detect and repair faults in a timely manner, which will reduce equipment failure rate, reduce downtime, improve production line operation efficiency, and reduce production losses.
[0006] Reduce production costs: Using PLC to control industrial equipment can optimize production processes and reduce production costs. Through real-time monitoring and measurement, PLC can accurately adjust and optimize the production process, thereby improving production efficiency and equipment utilization, and reducing energy consumption and material use. Summary of the invention
[0007] The embodiments of the present application provide a method, device and electronic device for generating a PLC program for online updating, so as to solve the problem of how to generate a PLC program for online updating existing in the prior art.
[0008] The present application embodiment provides a PLC program generation method for online updating, comprising:
[0009] Obtain a new version of the PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0010] Compile the new version PLC program source code into WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0011] The new version code block is added to the old version of the WebAssembly code to obtain the WebAssembly code for updating.
[0012] Furthermore, before adding the new version code block to the old version of WebAssembly code, it also includes:
[0013] Obtaining a data structure layout of the new version code block of the new version WebAssembly code, wherein the data structure layout is allocated for the new version code block in the WebAssembly linear space during the process of compiling the new version PLC program source code;
[0014] If the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, the step of adding the new version code block to the old version WebAssembly code is performed, and the data structure layout of the old version code block is allocated to the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0015] Furthermore, the data structure layout of the new version code block includes: the memory layout of the function block data structure and global variables of the new version code block.
[0016] Furthermore, before adding the new version code block to the old version of WebAssembly code, it also includes:
[0017] Based on identification information of code units in the export information generated in the process of compiling the new version of the PLC program source code, the new version code block is obtained from the new version of the WebAssembly code.
[0018] Furthermore, the new version code block is added to the old version WebAssembly code to obtain the updated WebAssembly code, including:
[0019] After each of the old version code blocks of the old version WebAssembly code, append the new version code block to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0020] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0021] Furthermore, in the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating, including:
[0022] In each of the old version code blocks of the old version WebAssembly code, based on the arrangement position of each of the old version code blocks, the old version code block corresponding to the new version code block is deleted, and the new version code block is added to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating; and according to the offset positions of each of the retained old version code blocks and the new version code blocks included after the replacement, the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code is modified, so as to obtain the function segment corresponding to the WebAssembly code for updating; or
[0023] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0024] The embodiment of the present application also provides a PLC program generation method for online updating, comprising:
[0025] Obtain a new version of the PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0026] Compile the new version PLC program source code into WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0027] Obtaining a data structure layout of the multiple code blocks of the new version of the WebAssembly code, wherein the data structure layout is allocated for the multiple code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code;
[0028] If the data structure layout of the multiple code blocks is consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, it is determined that the new version of the WebAssembly code is the WebAssembly code for updating, and the data structure layout of the old version code blocks is allocated to the old version code blocks in the WebAssembly linear space during the process of compiling the old version of the PLC program source code.
[0029] Furthermore, the data structure layout of the multiple code blocks includes: the memory layout of the function block data structures and global variables of the multiple code blocks.
[0030] Furthermore, it also includes:
[0031] If the data structure layout of the multiple code blocks is not completely consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, the new version code block is added to the old version WebAssembly code to obtain the WebAssembly code for updating.
[0032] Furthermore, the new version code block is added to the old version WebAssembly code to obtain the updated WebAssembly code, including:
[0033] After each of the old version code blocks of the old version WebAssembly code, append the new version code block to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0034] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0035] Furthermore, in the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating, including:
[0036] In each of the old version code blocks of the old version WebAssembly code, based on the arrangement position of each of the old version code blocks, the old version code block corresponding to the new version code block is deleted, and the new version code block is added to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating; and according to the offset positions of each of the retained old version code blocks and the new version code blocks included after the replacement, the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code is modified, so as to obtain the function segment corresponding to the WebAssembly code for updating; or
[0037] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0038] The embodiment of the present application also provides a PLC program generation device for online updating, comprising:
[0039] A first code acquisition module is used to acquire a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0040] a first code compilation module, configured to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0041] The code block adding module is used to add the new version code block to the old version WebAssembly code to obtain the WebAssembly code for updating.
[0042] Furthermore, the first code acquisition module is further used to acquire a data structure layout of the new version code block of the new version WebAssembly code, wherein the data structure layout is allocated for the new version code block in the WebAssembly linear space during the process of compiling the new version PLC program source code;
[0043] The code block adding module is specifically used to execute the step of adding the new version code block in the old version WebAssembly code if the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, and the data structure layout of the old version code block is allocated to the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0044] Furthermore, the data structure layout of the new version code block includes: the memory layout of the function block data structure and global variables of the new version code block.
[0045] Furthermore, the first code acquisition module is also used to acquire the new version code block from the new version of the WebAssembly code based on the identification information of the code unit in the export information generated in the process of compiling the new version of the PLC program source code.
[0046] Further, the code block adding module is specifically used to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0047] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0048] Further, the code block adding module is specifically used to delete the old code block corresponding to the new code block in each of the old code blocks of the old version of the WebAssembly code based on the arrangement position of each of the old code blocks, and add the new code block to the arrangement position of the corresponding old code block to obtain the WebAssembly code for updating; and modify the offset position pointed to by each code block in the function segment corresponding to the old version of the WebAssembly code according to the offset positions of each of the retained old code blocks and the new code blocks included after the replacement, to obtain the function segment corresponding to the WebAssembly code for updating; or
[0049] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0050] The embodiment of the present application also provides a PLC program generation device for online updating, comprising:
[0051] A second code acquisition module is used to acquire a new version of the PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0052] a second code compilation module, configured to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0053] a layout acquisition module, configured to acquire a data structure layout of the plurality of code blocks of the new version of the WebAssembly code, wherein the data structure layout is allocated for the plurality of code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code;
[0054] A code determination module is used to determine that the new version of the WebAssembly code is the WebAssembly code for updating if the data structure layouts of the multiple code blocks are all consistent with the data structure layouts of the old version code blocks corresponding to the multiple code blocks, and the data structure layouts of the old version code blocks are allocated to the old version code blocks in the WebAssembly linear space during the process of compiling the old version of the PLC program source code.
[0055] Furthermore, the data structure layout of the multiple code blocks includes: the memory layout of the function block data structures and global variables of the multiple code blocks.
[0056] Furthermore, the code determination module is also used to add the new version code block to the old version WebAssembly code to obtain the WebAssembly code for updating if the data structure layout of the multiple code blocks is not completely consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block.
[0057] Further, the code determination module is specifically used to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0058] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0059] Further, the code determination module is specifically used to delete the old version code block corresponding to the new version code block in each of the old version code blocks of the old version WebAssembly code based on the arrangement position of each of the old version code blocks, and add the new version code block to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating; and modify the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code according to the offset position of each retained old version code block and the new version code block included after replacement, so as to obtain the function segment corresponding to the WebAssembly code for updating; or
[0060] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0061] An embodiment of the present application also provides an electronic device, including a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to implement any of the above-mentioned PLC program generation methods for online updating.
[0062] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned PLC program generation methods for online updating is implemented.
[0063] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described PLC program generation methods for online updating.
[0064] The beneficial effects of this application include:
[0065] In the method provided in the embodiment of the present application, in the new version of the PLC program source code, some code units of the old version of the PLC program source code are modified, and the modified code units are new version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit, so that after the new version of the PLC source code is compiled into the new version of the WebAssembly code, the new version code blocks therein are compared with the corresponding old version code blocks. The data structure layout of the two can be consistent, so that based on the data structure layout of each old version code block of the old version of the WebAssembly code, the WebAssembly code used for updating can be directly run without recreating the data structure layout for the WebAssembly code, so that the WebAssembly code can be used to achieve online update.
[0066] Other features and advantages of the present application will be described in the subsequent description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0067] The accompanying drawings are used to provide a further understanding of the present application and constitute a part of the specification. Together with the embodiments of the present application, they are used to explain the present application and do not constitute a limitation of the present application. In the accompanying drawings:
[0068] Figure 1 A flowchart of a PLC program generation method for online updating provided in an embodiment of the present application;
[0069] Figure 2 A flowchart of a PLC program generation method for online updating provided in Example 1 of the present application;
[0070] Figure 3 This is a schematic diagram of using a new version code block to replace a corresponding old version code block using the first replacement method in an embodiment of the present application;
[0071] Figure 4 This is a schematic diagram of using a new version code block to replace a corresponding old version code block using the second replacement method in an embodiment of the present application;
[0072] Figure 5 This is a schematic diagram of adding a new version of the code block to the old version of the WebAssembly code using the second adding method in the embodiment of the present application;
[0073] Figure 6 A flowchart of a PLC program generation method for online updating provided by another embodiment of the present application;
[0074] Figure 7 A flowchart of a PLC program generation method for online updating provided in Example 2 of the present application;
[0075] Figure 8 A schematic diagram of the structure of a PLC program generation device for online updating provided in an embodiment of the present application;
[0076] Fig. 9 A schematic diagram of the structure of a PLC program generation device for online updating provided by another embodiment of the present application;
[0077] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0078] In order to provide an implementation scheme for generating a PLC program for online updating, the embodiments of the present application provide a method, device and electronic device for generating a PLC program for online updating. The preferred embodiments of the present application are described below in conjunction with the drawings of the specification. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present application, and are not used to limit the present application. In addition, the embodiments and features in the embodiments of the present application can be combined with each other if there is no conflict.
[0079] The present application embodiment provides a PLC program generation method for online updating, such as Figure 1 As shown, including:
[0080] Step 11, obtaining a new version of the PLC program source code, the new version of the PLC program source code includes multiple code units, the multiple code units correspond one to one with the multiple old version code units included in the old version of the PLC program source code, some of the multiple code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0081] Step 12: compile the new version of the PLC program source code into the WebAssembly code, as the new version of the WebAssembly code, the new version of the WebAssembly code includes multiple code blocks corresponding to the multiple code units one by one, the code blocks corresponding to the new version of the code unit are the new version of the code blocks, and the multiple code blocks correspond to the multiple old version of the code blocks included in the old version of the WebAssembly code one by one, and the old version of the WebAssembly code is obtained by compiling the old version of the PLC program source code;
[0082] Step 13: Add the new version code block to the old version of the WebAssembly code to obtain the updated WebAssembly code.
[0083] The above-mentioned embodiment provided by the present application Figure 1 The method shown modifies some code units of the old version of the PLC program source code in the new version of the PLC program source code, and the modified code units are new version code units, and the interfaces of the new version code units are consistent with the interfaces of the corresponding old version code units, so that after the new version of the PLC source code is compiled into the new version of the WebAssembly code, the new version code blocks therein are compared with the corresponding old version code blocks, and the data structure layout of the two can be consistent, so that based on the data structure layout of each old version code block of the old version of the WebAssembly code, the WebAssembly code used for updating can be directly run without recreating the data structure layout for the WebAssembly code, so that the WebAssembly code can be used to achieve online update.
[0084] Embodiment 1:
[0085] Embodiment 1 of the present application provides a PLC program generation method for online updating, such as Figure 2 As shown, the following steps are included:
[0086] Step 21: Get the new version of PLC program source code.
[0087] In the application of PLC technology, when updating a PLC program, the PLC program source code is often updated to obtain a new version of the PLC program source code, and the new version of the PLC program source code is compiled to obtain the PLC program for updating.
[0088] In the present application embodiment, Figure 3 As shown, the old version of the PLC program source code includes multiple old version code units, and the new version of the PLC program source code includes multiple code units, and the multiple code units correspond one-to-one to the multiple old version code units included in the old version of the PLC program source code, and some of the multiple code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interfaces of the new version code units are consistent with the interfaces of the corresponding old version code units.
[0089] In the embodiment of the present application, the old version PLC program source code and the new version PLC program source code may include various types of code units, for example, Figure 3 As shown, a code unit can be a function or a function block.
[0090] In the embodiment of the present application, the interface of the new version code unit is consistent with the interface of the corresponding old version code unit, including the name and type of the interface.
[0091] Step 22: compile the new version of the PLC program source code into the WebAssembly code as the new version of the WebAssembly code.
[0092] like Figure 3 As shown, the new version of WebAssembly code includes multiple code blocks corresponding to multiple code units one by one, and the code block corresponding to the new version code unit is the new version code block. The multiple code blocks correspond one by one to multiple old version code blocks included in the old version of WebAssembly code. The old version of WebAssembly code is obtained by compiling the old version of PLC program source code.
[0093] In the process of compiling the new version of the PLC program source code into the WebAssembly code, a data structure layout will be allocated in the WebAssembly linear space for each code block contained in the new version of the WebAssembly code, including the data structure layout allocated for the new version of the code block.
[0094] In the embodiment of the present application, the data structure layout allocated to the new version code block may include: the function block data structure of the new version code block and the memory layout of the global variables.
[0095] Step 23: Get the data structure layout of the new version of the code block of the new version of the WebAssembly code.
[0096] In this step, specifically, a memory layout description file outputted in the process of compiling the new version of the PLC program source code into the WebAssembly code can be obtained, from which the function block data structure of the new version of the code block can be obtained.
[0097] You can also obtain the map file or memory layout file output in the process of compiling the new version of the PLC program source code into the WebAssembly code, and obtain the memory layout of the global variables of the new version of the code block from it.
[0098] Step 24: Determine whether the data structure layout of the new version code block of the new version WebAssembly code is consistent with the data structure layout of the old version code block corresponding to the new version code block. If they are consistent, execute step 25.
[0099] In the embodiment of the present application, the data structure layout of the old version code block is allocated for the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0100] Accordingly, in this step, it can be specifically determined whether the function block data structure layout of the new version code block is consistent with the function block data structure layout of the old version code block corresponding to the new version code block, for example, whether the names and offset positions of the fields included in the function block data structure are consistent.
[0101] In this step, it is also possible to determine whether the memory layout of the global variables of the new version code block is consistent with the memory layout of the global variables of the old version code block corresponding to the new version code block. For example, it is determined whether the corresponding offset positions of the same global variable symbol name in the new version code block and the old version code block are consistent.
[0102] In actual applications, when compiling a new version of the PLC program source code, compared to compiling an old version of the PLC program source code, the compilation environment may change. For example, the compiler version may be different, or the physical machine to which the compiler belongs may change. This may cause the data structure layout of the obtained new version of the code block to be inconsistent with the data structure layout of the old version of the code block corresponding to the new version of the code block. Even if the interface of the new version of the code unit is consistent with the interface of the corresponding old version of the code unit, there may be an inconsistency in the data structure layout.
[0103] In an embodiment of the present application, if the data structure layout of the new version code block of the new version WebAssembly code is inconsistent with the data structure layout of the old version code block corresponding to the new version code block, it means that the new version code block cannot be run based on the data structure layout of the old version code block, that is, the online update of the PLC program cannot be achieved. At this time, the process of generating the PLC program for online update can be terminated.
[0104] If it can be determined that the compilation environment for compiling the new version of the PLC program source code and the old version of the PLC program source code remains unchanged, the above steps 23 and 24 can be canceled.
[0105] Step 25: Based on the identification information of the code unit in the export information generated in the process of compiling the new version of the PLC program source code, obtain the new version of the code block from the new version of the WebAssembly code.
[0106] Step 26: Add the new version code block to the old version of the WebAssembly code to obtain the updated WebAssembly code.
[0107] In this step, you can use the following two methods to add the new version of the code block to the old version of the WebAssembly code:
[0108] The first adding method: In the old version of WebAssembly code, use the new version of the code block to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0109] Specifically, the following two replacement methods may be included:
[0110] The first replacement method: Figure 3 As shown, in each old version code block of the old version WebAssembly code, based on the arrangement position of each old version code block, the old version code block corresponding to the new version code block is deleted, and the new version code block is added to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating;
[0111] According to the offset positions of the retained old version code blocks and the new version code blocks included after the replacement, the offset positions pointed to by each code block are modified in the function segment corresponding to the old version of the WebAssembly code, so as to obtain the function segment corresponding to the WebAssembly code for updating, and the function segment is used to run the obtained WebAssembly code for updating.
[0112] The second replacement method: Figure 4As shown, the new version code blocks and the old version code blocks of the old version of the WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks;
[0113] Use the new version of the text code block to replace the corresponding old version of the text code block to obtain the text code for updating in text format;
[0114] The text code for updating is compiled into a WebAssembly code to obtain the WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0115] The second way to add: Figure 5 As shown, after each old version code block of the old version WebAssembly code, the new version code block is appended to obtain the WebAssembly code for updating;
[0116] The index of the old version code block in the function section corresponding to the old version WebAssembly code is modified to point to the offset position of the corresponding new version code block, thereby obtaining the function section corresponding to the updated WebAssembly code, which is used to run the updated WebAssembly code;
[0117] Among them, the function section corresponding to the old version of WebAssembly code is generated in the process of compiling the old version of PLC program source code, and is used to run the compiled old version of WebAssembly code.
[0118] The present application also provides a method for generating a PLC program for online updating, such as Figure 6 As shown, including:
[0119] Step 61, obtaining a new version of the PLC program source code, the new version of the PLC program source code includes a plurality of code units, the plurality of code units correspond one to one with a plurality of old version code units included in the old version of the PLC program source code, some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0120] Step 62: compile the new version PLC program source code into WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes multiple code blocks corresponding to multiple code units one by one, the code blocks corresponding to the new version code units are new version code blocks, and the multiple code blocks correspond to multiple old version code blocks included in the old version WebAssembly code one by one, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0121] Step 63: Obtain a data structure layout of multiple code blocks of the new version of the WebAssembly code, where the data structure layout is allocated for the multiple code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code;
[0122] Step 64: If the data structure layouts of the multiple code blocks are all consistent with the data structure layouts of the old version code blocks corresponding to the multiple code blocks, it is determined that the new version of the WebAssembly code is the WebAssembly code for updating, and the data structure layouts of the old version code blocks are allocated to each old version code block in the WebAssembly linear space during the process of compiling the old version of the PLC program source code.
[0123] The above-mentioned embodiment provided by the present application Figure 6 The method shown modifies some code units of the old version of the PLC program source code in the new version of the PLC program source code, and the modified code units are new version code units, and the interfaces of the new version code units are consistent with the interfaces of the corresponding old version code units, so that after the new version of the PLC source code is compiled into the new version of the WebAssembly code, the new version code blocks therein are compared with the corresponding old version code blocks. The data structure layout of the two can be consistent. Furthermore, it is verified that the data structure layout of multiple code blocks of the new version of the WebAssembly code is consistent with the data structure layout of each old version code block corresponding to the multiple code blocks, so that the WebAssembly code for updating can be directly run based on the data structure layout of each old version code block of the old version of the WebAssembly code, without the need to recreate the data structure layout for the WebAssembly code, so that the WebAssembly code can be used to achieve online update.
[0124] Embodiment 2:
[0125] Embodiment 2 of the present application provides a PLC program generation method for online updating, such as Figure 7 As shown, the following steps are included:
[0126] Step 71: Obtain the new version of the PLC program source code.
[0127] In the application of PLC technology, when updating a PLC program, the PLC program source code is often updated to obtain a new version of the PLC program source code, and the new version of the PLC program source code is compiled to obtain the PLC program for updating.
[0128] In an embodiment of the present application, the old version PLC program source code includes multiple old version code units, and the new version PLC program source code includes multiple code units, which correspond one-to-one to the multiple old version code units included in the old version PLC program source code, and some of the multiple code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit.
[0129] In the embodiment of the present application, the old version PLC program source code and the new version PLC program source code may include various types of code units. For example, the code unit may be a function or a function block.
[0130] In the embodiment of the present application, the interface of the new version code unit is consistent with the interface of the corresponding old version code unit, including the name and type of the interface.
[0131] Step 72: compile the new version of the PLC program source code into the WebAssembly code as the new version of the WebAssembly code.
[0132] The new version of WebAssembly code includes multiple code blocks corresponding to multiple code units one by one. The code blocks corresponding to the new version code units are new version code blocks. The multiple code blocks correspond one by one to multiple old version code blocks included in the old version of WebAssembly code. The old version of WebAssembly code is obtained by compiling the old version of PLC program source code.
[0133] In the process of compiling the new version of the PLC program source code into the WebAssembly code, a data structure layout will be allocated in the WebAssembly linear space for each code block contained in the new version of the WebAssembly code, including the data structure layout allocated for the new version of the code block.
[0134] In the embodiment of the present application, the data structure layout allocated to the multiple code blocks may include: the memory layout of the function block data structures and global variables of the multiple code blocks.
[0135] Step 73: Obtain the data structure layout of multiple code blocks of the new version of the WebAssembly code.
[0136] In this step, specifically, a memory layout description file outputted in the process of compiling the new version of the PLC program source code into the WebAssembly code can be obtained, from which the function block data structure of the new version of the code block can be obtained.
[0137] You can also obtain the map file or memory layout file output in the process of compiling the new version of the PLC program source code into the WebAssembly code, and obtain the memory layout of the global variables of the new version of the code block from it.
[0138] Step 74: Determine whether the data structure layouts of the multiple code blocks of the new version of the WebAssembly code are all consistent with the data structure layouts of the old version of the code blocks corresponding to the multiple code blocks. If they are all consistent, execute step 75; if they are not all consistent, execute step 76.
[0139] In the embodiment of the present application, the data structure layout of the old version code block is allocated for the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0140] Accordingly, in this step, it can be specifically determined whether the function block data structure layout of multiple code blocks of the new version of the WebAssembly code is consistent with the function block data structure layout of each old version of the code blocks corresponding to the multiple code blocks, for example, whether the names and offset positions of each field included in the function block data structure are consistent.
[0141] In this step, it is also possible to determine whether the memory layout of the global variables of the multiple code blocks of the new version of the WebAssembly code is consistent with the memory layout of the global variables of the old version code blocks corresponding to the multiple code blocks. For example, it is determined whether the corresponding offset positions of the same global variable symbol name in the code block of the new version of the WebAssembly code and the corresponding old version of the code block are consistent.
[0142] In actual applications, when compiling a new version of the PLC program source code, compared to compiling an old version of the PLC program source code, the compilation environment may change. For example, the compiler version may be different, or the physical machine to which the compiler belongs may change. This may cause the data structure layout of the code block of the obtained new version of the WebAssembly code to be inconsistent with the data structure layout of the corresponding old version of the code block. Even if the interface of each code unit of the new version of the PLC program source code is consistent with the interface of the corresponding old version of the code unit, there may be an inconsistency in the data structure layout.
[0143] Step 75: Determine that the new version of the WebAssembly code is the WebAssembly code for updating.
[0144] When the data structure layout of multiple code blocks of the new version of WebAssembly code is consistent with the data structure layout of each old version of code blocks corresponding to the multiple code blocks, it means that the multiple code blocks of the new version of WebAssembly code can be run based on the data structure layout of the old version of code blocks, so that the online update of the PLC program can be realized. Therefore, in this step, the new version of WebAssembly code can be determined as the WebAssembly code for updating.
[0145] Step 76: Determine whether the data structure layout of the new version code block of the new version WebAssembly code is consistent with the data structure layout of the old version code block corresponding to the new version code block. If they are consistent, execute step 77.
[0146] If the data structure layout of multiple code blocks of the new version of the WebAssembly code is not completely consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of the new version of the code block is consistent with the data structure layout of the old version of the code block corresponding to the new version of the code block, it means that the new version of the code block and the old version of the code block corresponding to the other code blocks can be used together for online update of the PLC program, that is, execute step 77.
[0147] In an embodiment of the present application, if the data structure layout of the new version code block of the new version WebAssembly code is inconsistent with the data structure layout of the old version code block corresponding to the new version code block, it means that the new version code block cannot be run based on the data structure layout of the old version code block, that is, the online update of the PLC program cannot be achieved. At this time, the process of generating the PLC program for online update can be terminated.
[0148] Step 77: Based on the identification information of the code unit in the export information generated in the process of compiling the new version of the PLC program source code, obtain the new version of the code block from the new version of the WebAssembly code.
[0149] Step 78: Add the new version code block to the old version of the WebAssembly code to obtain the WebAssembly code for updating.
[0150] Specifically, this step 78 can be combined with the above Figure 2 The same as step 26 in FIG. 1 is omitted here for further details.
[0151] To achieve online version upgrade, the core problem that needs to be solved is how to realize that the running context-related information of the current program can be transferred to the new version of the program, and be identified and used to resume the execution of the new version of the program. Common methods include implementing context migration between the old and new versions based on symbolic information or using a memory structure specially designed for the application. The present invention proposes a new method that supports the use of a fully compatible memory layout model between the old and new versions. The advantage of this method is that it has better adaptability. The program used for upgrading can support target instructions generated using general compilation technology, as well as target instructions generated by mixed compilation of IEC61131-3 languages and modern computer languages such as C / C++, Rust, etc.
[0152] Based on the same inventive concept, according to the PLC program generation method for online update provided in the above embodiment of the present application, correspondingly, another embodiment of the present application also provides a PLC program generation device for online update, and its structural schematic diagram is shown as follows: Figure 8 As shown, specifically including:
[0153] A first code acquisition module 81 is used to acquire a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0154] A first code compiling module 82 is used to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding to the plurality of code units one-to-one, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond to a plurality of old version code blocks included in the old version WebAssembly code one-to-one, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0155] The code block adding module 83 is used to add the new version code block to the old version WebAssembly code to obtain the WebAssembly code for updating.
[0156] Furthermore, the first code acquisition module 81 is further used to acquire a data structure layout of the new version code block of the new version WebAssembly code, wherein the data structure layout is allocated for the new version code block in the WebAssembly linear space during the process of compiling the new version PLC program source code;
[0157] The code block adding module 83 is specifically used to execute the step of adding the new version code block in the old version WebAssembly code if the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, and the data structure layout of the old version code block is allocated to the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0158] Furthermore, the data structure layout of the new version code block includes: the memory layout of the function block data structure and global variables of the new version code block.
[0159] Furthermore, the first code acquisition module 81 is further configured to acquire the new version code block from the new version WebAssembly code based on identification information of the code unit in the export information generated during the compilation of the new version PLC program source code.
[0160] Further, the code block adding module 83 is specifically used to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0161] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0162] Further, the code block adding module 83 is specifically used to delete the old version code block corresponding to the new version code block in each of the old version code blocks of the old version WebAssembly code based on the arrangement position of each of the old version code blocks, and add the new version code block to the arrangement position of the corresponding old version code block to obtain the WebAssembly code for updating; and modify the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code according to the offset positions of each retained old version code block and the new version code block included after replacement, to obtain the function segment corresponding to the WebAssembly code for updating; or
[0163] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0164] Based on the same inventive concept, according to the PLC program generation method for online update provided in the above embodiment of the present application, correspondingly, another embodiment of the present application also provides a PLC program generation device for online update, and its structural schematic diagram is shown as follows: Fig. 9 As shown, specifically including:
[0165] A second code acquisition module 91 is used to acquire a new version of the PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit;
[0166] A second code compiling module 92 is used to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding to the plurality of code units one-to-one, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond to a plurality of old version code blocks included in the old version WebAssembly code one-to-one, and the old version WebAssembly code is obtained by compiling the old version PLC program source code;
[0167] A layout acquisition module 93 is used to acquire a data structure layout of the multiple code blocks of the new version of the WebAssembly code, wherein the data structure layout is allocated for the multiple code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code;
[0168] The code determination module 94 is used to determine that the new version of the WebAssembly code is the WebAssembly code for updating if the data structure layout of the multiple code blocks is consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of each old version code block is allocated to each old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
[0169] Furthermore, the data structure layout of the multiple code blocks includes: the memory layout of the function block data structures and global variables of the multiple code blocks.
[0170] Furthermore, the code determination module 94 is also used to add the new version code block to the old version WebAssembly code to obtain the WebAssembly code for updating if the data structure layout of the multiple code blocks is not entirely consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block.
[0171] Further, the code determination module 94 is specifically configured to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or
[0172] In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
[0173] Further, the code determination module 94 is specifically used to delete the old version code block corresponding to the new version code block in each of the old version code blocks of the old version WebAssembly code based on the arrangement position of each of the old version code blocks, and add the new version code block to the arrangement position of the corresponding old version code block to obtain the WebAssembly code for updating; and modify the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code according to the offset position of each retained old version code block and the new version code block included after replacement, to obtain the function segment corresponding to the WebAssembly code for updating; or
[0174] The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
[0175] The functions of the above modules can correspond to Figures 1 to 7 The corresponding processing steps in the shown process will not be repeated here.
[0176] The PLC program generation device for online update provided by the embodiment of the present application can be implemented by a computer program. Those skilled in the art should be able to understand that the above module division method is only one of many module division methods. If it is divided into other modules or not divided into modules, as long as the PLC program generation device for online update has the above functions, it should be within the protection scope of the present application.
[0177] The present application also provides an electronic device, such as Fig.10 As shown, it includes a processor 101 and a machine-readable storage medium 102, wherein the machine-readable storage medium 102 stores machine-executable instructions that can be executed by the processor 101, and the processor 101 is prompted by the machine-executable instructions to implement any of the above-mentioned PLC program generation methods for online updating.
[0178] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, any of the above-mentioned PLC program generation methods for online updating is implemented.
[0179] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute any of the above-described PLC program generation methods for online updating.
[0180] The machine-readable storage medium in the electronic device may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the processor.
[0181] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0182] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, electronic device, computer-readable storage medium, and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0183] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0184] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0185] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0186] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A PLC program generation method for online updating, characterized in that: include: Obtain a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit; Compile the new version PLC program source code into WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code; Obtaining a data structure layout of the new version code block of the new version WebAssembly code, wherein the data structure layout is allocated for the new version code block in the WebAssembly linear space during the process of compiling the new version PLC program source code; If the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, the new version code block is added to the old version WebAssembly code to obtain the WebAssembly code for updating. The data structure layout of the old version code block is allocated to the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
2. The method according to claim 1, characterized in that The data structure layout of the new version code block includes: the memory layout of the function block data structure and global variables of the new version code block.
3. The method according to claim 1, characterized in that In the old version of WebAssembly code, before adding the new version code block, it also includes: Based on identification information of code units in the export information generated in the process of compiling the new version of the PLC program source code, the new version code block is obtained from the new version of the WebAssembly code.
4. The method according to claim 1, characterized in that The step of adding the new version code block to the old version of the WebAssembly code to obtain the updated WebAssembly code includes: After each of the old version code blocks of the old version WebAssembly code, append the new version code block to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
5. The method according to claim 4, characterized in that In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating, including: In each of the old version code blocks of the old version WebAssembly code, based on the arrangement position of each of the old version code blocks, the old version code block corresponding to the new version code block is deleted, and the new version code block is added to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating; and according to the offset positions of each of the retained old version code blocks and the new version code blocks included after the replacement, the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code is modified, so as to obtain the function segment corresponding to the WebAssembly code for updating; or The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
6. A PLC program generation method for online updating, characterized in that: include: Obtain a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit; Compile the new version PLC program source code into WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code; Obtaining a data structure layout of the multiple code blocks of the new version of the WebAssembly code, wherein the data structure layout is allocated for the multiple code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code; If the data structure layout of the multiple code blocks is consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, it is determined that the new version of the WebAssembly code is the WebAssembly code for updating, and the data structure layout of the old version code blocks is allocated to the old version code blocks in the WebAssembly linear space during the process of compiling the old version of the PLC program source code.
7. The method according to claim 6, characterized in that The data structure layout of the multiple code blocks includes: the memory layout of the function block data structures and global variables of the multiple code blocks.
8. The method according to claim 6, characterized in that Also includes: If the data structure layout of the multiple code blocks is not completely consistent with the data structure layout of the old version code blocks corresponding to the multiple code blocks, and the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, the new version code block is added to the old version WebAssembly code to obtain the WebAssembly code for updating.
9. The method according to claim 8, characterized in that The step of adding the new version code block to the old version of the WebAssembly code to obtain the updated WebAssembly code includes: After each of the old version code blocks of the old version WebAssembly code, append the new version code block to obtain the WebAssembly code for updating; and modify the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block to obtain the function segment corresponding to the WebAssembly code for updating; or In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
10. The method according to claim 9, characterized in that In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating, including: In each of the old version code blocks of the old version WebAssembly code, based on the arrangement position of each of the old version code blocks, the old version code block corresponding to the new version code block is deleted, and the new version code block is added to the arrangement position of the corresponding old version code block, so as to obtain the WebAssembly code for updating; and according to the offset positions of each of the retained old version code blocks and the new version code blocks included after the replacement, the offset position pointed to by each code block in the function segment corresponding to the old version WebAssembly code is modified, so as to obtain the function segment corresponding to the WebAssembly code for updating; or The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
11. A PLC program generation device for online updating, characterized in that: include: A first code acquisition module is used to acquire a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit; a first code compilation module, configured to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code; The first code acquisition module is further used to acquire a data structure layout of the new version code block of the new version WebAssembly code, wherein the data structure layout is allocated for the new version code block in the WebAssembly linear space during the process of compiling the new version PLC program source code; A code block adding module is used to add the new version code block to the old version WebAssembly code if the data structure layout of the new version code block is consistent with the data structure layout of the old version code block corresponding to the new version code block, so as to obtain the WebAssembly code for updating. The data structure layout of the old version code block is allocated to the old version code block in the WebAssembly linear space during the process of compiling the old version PLC program source code.
12. The device according to claim 11, characterized in that The data structure layout of the new version code block includes: the memory layout of the function block data structure and global variables of the new version code block.
13. The device according to claim 11, characterized in that The first code acquisition module is further used to acquire the new version code block from the new version WebAssembly code based on the identification information of the code unit in the export information generated in the process of compiling the new version PLC program source code.
14. The device according to claim 11, characterized in that The code block adding module is specifically used to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modifying the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block, to obtain the function segment corresponding to the WebAssembly code for updating; or In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
15. The device according to claim 14, characterized in that The code block adding module is specifically used to delete the old code blocks corresponding to the new code blocks in each of the old code blocks of the old WebAssembly code based on the arrangement positions of each of the old code blocks, and add the new code blocks to the arrangement positions of the corresponding old code blocks, so as to obtain the WebAssembly code for updating; and modify the offset positions pointed to by each code block in the function segment corresponding to the old WebAssembly code according to the offset positions of each of the retained old code blocks and the new code blocks included after replacement, so as to obtain the function segment corresponding to the WebAssembly code for updating; or The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
16. A PLC program generation device for online updating, characterized in that: include: A second code acquisition module is used to acquire a new version of a PLC program source code, wherein the new version of the PLC program source code includes a plurality of code units, and the plurality of code units correspond one-to-one to a plurality of old version code units included in the old version of the PLC program source code, and some of the plurality of code units remain unchanged compared to the corresponding old version code units, and the remaining code units are new version code units that are modified compared to the corresponding old version code units, and the interface of the new version code unit is consistent with the interface of the corresponding old version code unit; a second code compilation module, configured to compile the new version PLC program source code into a WebAssembly code as the new version WebAssembly code, wherein the new version WebAssembly code includes a plurality of code blocks corresponding one-to-one to the plurality of code units, the code blocks corresponding to the new version code units are new version code blocks, the plurality of code blocks correspond one-to-one to a plurality of old version code blocks included in the old version WebAssembly code, and the old version WebAssembly code is obtained by compiling the old version PLC program source code; a layout acquisition module, configured to acquire a data structure layout of the plurality of code blocks of the new version of the WebAssembly code, wherein the data structure layout is allocated for the plurality of code blocks in the WebAssembly linear space during the process of compiling the new version of the PLC program source code; A code determination module is used to determine that the new version of the WebAssembly code is the WebAssembly code for updating if the data structure layouts of the multiple code blocks are all consistent with the data structure layouts of the old version code blocks corresponding to the multiple code blocks, and the data structure layouts of the old version code blocks are allocated to the old version code blocks in the WebAssembly linear space during the process of compiling the old version of the PLC program source code.
17. The device according to claim 16, characterized in that The data structure layout of the multiple code blocks includes: the memory layout of the function block data structures and global variables of the multiple code blocks.
18. The device according to claim 16, characterized in that The code determination module is further configured to, if the data structure layouts of the multiple code blocks are not all consistent with the data structure layouts of the old version code blocks corresponding to the multiple code blocks, and the data structure layouts of the new version code blocks are consistent with the data structure layouts of the old version code blocks corresponding to the new version code blocks, add the new version code blocks to the old version WebAssembly code to obtain the WebAssembly code for updating.
19. The device according to claim 18, characterized in that The code determination module is specifically used to append the new version code block after each of the old version code blocks of the old version WebAssembly code to obtain the WebAssembly code for updating; and modifying the index of the old version code block in the function segment corresponding to the old version WebAssembly code to point to the offset position of the corresponding new version code block, to obtain the function segment corresponding to the WebAssembly code for updating; or In the old version of the WebAssembly code, the new version of the code block is used to replace the corresponding old version of the code block to obtain the WebAssembly code for updating.
20. The device according to claim 19, characterized in that The code determination module is specifically configured to delete, based on the arrangement position of each of the old code blocks in the old WebAssembly code, the old code block corresponding to the new code block, and add the new code block to the arrangement position of the corresponding old code block, to obtain the WebAssembly code for updating; and modify the offset position pointed to by each code block in the function segment corresponding to the old WebAssembly code according to the offset positions of each of the retained old code blocks and the new code block included after replacement, to obtain the function segment corresponding to the WebAssembly code for updating; or The new version code block and each of the old version code blocks of the old version WebAssembly code are converted into code blocks in text format to obtain new version text code blocks and old version text code blocks; and the new version text code blocks are used to replace the corresponding old version text code blocks to obtain text code for updating in text format; and the text code is compiled into WebAssembly code to obtain WebAssembly code for updating, and a function segment corresponding to the WebAssembly code for updating is generated.
21. An electronic device, characterized in that: The method comprises a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to implement any of the methods described in claims 1-5, or to implement any of the methods described in claims 6-10.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in any one of claims 1 to 5 is implemented, or the method described in any one of claims 6 to 10 is implemented.
