Object-oriented code processing method and device, electronic equipment and storage medium

By using an object-oriented code processing method and a carriage merging algorithm to compare and analyze the variable library, a file for processing memory blocks to be updated is generated. This solves the problems of high code complexity and memory consumption caused by the classification scheme of data area and object area, and realizes online, efficient incremental updates and reusability of object-oriented code.

CN120909558BActive Publication Date: 2026-07-03NR ELECTRIC CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NR ELECTRIC CO LTD
Filing Date
2024-05-06
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing object-oriented code processing methods, when converting structured text languages ​​into C++ code, result in high code complexity, additional memory consumption, incomplete polymorphism functionality, and an inability to implement incremental updates due to the data area and object area classification scheme.

Method used

An object-oriented code processing method is adopted to generate target files and variable libraries through code conversion. The variable libraries are compared and analyzed using a pre-built carriage merging algorithm to generate memory block processing files to be updated, which are then sent to the programmable controller for execution to adjust the memory allocation structure.

Benefits of technology

It solves the problems of high code complexity and memory consumption, enables efficient online incremental updates of object-oriented code, and improves the reusability of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909558B_ABST
    Figure CN120909558B_ABST
Patent Text Reader

Abstract

This application provides an object-oriented code processing method, apparatus, electronic device, and storage medium, relating to the field of programmable logic controller (PLC) technology. The object-oriented code processing method provided by this application includes: converting an acquired structured text language program into code to generate a code program, and compiling the code program to obtain an object file and a first variable library; given that the acquired PLC's operating mode is incremental update mode and the PLC has a second variable library, using a pre-built carriage merging algorithm to compare and analyze the second variable library with the first variable library to obtain a memory block processing file to be updated; and sending the object file, the first variable library, and the memory block processing file to be updated to the PLC, enabling the PLC to run the code program based on the object file, the first variable library, and the memory block processing file to be updated. This application can reduce program complexity and achieve incremental update operation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of programmable controller technology, and in particular to an object-oriented code processing method, apparatus, electronic device, and storage medium. Background Technology

[0002] Object-oriented function block polymorphism refers to the different behaviors of the same function block due to different inheritance, overriding, and referencing. Existing methods for processing, generating, and running object-oriented code, in the process of converting structured text language code into C++ code, use a method of separating the data area and object area for C++ class code. The data area stores basic variables and class data structures, while the object area contains pointers to the data structures associated with class instances.

[0003] However, since C type structure pointers are not class object pointers, they cannot implement polymorphism, which leads to the inability to achieve interface polymorphism and input-output variable polymorphism. Furthermore, incremental updates cannot be performed on the programmable controller side for C++ code patterns. In addition, the classification scheme of data area and object area will result in high code complexity. Summary of the Invention

[0004] To address the issues of high code complexity, additional memory usage associated with data structure and object structure pointers, and incomplete polymorphism caused by the data area and object area classification scheme, and to improve program reusability, this application provides an object-oriented code processing method, apparatus, electronic device, and storage medium.

[0005] This application provides an object-oriented code processing method, which adopts the following technical solution:

[0006] An object-oriented code processing method, comprising:

[0007] The acquired structured text language program is converted into a code program, and the code program is compiled to obtain the target file and the first variable library;

[0008] If the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library, the pre-built carriage merging algorithm is used to compare and analyze the second variable library with the first variable library to obtain the memory block processing file to be updated.

[0009] The target file, the first variable library, and the memory block processing file to be updated are sent to the programmable controller, which then runs the code program based on the target file, the first variable library, and the memory block processing file to be updated.

[0010] According to some embodiments, the code conversion of the acquired structured text language program to generate a code program includes:

[0011] Lexical and syntactic scanning is performed on structured text language programs to obtain a syntax tree;

[0012] Semantic analysis is performed on the syntax tree to obtain the semantic tree;

[0013] The code program is obtained based on the node type of the semantic tree.

[0014] According to some embodiments, after converting the acquired structured text language program into a code program, the method further includes:

[0015] Based on the programmable controller's memory allocation interface, variables and class instances in the code program are allocated to the corresponding data areas;

[0016] During the definition of program organization units, the address information of variables, class instances, and data areas is associated with the initialization function.

[0017] According to some embodiments, the object-oriented code processing method further includes:

[0018] When the operating mode is full update mode, the target file and the first variable library are sent to the programmable controller, so that the programmable controller can run the code program based on the target file and the first variable library after initializing its own memory and executing the initialization function.

[0019] According to some embodiments, the acquired structured text language program is converted into code, including:

[0020] Convert the input-output variables declared in the function blocks of the structured text language program into pointer-type member variables of the code class.

[0021] According to some embodiments, the first variable library contains first variable information; the second variable library contains second variable information;

[0022] Using a pre-built carriage merging algorithm, the second variable library is compared and analyzed with the first variable library to obtain the memory block processing file to be updated, including:

[0023] Compare and analyze the information of the first variable with the information of the second variable;

[0024] If the first variable information and the second variable information have the same hierarchical variable name, variable type and length, a memory block corresponding to the first variable information is created, and the starting offset address and length information of the first variable information in its corresponding data area are stored in the memory block. Based on the memory block, the memory block to be updated processing file is obtained.

[0025] According to some embodiments, the first variable library contains multiple first variable information; the second variable library contains multiple second variable information; wherein, there is a correspondence between the multiple variable information and the multiple second variable information;

[0026] Using a pre-built carriage merging algorithm, the second variable library is compared and analyzed with the first variable library to obtain the memory block processing file to be updated, including:

[0027] The information of multiple first variables is compared and analyzed with the information of their corresponding multiple second variables in turn;

[0028] If the first variable information in multiple first variable information is the same as the hierarchical variable name, variable type and length of its corresponding second variable information, set the first variable information as a compatibility flag and create the first memory block corresponding to the first variable information.

[0029] If the second first variable information, which is compactly arranged with the first variable information, is a compatibility marker, a second memory block corresponding to the second variable information is created, and the second memory block is merged with the first memory block; after all the first variable information and its corresponding second variable information are compared and analyzed, the memory block processing file to be updated is obtained.

[0030] This application provides an object-oriented code processing device, which adopts the following technical solution:

[0031] An object-oriented code processing device includes: a code conversion and compilation module, a memory block processing and file determination module, and a file distribution module, wherein...

[0032] The code conversion and compilation module is used to convert the acquired structured text language program into a code program, and then compile the code program to obtain the target file and the first variable library;

[0033] The memory block processing file determination module is used to compare and analyze the second variable library with the first variable library using a pre-built carriage merging algorithm when the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library, to obtain the memory block processing file to be updated.

[0034] The file distribution module is used to distribute the target file, the first variable library, and the memory block processing file to be updated to the programmable controller, and control the programmable controller to run code programs based on the target file, the first variable library, and the memory block processing file to be updated.

[0035] According to some embodiments, the code conversion and compilation module is also specifically used for:

[0036] Lexical and syntactic scanning is performed on structured text language programs to obtain a syntax tree;

[0037] Semantic analysis is performed on the syntax tree to obtain the semantic tree;

[0038] The code program is obtained based on the node type of the semantic tree.

[0039] According to some embodiments, the code conversion and compilation module is also specifically used for:

[0040] Based on the programmable controller's memory allocation interface, variables and class instances in the code program are allocated to the corresponding data areas;

[0041] During the definition of program organization units, the address information of variables, class instances, and data areas is associated with the initialization function.

[0042] According to some embodiments, the file distribution module is further used for:

[0043] When the running mode is full update mode, the target file and the first variable library are sent to the programmable controller, and the programmable controller is controlled to run the code program based on the target file and the first variable library while initializing its own memory and executing the initialization function.

[0044] According to some embodiments, the code conversion and compilation module is also specifically used for:

[0045] Based on the constructed code conversion rules, the acquired structured text language program is converted into code, including:

[0046] Convert the input-output variables declared in the function blocks of the structured text language program into pointer-type member variables of the code class.

[0047] According to some embodiments, the first variable library contains first variable information; the second variable library contains second variable information; the memory block processing file determination module is further used for:

[0048] Compare and analyze the information of the first variable with the information of the second variable;

[0049] If the first variable information and the second variable information have the same hierarchical variable name, variable type and length, a memory block corresponding to the first variable information is created, and the starting offset address and length information of the first variable information in its corresponding data area are stored in the memory block. Based on the memory block, the memory block to be updated processing file is obtained.

[0050] According to some embodiments, the first variable library contains multiple first variable information; the second variable library contains multiple second variable information; wherein, there is a correspondence between the multiple variable information and the multiple second variable information; the memory block processing file determination module is further used for:

[0051] Using a pre-built carriage merging algorithm, the second variable library is compared and analyzed with the first variable library to obtain the memory block processing file to be updated, including:

[0052] The information of multiple first variables is compared and analyzed with the information of their corresponding multiple second variables in turn;

[0053] If the first variable information in multiple first variable information is the same as the hierarchical variable name, variable type and length of its corresponding second variable information, set the first variable information as a compatibility flag and create the first memory block corresponding to the first variable information.

[0054] If the second first variable information, which is compactly arranged with the first variable information, is a compatibility marker, a second memory block corresponding to the second variable information is created, and the second memory block is merged with the first memory block; after all the first variable information and its corresponding second variable information are compared and analyzed, the memory block processing file to be updated is obtained.

[0055] This application provides an electronic device that adopts the following technical solution:

[0056] An electronic device comprising:

[0057] processor;

[0058] The memory stores computer programs, which, when executed by the processor, cause the processor to perform the object-oriented code processing methods described above.

[0059] This application provides a computer-readable storage medium, which adopts the following technical solution:

[0060] A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to execute object-oriented code processing methods.

[0061] This application includes the following beneficial technical effects:

[0062] 1. Converting object-oriented structured text language into code programs and then compiling and running them solves the problems of high code complexity, additional memory occupation associated with data structure and object structure pointers, and incomplete polymorphism functionality caused by the data area and object area classification scheme.

[0063] 2. By comparing and analyzing the first variable library and the second variable library, the memory block processing file to be updated is obtained. The relevant variables in the data area of ​​the programmable controller memory are updated and the memory allocation structure of the programmable controller is adjusted through the memory block processing file to be updated. This realizes online and efficient incremental updates of object-oriented code programs and improves the reusability of code programs. Attached Figure Description

[0064] Figure 1 This is a block diagram illustrating the object-oriented code processing method according to an embodiment of this application;

[0065] Figure 2 This is a schematic diagram of a syntax tree example from an embodiment of this application;

[0066] Figure 3 This is a schematic diagram illustrating an example of converting a structured text class into a C++ class according to an embodiment of this application;

[0067] Figure 4 This is a schematic diagram of the memory block carriage merging algorithm in an embodiment of this application;

[0068] Figure 5 This is a schematic diagram of the object-oriented code processing method according to an embodiment of this application;

[0069] Figure 6 This is a block diagram of an object-oriented code processing device according to an embodiment of this application;

[0070] Figure 7 This is a schematic diagram of the electronic device of this application.

[0071] Explanation of reference numerals in the attached figures: 601: Code conversion and compilation module; 602: Memory block processing and file determination module; 603: File distribution module; 70: Electronic device; 701: Processor; 702: Bus; 703: Memory; 704: Transceiver. Detailed Implementation

[0072] The following is in conjunction with the appendix Figures 1-7 This application will be described in further detail.

[0073] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0074] This application provides a programmable logic controller (PLC) program processing method, which can be executed by an electronic device. The electronic device can be a server or a terminal device. The server can be a standalone physical server, a server cluster consisting of multiple physical servers, a distributed device, or a cloud server providing cloud computing services. The electronic device is equipped with PLC programmable logic controller (PLC) program development software. The terminal device can be a tablet computer, laptop computer, desktop computer, etc., but is not limited to these. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not impose any limitations on this connection.

[0075] Reference Figure 1 An object-oriented code processing method includes steps S101, S102, and S103, wherein...

[0076] S101, the acquired structured text language program is converted into a code program, and the code program is compiled to obtain the target file and the first variable library.

[0077] In some embodiments, the code program is a C++ code program; the target file is a file that records multiple instructions for data operation and processing; the first variable library is a variable library generated by the code program; the first variable library contains hierarchical variable names, variable types, addresses of relative offsets in the data area, and data length information; the code conversion rules are rules for converting structured text language programs into code programs. The code conversion rules are conversion rules that are subjectively constructed by the user according to code compilation specifications and entered into the electronic device through external input.

[0078] The electronic device is equipped with programmable logic controller (PLC) compiler software. When it receives a program in a structured text language, it invokes code conversion rules and uses the PLC compiler software to convert the program into code. First, the PLC program is scanned and semantically analyzed to obtain a semantic tree. Then, the node type of each node in the semantic tree is determined. Using the code conversion rules and node types, the code program is output. The converted content includes data structure definitions, expression assignment statements, loop statements, and conditional statements. In addition, the interfaces, function blocks, and classes of the structured text language are converted into C++ class definitions. The electronic device then uses the PLC compiler software to compile the code program to obtain the object file and the first variable library.

[0079] S102, if the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library, the second variable library is compared and analyzed with the first variable library using a pre-built carriage merging algorithm to obtain the memory block processing file to be updated.

[0080] In some embodiments, the second variable library is the variable library currently in operation by the programmable controller.

[0081] The electronic device sends the target file and the first variable library to the programmable controller (PLC). Before the PLC runs the code program based on the target file and the first variable library, it needs to update the relevant variable information of the code program in the PLC's memory. Before updating, it needs to determine the current operating mode of the PLC and perform the corresponding update based on the operating mode. Therefore, the electronic device first obtains the current operating mode of the PLC and determines the type of operating mode. If the PLC's operating mode is incremental update mode and the PLC has a second variable library, it means that the variable information contained in the first variable library needs to be updated in the PLC's memory, and the memory allocation structure of the PLC is adjusted. Then, the electronic device calls the pre-built carriage merging algorithm, and compares and analyzes the first variable library and the second variable library based on the carriage merging algorithm to obtain the memory block processing file to be updated. Subsequently, the electronic device sends the memory block processing file to be updated to the PLC.

[0082] S103 sends the target file, the first variable library, and the memory block processing file to be updated to the programmable controller, and controls the programmable controller to run the code program based on the target file, the first variable library, and the memory block processing file to be updated.

[0083] In some embodiments, the memory block processing file to be updated includes the memory block that needs to be copied and moved, the starting offset address of the source memory block, the starting offset address of the destination memory block, and the length of the memory block.

[0084] The electronic device sends the target file, the first variable library, and the memory block processing file to be updated to the programmable controller (PLC). The PLC then runs the code program based on these components. Specifically, the PLC enables the task scheduler based on the target file, performs task scheduling, and executes the code program. It updates relevant variable information in the PLC's memory based on the first variable library and adjusts the PLC's memory allocation structure based on the memory block processing file to be updated. By converting object-oriented structured text language into C++ code and then compiling and running it, the high code complexity, additional memory usage associated with data structure and object structure pointers, and incomplete polymorphism issues inherent in data- and object-area separation schemes are resolved. Furthermore, the memory block merging algorithm enables efficient online incremental updates of the object-oriented code.

[0085] In some embodiments, during the process of adjusting the memory allocation structure of the programmable controller based on the memory block processing file to be updated, the memory block processing file to be updated is first parsed, and a cache table is created according to the source memory block start offset address, destination memory block start offset address, and memory block length contained in the memory block processing file. The memory blocks are recorded in the cache table. Then, the programmable controller copies the memory blocks contained in the cache table to a specified location in the data area of ​​the programmable controller's memory to complete the adjustment of the programmable controller's memory allocation structure.

[0086] In some embodiments, during the process of the programmable controller updating the relevant variable information in the memory of the current programmable controller based on the first variable library, the programmable controller initializes its corresponding memory based on the first variable library and updates the relevant variable information contained in the first variable library into the memory that has been initialized.

[0087] This application provides an object-oriented code processing method. An electronic device uses programmable logic controller (PLC) software to perform code conversion on a structured text language program based on call-based code transformation rules, obtaining a code program. The code program is then compiled to obtain an object file and a first variable library. Before sending the object file and the first variable library to the PLC for program operation, the relevant variable information in the PLC's memory needs to be updated. The update method requires specifying the PLC's operating mode. Therefore, the electronic device obtains the PLC's operating mode and determines its type. If the PLC's operating mode is determined to be incremental update mode, and a second variable library exists, it indicates that the relevant variable information in the PLC's memory needs to be updated, and the memory allocation also needs to be updated. The electronic device adjusts the memory allocation structure accordingly, then calls a pre-built carriage merging algorithm to compare and analyze the first and second variable libraries to obtain the memory block processing file to be updated. The electronic device then sends the target file, the first variable library, and the memory block processing file to be updated to the programmable controller (PLC). The PLC updates the relevant variable information in its memory and adjusts the memory allocation structure based on the first variable library and the memory block processing file. It then runs the code program based on the target file. This solves the problems of high code complexity, additional memory usage associated with data structure and object structure pointers, and incomplete polymorphism caused by the data area and object area separation scheme. Simultaneously, the memory block carriage merging algorithm enables efficient online incremental updates of object-oriented code, reducing code complexity and improving code reusability.

[0088] In step S101, the obtained structured text language program is converted into a code program, including: performing lexical and syntactic scanning on the structured text language program to obtain a syntax tree; performing semantic analysis on the syntax tree to obtain a semantic tree; and obtaining the code program according to the node type of the semantic tree.

[0089] In some embodiments, the electronic device sequentially performs lexical analysis and syntax analysis on the structured text language program based on code conversion rules, transforming the structured text language program into a syntax tree. For example, the structured text language corresponding to x = y + z, after lexical analysis and syntax analysis, yields a syntax tree as shown below. Figure 2 The syntax tree is shown; subsequently, the electronic device performs semantic analysis on the syntax tree. This semantic analysis process includes calculating the type of each expression, determining whether variables have been defined before use, determining whether constants are left operands, determining whether the type of the conditional expressions in statements such as WHILE is BOOL, and determining whether the parent class of CLASS is FUNCTION_BLOCK, etc. After semantic analysis, a semantic tree is obtained. Then, the electronic device determines the node type corresponding to each node in the semantic tree, for example... Figure 2 As shown, the "=" node is of type assignment statement, the "x" node is of type variable, and the "+" node is of type operator; then the electronic device generates code program according to the node type.

[0090] In some embodiments, refer to Figure 3 This document discloses an example of converting a structured text class (ST) into a C++ class. Taking class definition as an example, the CLASS class in ST is converted to a C++ class, and the METHOD function within the CLASS is converted to a virtual function of the C++ class. The EXTENDS and IMPLEMENTS functions in ST are both converted to public inheritance of the C++ class, using C++ multiple inheritance to achieve the conversion. The VAR_IN_OUT variable of the ST class is converted to a pointer-type member variable of the C++ class, and the input variable VAR_INPUT and output variable VAR_OUTPUT variables of the ST class are converted to public member variables of the C++ class. The local variable VAR of the ST class is converted to a local member variable of the C++ class.

[0091] In step S101, the obtained structured text language program is converted into code, including converting the input-output type variables declared by the function blocks in the structured text language program into pointer type member variables of the code class.

[0092] In some embodiments, the output-output variables generated by the function blocks in the structured text language program are converted into pointer-type member variables of the C++ code class, which include input pointers; during program initialization, the input pointers are linked to the external data source; after the electronic device sends the target file, the first variable library and the memory block processing file to be updated to the programmable controller, before controlling the programmable controller to run the code program based on the target file, it is determined whether there is a null pointer, so as to prevent exceptions from occurring during the execution of the code program.

[0093] In step S101, after converting the obtained structured text language program into a code program, the method further includes: allocating the variables and class instances of the code program to the corresponding data area based on the memory allocation interface of the programmable controller; and associating the address information of the variables, class instances, and data area with the initialization function during the program organization unit definition process.

[0094] In some embodiments, after an electronic device generates a code program through a programmable controller (PLC) program development software, it needs to associate the relevant variable information contained in the code program with the data area contained in the memory of the PLC and the initialization function. Therefore, the electronic device first needs to obtain the memory allocation interface of the PLC, and allocate the variables and class instances contained in the code program to the specified data area in the memory of the corresponding PLC based on the memory allocation interface. In the process of defining the program organization unit, the variables and class instances and the address information of the data area are associated with the preset initialization function.

[0095] In some embodiments, when the running mode is full update mode, the target file and the first variable library are sent to the programmable controller, and the programmable controller is controlled to run the code program based on the target file and the first variable library while initializing its own memory and executing the initialization function.

[0096] In some embodiments, the full update mode is a mode in which the programmable controller clears all its existing memory allocations and completely reallocates its memory according to the first variable library.

[0097] When the electronic device determines that the programmable controller is in full update mode, it indicates that the current memory allocation of the programmable controller needs to be cleared. The electronic device then sends the target file and the first variable library to the programmable controller. The programmable controller initializes its own memory and executes the initialization function, updates the memory of the programmable controller based on the first variable library, and runs the code program based on the first target file.

[0098] In step S102, the first variable library contains first variable information; the second variable library contains second variable information; the second variable library and the first variable library are compared and analyzed using a pre-built carriage merging algorithm to obtain the memory block processing file to be updated, including: comparing and analyzing the first variable information and the second variable information; if the hierarchical variable name, variable type and length of the first variable information and the second variable information are the same, creating a memory block corresponding to the first variable information, storing the starting offset address and length information of the first variable information in its corresponding data area into the memory block, and obtaining the memory block processing file to be updated based on the memory block.

[0099] In some embodiments, the variables and class instances contained in the first variable library are collectively referred to as first variable information; the variables and class instances contained in the second variable library are collectively referred to as second variable information; both the first variable information and the second variable information contain hierarchical variable names, variable types, and lengths.

[0100] When the first variable library contains a first variable and the second variable library contains a second variable, the electronic device calls a pre-built carriage merging algorithm to compare and analyze the first and second variable information. Specifically, the hierarchical variable name, variable type, and length in the first variable information are compared with those in the second variable information. If the hierarchical variable name, variable type, and length of the first and second variable information are the same, a memory block for the first variable information is created, and the starting offset address and length information of the first variable information in its corresponding data area are stored in the memory block. Based on this memory block, a memory block processing file to be updated is obtained, and subsequently, the memory allocation structure of the programmable controller is adjusted using this memory block processing file.

[0101] In some embodiments, a first variable library contains multiple first variable information; a second variable library contains multiple second variable information; wherein, there is a correspondence between the multiple variable information and the multiple second variable information; a pre-built carriage merging algorithm is used to compare and analyze the second variable library and the first variable library to obtain a memory block processing file to be updated, including: comparing and analyzing the multiple first variable information and their corresponding multiple second variable information in sequence; when the first variable information in the multiple first variable information and its corresponding second variable information have the same hierarchical variable name, variable type, and length, the first variable information is set as a compatibility marker, and a first memory block corresponding to the first variable information is created; when the second first variable information, which is compactly arranged with the first variable information, is set as a compatibility marker, a second memory block corresponding to the second variable information is created, and the second memory block is merged with the first memory block; after all the comparison and analysis of the first variable information and its corresponding second information is completed, a memory block processing file to be updated is obtained.

[0102] In some embodiments, there is a one-to-one correspondence between the multiple first variable information contained in the first variable library and the multiple second variable information contained in the second variable library. During the process of the electronic device calling a preset carriage merging algorithm to compare and analyze the first and second variable libraries, it is necessary to compare and analyze each of the multiple first variable information and its corresponding multiple second variable information one by one. This comparison and analysis can be performed sequentially based on the ascending order of the addresses of the first variable information. If the hierarchical variable name, variable type, and length of the first variable information and its corresponding second variable information are equal, the first variable information is set as a compatibility flag, and a first memory block corresponding to the first variable information is created. Then, the second first variable information, which is tightly arranged with the first variable information, and its corresponding second variable information are compared and analyzed. If the hierarchical variable name, variable type, and length of the second first variable information and its corresponding second variable information are the same, the second first variable information is set as a compatibility flag, and a second memory block for the second first variable information is created. Subsequently, the first memory block and the second memory block are merged into one memory block, increasing the length of the merged memory block. After all the comparison and analysis of the first variable information and its corresponding second variable information is completed, a memory block processing file to be updated is obtained.

[0103] In some embodiments, if the addresses of the third first variable information and the second first variable information are not contiguous, or if the third first variable information is incompatible with its corresponding second variable information, the memory block corresponding to the third first variable information is not merged with the merged memory block.

[0104] Reference Figure 4 The variable library currently running on the programmable controller (PLC), i.e., the second variable library, is compared and analyzed with the variable library of the program to be downloaded and compiled, i.e., the first variable library. Variable C1 is added, and member b3 of class instance 2 is deleted. Using the carriage merging algorithm, the three groups of variables meet the conditions of compatibility and close relative address arrangement. Then, a1 and b1 are merged, a2, b2 and a3 are merged, and a4 and b4 are merged, thus obtaining three memory blocks. Subsequently, the starting offset address and length information of each variable in its corresponding data area are stored in the memory blocks. Based on the three memory blocks obtained, a memory block information table is obtained, i.e., the memory block processing file to be updated.

[0105] This application discloses an object-oriented code processing method, referring to... Figure 5First, the conversion rules between object-oriented structured text language and C++ are determined. The object-oriented structured text language is converted to obtain C++ code, i.e., the code program. Then, the memory allocation function is overloaded to allocate the variables and class instances of the code program to the pre-built data area. The address information of variables, class instances and data area is associated in the program organization unit initialization function. The code program is compiled to obtain the object file and the first variable library.

[0106] The programmable controller (PLC) obtains its operating mode and determines its type. If the operating mode is determined to be a full update mode, the PLC downloads the target file and the first variable library, reinitializes its memory, loads the target file, and executes the initialization function. The PLC then performs task scheduling and program execution.

[0107] If the operating mode is determined to be incremental update mode, the system checks whether the programmable controller (PLC) has a second variable library. If a second variable library exists, based on the pre-built carriage merging algorithm, the first and second variable libraries are compared and analyzed to obtain the memory block processing file to be updated. The PLC downloads the target file, the first variable library, and the memory block processing file to be updated. The PLC parses the memory block processing file to be updated, creates a cache table, copies the memory block specified in the current data area to the cache table, reinitializes the memory, loads the target file, and executes the initialization function. The PLC then copies the memory block from the cache table to the specified location in the data area. After that, the PLC performs task scheduling and program execution.

[0108] If the programmable controller does not have a variable library, the target file and the first variable library are downloaded, the programmable controller re-initializes its memory, loads the target file, and executes the initialization function; then the programmable controller performs task scheduling and program execution.

[0109] This application provides an object-oriented code processing device, which adopts the following technical solution:

[0110] Reference Figure 6 An object-oriented code processing device 60 includes: a code conversion and compilation module 601, a memory block processing file determination module 602, and a file distribution module 603, wherein...

[0111] The code conversion and compilation module 601 is used to convert the acquired structured text language program into a code program, and compile the code program to obtain the target file and the first variable library;

[0112] The memory block processing file determination module 602 is used to compare and analyze the second variable library with the first variable library using a pre-built carriage merging algorithm when the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library to obtain the memory block processing file to be updated.

[0113] The file distribution module 603 is used to distribute the target file, the first variable library, and the memory block processing file to be updated to the programmable controller, and control the programmable controller to run code programs based on the target file, the first variable library, and the memory block processing file to be updated.

[0114] In some embodiments, the code conversion and compilation module 601 is further used for:

[0115] Lexical and syntactic scanning is performed on structured text language programs to obtain a syntax tree;

[0116] Semantic analysis is performed on the syntax tree to obtain the semantic tree;

[0117] The code program is obtained based on the node type of the semantic tree.

[0118] In some embodiments, the code conversion and compilation module 601 is further used for:

[0119] Based on the programmable controller's memory allocation interface, variables and class instances in the code program are allocated to the corresponding data areas;

[0120] During the definition of program organization units, the address information of variables, class instances, and data areas is associated with the initialization function.

[0121] In some embodiments, the file distribution module 603 is further configured to:

[0122] When the running mode is full update mode, the target file and the first variable library are sent to the programmable controller, and the programmable controller is controlled to run the code program based on the target file and the first variable library while initializing its own memory and executing the initialization function.

[0123] In some embodiments, the code conversion and compilation module 601 is further used for:

[0124] Based on the constructed code conversion rules, the acquired structured text language program is converted into code, including:

[0125] Convert the input-output variables declared in the function blocks of the structured text language program into pointer-type member variables of the code class.

[0126] In some embodiments, the first variable library contains first variable information; the second variable library contains second variable information; the memory block processing file determination module 602 is further configured to:

[0127] Compare and analyze the information of the first variable with the information of the second variable;

[0128] If the first variable information and the second variable information have the same hierarchical variable name, variable type and length, a memory block corresponding to the first variable information is created, and the starting offset address and length information of the first variable information in its corresponding data area are stored in the memory block. Based on the memory block, the memory block to be updated processing file is obtained.

[0129] In some embodiments, the first variable library contains multiple first variable information; the second variable library contains multiple second variable information; wherein, there is a correspondence between the multiple variable information and the multiple second variable information; the memory block processing file determination module 602 is further used for:

[0130] Using a pre-built carriage merging algorithm, the second variable library is compared and analyzed with the first variable library to obtain the memory block processing file to be updated, including:

[0131] The information of multiple first variables is compared and analyzed with the information of their corresponding multiple second variables in turn;

[0132] If the first variable information in multiple first variable information is the same as the hierarchical variable name, variable type and length of its corresponding second variable information, set the first variable information as a compatibility flag and create the first memory block corresponding to the first variable information.

[0133] If the second first variable information, which is compactly arranged with the first variable information, is a compatibility marker, a second memory block corresponding to the second variable information is created, and the second memory block is merged with the first memory block; after all the first variable information and its corresponding second variable information are compared and analyzed, the memory block processing file to be updated is obtained.

[0134] In some embodiments, the code conversion and compilation module 601 may include logic circuits or may be implemented by a central processing unit, digital signal processor or field-programmable gate array included in an electronic device;

[0135] The memory block processing file determination module may contain logic circuits or be implemented by a central processing unit, digital signal processor or field-programmable gate array contained in an electronic device;

[0136] The device operation module 602 may include logic circuits or be implemented by a central processing unit, digital signal processor or field-programmable gate array contained in electronic equipment;

[0137] The file distribution module 603 may include logic circuits or be implemented by a central processing unit, digital signal processor or field-programmable gate array contained in an electronic device.

[0138] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0139] This invention also describes an electronic device from the perspective of a physical device, such as... Figure 7 As shown, Figure 7 The illustrated electronic device 70 includes a processor 701 and a memory 703. The processor 701 and the memory 703 are connected, for example, via a bus 702. Optionally, the electronic device 70 may also include a transceiver 704. It should be noted that in practical applications, the transceiver 704 is not limited to one type, and the structure of this electronic device 70 does not constitute a limitation on the embodiments of the present invention.

[0140] Processor 701 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in this disclosure. Processor 701 may also be a combination that implements computational functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.

[0141] Bus 702 may include a pathway for transmitting information between the aforementioned components. Bus 702 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. Bus 702 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0142] The memory 703 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other storage medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.

[0143] The memory 703 stores application code that executes the present invention, and its execution is controlled by the processor 701. The processor 701 executes the application code stored in the memory 703 to implement the content shown in the foregoing method embodiments.

[0144] Figure 7 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.

[0145] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0146] The above are only some embodiments of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.

Claims

1. An object-oriented code processing method, characterized in that, include: The acquired structured text language program is converted into a code program, and the code program is compiled to obtain an object file and a first variable library; If the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library, the second variable library and the first variable library are compared and analyzed using a pre-built carriage merging algorithm to obtain the memory block processing file to be updated. The first variable library contains multiple first variable information; the second variable library contains multiple second variable information, and the multiple first variable information and the multiple second variable information have a corresponding relationship. The target file, the first variable library, and the memory block processing file to be updated are sent to the programmable controller, and the programmable controller is controlled to run the code program based on the target file, the first variable library, and the memory block processing file to be updated; The step of using a pre-built carriage merging algorithm to compare and analyze the second variable library with the first variable library to obtain the memory block processing file to be updated includes: The information of the multiple first variables is compared and analyzed with the information of the multiple corresponding second variables in turn; If the first variable information in the plurality of first variable information has the same hierarchical variable name, variable type and length as its corresponding second variable information, the first variable information is set as a compatibility flag and a first memory block corresponding to the first variable information is created. If the second first variable information, which is compactly arranged with the first variable information, is a compatibility marker, a second memory block corresponding to the second first variable information is created, and the second memory block is merged with the first memory block; after all the first variable information and its corresponding second variable information are compared and analyzed, the memory block processing file to be updated is obtained.

2. The method according to claim 1, characterized in that, The process of converting the acquired structured text language program into a code program includes: Lexical and syntactic scanning is performed on the structured text language program to obtain a syntax tree; Semantic analysis is performed on the syntax tree to obtain a semantic tree; The code program is obtained based on the node types of the semantic tree.

3. The method according to claim 1, characterized in that, After converting the acquired structured text language program into a code program, the method further includes: Based on the memory allocation interface of the programmable controller, the variables and class instances of the code program are allocated to the corresponding data areas; During the definition of program organization units, the address information of the variables, the class instances, and the data areas are associated with the initialization function.

4. The method according to claim 1, characterized in that, Also includes: When the running mode is full update mode, the target file and the first variable library are sent to the programmable controller, and the programmable controller is controlled to run the code program based on the target file and the first variable library while initializing its own memory and executing the initialization function.

5. The method according to claim 1, characterized in that, The code conversion of the acquired structured text language program includes: The input-output variables declared in the function blocks of the structured text language program are converted into pointer-type member variables of the code class.

6. The method according to claim 1, characterized in that, The first variable library contains first variable information; the second variable library contains second variable information. The step of using a pre-built carriage merging algorithm to compare and analyze the second variable library with the first variable library to obtain the memory block processing file to be updated includes: The information of the first variable is compared and analyzed with the information of the second variable; When the first variable information and the second variable information have the same hierarchical variable name, variable type and length, a memory block corresponding to the first variable information is created, and the starting offset address and length information of the first variable information in its corresponding data area are stored in the memory block, and the memory block to be updated processing file is obtained based on the memory block.

7. An object-oriented code processing apparatus, comprising: The code conversion and compilation module is used to convert the acquired structured text language program into a code program, and to compile the code program to obtain the target file and the first variable library; The memory block processing file determination module is used to compare and analyze the second variable library with the first variable library using a pre-built carriage merging algorithm when the obtained programmable controller is in incremental update mode and the programmable controller has a second variable library to obtain the memory block processing file to be updated. The first variable library contains multiple first variable information, the second variable library contains multiple second variable information, and there is a corresponding relationship between the multiple first variable information and the multiple second variable information. The file distribution module is used to distribute the target file, the first variable library, and the memory block processing file to be updated to the programmable controller, and control the programmable controller to run the code program based on the target file, the first variable library, and the memory block processing file to be updated; Specifically, the memory block processing file determination module is used to sequentially compare and analyze the plurality of first variable information with its corresponding plurality of second variable information; when the first variable information among the plurality of first variable information has the same hierarchical variable name, variable type, and length as its corresponding second variable information, the first variable information is set as a compatibility marker, and a first memory block corresponding to the first variable information is created; when the second first variable information, which is compactly arranged with the first variable information, is set as a compatibility marker, a second memory block corresponding to the second first variable information is created, and the second memory block is merged with the first memory block; after all the comparison and analysis of the first variable information with its corresponding second variable information is completed, the memory block processing file to be updated is obtained.

8. An electronic device, characterized in that, include: processor; A memory storing a computer program that, when executed by the processor, causes the processor to perform the object-oriented code processing method as described in any one of claims 1-6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed in the computer, the computer is instructed to perform the object-oriented code processing method according to any one of claims 1-6.