Variable comparison method, device, equipment and medium of programmable logic controller

By converting PLC variable data into tabular data for comparison, the problem of insufficient applicability of PLC variable comparison methods is solved, and more efficient and intuitive variable difference display is achieved.

CN117270453BActive Publication Date: 2026-05-05SHENZHEN INOVANCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN INOVANCE TECH CO LTD
Filing Date
2023-10-12
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

Existing PLC variable comparison methods require both the PLC and the host computer to support text-based programming, which many PLCs do not, resulting in limited applicability.

Method used

By converting the PLC's variable data into tabular data and comparing them at the tabular level to identify differences, the requirement for text-based programming of the PLC is avoided.

Benefits of technology

It improves the applicability and efficiency of PLC variable comparison, makes the display more intuitive, and can accurately compare variable differences.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117270453B_ABST
    Figure CN117270453B_ABST
Patent Text Reader

Abstract

This invention discloses a variable comparison method for a programmable logic controller (PLC). The method includes: upon receiving a variable comparison instruction, acquiring current variable data of the current process of the PLC and comparison variable data of the comparison process; converting the current variable data into current table data and converting the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; comparing the current table data and the comparison table data to determine the differences between them. This application solves the technical problem of the weak applicability of existing PLC variable comparison methods.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of programmable logic controller (PLC) technology, and more particularly to a variable comparison method, apparatus, device, and readable storage medium for a PLC. Background Technology

[0002] During the debugging process of a PLC (Programmable Logic Controller), several project versions may be generated. For debugging personnel, it is necessary to check the differences between two PLC project versions, which requires comparison of the two PLC project versions. PLC project comparison generally consists of three parts: variable comparison, program comparison, and configuration comparison.

[0003] Existing PLC variable comparison methods convert variables into text-based programming and then use text comparison algorithms, such as the LCS (Longest Common Subsequence) algorithm, to compare the converted text and determine the differences between variables in two PLC project versions. However, this variable comparison method requires both the PLC and the host computer to support text-based programming, which many current PLCs do not, resulting in limited applicability of existing PLC variable comparison methods. Summary of the Invention

[0004] The main objective of this invention is to provide a variable comparison method, apparatus, device, and medium for programmable logic controllers, aiming to solve the technical problem of the weak applicability of existing PLC variable comparison methods.

[0005] To achieve the above objectives, the present invention provides a variable comparison method for a programmable logic controller (PLC), the variable comparison method for the PLC comprising:

[0006] Upon receiving a variable comparison instruction, the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project are obtained.

[0007] The current variable data is converted into current table data, and the comparison variable data is converted into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data;

[0008] Compare the current table data with the comparison table data to determine the differences between the current table data and the comparison table data.

[0009] Optionally, the steps of converting the current variable data into current table data and converting the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data, include:

[0010] The current variable data is converted into first tree structure data, and the comparison variable data is converted into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data;

[0011] The first tree structure data is converted into the current table data, and the second tree structure data is converted into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data.

[0012] Optionally, the steps of converting the current variable data into first tree structure data and converting the comparison variable data into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include:

[0013] Convert the current variable data into first table data, and convert the comparison variable data into second table data;

[0014] The first table data is converted into a third tree structure data, and the second table data is converted into a fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data.

[0015] The tree structure of the third tree structure data is adjusted to obtain the first tree structure data; and the tree structure of the fourth tree structure data is adjusted to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0016] Optionally, the steps of adjusting the tree structure of the third tree structure data to obtain the first tree structure data; and adjusting the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include:

[0017] The tree nodes of the third tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0018] The tree nodes of the fourth tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the third tree structure data. If the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0019] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0020] Optionally, the steps of adjusting the tree structure of the third tree structure data to obtain the first tree structure data; and adjusting the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include:

[0021] The tree nodes of the third tree structure data are traversed layer by layer, and each tree node at each level is converted into a first text language; the tree nodes of the fourth tree structure data are traversed layer by layer, and each tree node at each level is converted into a second text language.

[0022] Traverse the strings in the first text language and determine whether the string exists in the second text language. If the string does not exist in the second text language, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0023] Traverse the strings in the second text language and determine whether the string exists in the first text language. If the string does not exist in the first text language, insert an empty tree node at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0024] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0025] Optionally, the step of comparing the current table data with the comparison table data to determine the difference between the current table data and the comparison table data includes:

[0026] Obtain row attribute information for rows that are identical to the current table data and the comparison table data, wherein the row attribute information includes at least one of variable name, data type, initial value, power-down retention, network exposure, comment, soft device address, and allocation address;

[0027] Determine whether the row attribute information of the same row in the current table data is consistent with that in the comparison table data, and determine the difference between the current table data and the comparison table data.

[0028] Optionally, after the step of comparing the current table data with the comparison table data to determine the difference between the current table data and the comparison table data, the method further includes:

[0029] Upon receiving a variable synchronization instruction, identify the rows in the comparison table data that differ from the current table data;

[0030] Determine whether the data in the differing rows supports synchronization;

[0031] When the data in the differing row supports synchronization, the data in the current table data that is the same as the differing row is replaced with the data in the differing row.

[0032] To achieve the above objectives, the present invention also provides a variable comparison device for a programmable logic controller, the variable comparison device for the programmable logic controller comprising:

[0033] The acquisition module is used to acquire the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project when a variable comparison instruction is received;

[0034] A conversion module is used to convert the current variable data into current table data and the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data;

[0035] The comparison module is used to compare the current table data with the comparison table data and determine the differences between the current table data and the comparison table data.

[0036] Furthermore, to achieve the above objectives, the present invention also provides a variable comparison device for a programmable logic controller (PLC). The PLC variable comparison device includes: a memory, a processor, and a program for a variable comparison method of the PLC stored in the memory and executable on the processor. When the program for the variable comparison method of the PLC is executed by the processor, it can implement the steps of the variable comparison method of the PLC as described above.

[0037] Furthermore, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a variable comparison program for a programmable logic controller (PLC). When the PLC variable comparison program is executed by a processor, it implements the steps of the variable comparison method for a PLC as described above.

[0038] In addition, to achieve the above objectives, the present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the variable comparison method of the programmable logic controller as described above.

[0039] This invention provides a method, apparatus, device, and medium for comparing variables in a programmable logic controller (PLC). Upon receiving a variable comparison instruction, the invention acquires current variable data for the current process of the PLC and comparison variable data for the comparison process. It then converts the current variable data into current table data and the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data. Finally, it compares the current table data and the comparison table data to determine the differences between them. This invention converts variables into tables for comparison during PLC variable comparison, eliminating the need for PLC support for text-based programming, thus improving the applicability of the PLC variable comparison method and solving the problem of weak applicability in existing PLC variable comparison methods. Attached Figure Description

[0040] Figure 1 This is a schematic diagram of the hardware architecture of the variable comparison device of the programmable logic controller involved in the embodiment of the present invention;

[0041] Figure 2 This is a flowchart illustrating a first embodiment of the variable comparison method for a programmable logic controller according to the present invention.

[0042] Figure 3 This is a flowchart illustrating a second embodiment of the variable comparison method for a programmable logic controller according to the present invention.

[0043] Figure 4 This is a flowchart illustrating a third embodiment of the variable comparison method for a programmable logic controller according to the present invention.

[0044] Figure 5 This is a flowchart illustrating a fourth embodiment of the variable comparison method for a programmable logic controller according to the present invention.

[0045] Figure 6 This is a schematic diagram of the module structure of the variable comparison device of the programmable logic controller involved in the embodiment of the present invention.

[0046] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0047] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.

[0048] Reference Figure 1 , Figure 1 This is a schematic diagram of the hardware architecture of the variable comparison device of the programmable logic controller involved in the embodiment of the present invention.

[0049] like Figure 1 As shown, the variable comparison device of the programmable logic controller may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to implement communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wireless-Fidelity (Wi-Fi) interface). The memory 1005 may be high-speed random access memory (RAM) or stable non-volatile memory (NVM), such as a disk storage device. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.

[0050] Those skilled in the art will understand that Figure 1 The structure shown does not constitute a limitation on the variable comparison device of a programmable logic controller, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0051] like Figure 1 As shown, the memory 1005, which serves as a storage medium, may include an operating system, a network communication module, a user interface module, and a variable comparison program for a programmable logic controller.

[0052] exist Figure 1 In the variable comparison device of the programmable logic controller (PLC) shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 can be set in the variable comparison device of the PLC. The variable comparison device of the PLC calls the variable comparison program of the PLC stored in the memory 1005 through the processor 1001 and executes the following steps:

[0053] Upon receiving a variable comparison instruction, the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project are obtained.

[0054] The current variable data is converted into current table data, and the comparison variable data is converted into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data;

[0055] Compare the current table data with the comparison table data to determine the differences between the current table data and the comparison table data.

[0056] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0057] The current variable data is converted into first tree structure data, and the comparison variable data is converted into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data;

[0058] The first tree structure data is converted into the current table data, and the second tree structure data is converted into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data.

[0059] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0060] Convert the current variable data into first table data, and convert the comparison variable data into second table data;

[0061] The first table data is converted into a third tree structure data, and the second table data is converted into a fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data.

[0062] The tree structure of the third tree structure data is adjusted to obtain the first tree structure data; and the tree structure of the fourth tree structure data is adjusted to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0063] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0064] The tree nodes of the third tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0065] The tree nodes of the fourth tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the third tree structure data. If the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0066] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0067] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0068] The tree nodes of the third tree structure data are traversed layer by layer, and each tree node at each level is converted into a first text language; the tree nodes of the fourth tree structure data are traversed layer by layer, and each tree node at each level is converted into a second text language.

[0069] Traverse the strings in the first text language and determine whether the string exists in the second text language. If the string does not exist in the second text language, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0070] Traverse the strings in the second text language and determine whether the string exists in the first text language. If the string does not exist in the first text language, insert an empty tree node at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0071] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0072] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0073] Obtain row attribute information for rows that are identical to the current table data and the comparison table data, wherein the row attribute information includes at least one of variable name, data type, initial value, power-down retention, network exposure, comment, soft device address, and allocation address;

[0074] Determine whether the row attribute information of the same row in the current table data is consistent with that in the comparison table data, and determine the difference between the current table data and the comparison table data.

[0075] Furthermore, the processor 1001 can call the variable comparison program of the programmable logic controller stored in the memory 1005, and also perform the following steps:

[0076] Upon receiving a variable synchronization instruction, identify the rows in the comparison table data that differ from the current table data;

[0077] Determine whether the data in the differing rows supports synchronization;

[0078] When the data in the differing row supports synchronization, the data in the current table data that is the same as the differing row is replaced with the data in the differing row.

[0079] During PLC (Programmable Logic Controller) debugging, several project versions may be generated. Debuggers need to examine the differences between two PLC project versions, requiring comparison. PLC variable comparison is a crucial aspect of PLC project comparison. Existing methods for PLC variable comparison convert variables into text-based programming and then use text comparison algorithms, such as the LCS (Longest Common Subsequence) algorithm, to compare the converted text and determine the differences between the two PLC project versions. However, this method requires both the PLC and the host computer to support text-based programming, which many current PLCs do not, resulting in limited applicability of existing PLC variable comparison methods.

[0080] To address the aforementioned problems, the variable comparison method for programmable logic controllers of the present invention is proposed. The variable comparison method for programmable logic controllers of the present invention will be described in detail below through specific embodiments.

[0081] Example 1

[0082] Reference Figure 2 , Figure 2 This is a flowchart illustrating a first embodiment of the variable comparison method for a programmable logic controller (PLC) according to the present invention. The variable comparison method for the PLC includes the following steps:

[0083] Step S1000: Upon receiving a variable comparison instruction, obtain the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project;

[0084] In this embodiment, the execution entity of the variable comparison method of the programmable logic controller is the variable comparison device of the programmable logic controller. The variable comparison device of the programmable logic controller can be a host computer, such as a computer, human-machine interface or other terminal device. Of course, in other embodiments, the variable comparison device of the programmable logic controller can also be determined according to the actual situation. This embodiment does not limit it.

[0085] In this embodiment, a variable comparison instruction refers to a command that triggers the programmable logic controller's (PLC) program comparison device to perform a variable comparison operation. The variable comparison instruction can be triggered manually or automatically by the device. For example, a trigger control for the variable comparison instruction can be set in the PLC's variable comparison device. When the trigger control is clicked by the debugging personnel, the variable comparison instruction is triggered. The current project refers to the PLC project being edited, and the comparison project refers to the PLC project used for difference comparison with the current project. The current project and the comparison project can be historical PLC projects, newly created PLC projects, or PLC projects currently being executed by the PLC. The current variable data refers to the source data of the variables contained in the current project, and the comparison variable data refers to the source data of the variables contained in the comparison project.

[0086] In one possible implementation, the variable comparison device of the programmable logic controller (PLC) is equipped with a trigger control for variable comparison instructions. When the debugging personnel need to perform variable comparison, they can select the current project and the comparison project to be used for comparison, and then click the trigger control for variable comparison instructions to trigger the variable comparison device of the PLC to perform variable comparison operations. When the variable comparison device of the PLC receives the variable comparison instructions, it automatically obtains the variable source data contained in the current project of the PLC and the variable source data contained in the comparison project.

[0087] Step S2000: Convert the current variable data into current table data and convert the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data;

[0088] In this embodiment, the current table data refers to the data of the current variable data displayed in a table format, and the comparison table data refers to the data of the comparison variable data displayed in a table format. Each row of the table data represents a member variable and records the attribute information of that member variable. The attribute information of the variable may include variable name, data type, initial value, power-down retention, network exposure, comments, soft device address, allocation address, etc. It should be noted that the table structure of the current table data and the comparison table data is consistent.

[0089] In one possible implementation, the variable comparison device of the programmable logic controller automatically obtains the variable source data contained in the current project and the variable source data contained in the comparison project of the programmable logic controller, and converts the variable source data contained in the current project into current table data displayed in tabular form, and converts the variable source data contained in the comparison project into comparison table data displayed in tabular form.

[0090] Step S3000: Compare the current table data with the comparison table data to determine the difference between the current table data and the comparison table data.

[0091] In this embodiment, the difference between the current table data and the comparison table data is determined, that is, whether there are differences in the attribute information of the member variables in the current table data and the comparison table data. During the comparison, each row of the same data can be compared individually, or the entire set of the same data can be compared.

[0092] In one possible implementation, the variable comparison device of the programmable logic controller converts the current variable data into current table data and the comparison variable data into comparison table data, and then automatically compares the same rows of the current table data and the comparison table data row by row to determine whether there are differences in the attribute information between the member variables of the same row.

[0093] Optionally, the steps of S3000 above include:

[0094] Step S3100: Obtain row attribute information of the same rows in the current table data and the comparison table data, wherein the row attribute information includes at least one of variable name, data type, initial value, power-down retention, network exposure, comment, soft device address, and allocation address;

[0095] Step S3200: Determine whether the row attribute information of the same row in the current table data and the comparison table data are consistent, and determine the difference between the current table data and the comparison table data.

[0096] In this embodiment, the variable comparison device of the programmable logic controller (PLC) acquires the row attribute information of the same rows in the current table data and the comparison table data. It determines whether there is a difference between the current table data and the comparison table data by judging whether the row attribute information of the same rows in the current table data and the comparison table data are consistent. The row attribute information may include at least one of the following: variable name, data type, initial value, power-down retention, network exposure, comments, soft device address, and allocation address. When comparing the row attribute information, identical row attribute information can be compared one by one; if any row attribute information is different, the row is considered different. By comparing the row attribute information one by one, the differences between the current table data and the comparison table data can be accurately determined.

[0097] Optionally, when differences are found after comparison, the differences can be marked and displayed. The marking and display method can be to display the differences in a font of a different eye-catching color.

[0098] In one possible implementation, if the initial values ​​of the member variables represented by the first row of the current table data differ from those in the comparison table data, the initial values ​​of both are displayed in red. By highlighting the differences, the location of the discrepancies can be identified to the debugging personnel.

[0099] In the technical solution provided in this embodiment, when the variable comparison device of the programmable logic controller (PLC) receives a variable comparison instruction, it acquires the current variable data of the current project of the PLC and the comparison variable data of the comparison project; converts the current variable data into current table data and the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; and compares the current table data and the comparison table data to determine the differences between them. In this way, when comparing PLC variables, the variables are converted into tables and compared using a tabular format. This eliminates the need for the PLC to support text language programming, improving the applicability of the PLC variable comparison method and solving the problem of weak applicability of existing PLC variable comparison methods. Furthermore, the variables are displayed in tabular form, making the display more intuitive and efficient, and allowing for misaligned comparisons of variables with the same name.

[0100] Example 2

[0101] Reference Figure 3 , Figure 3 This is a flowchart illustrating a second embodiment of the variable comparison method for a programmable logic controller according to the present invention. Based on embodiment one, the steps in S2000 above include:

[0102] Step S2100: Convert the current variable data into first tree structure data and convert the comparison variable data into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data;

[0103] In this embodiment, the first tree structure data refers to the data where the current variable data is displayed in a tree structure, and the second tree structure data refers to the data where the comparison variable data is displayed in a tree structure. Each main variable name corresponds to a parent node, and each of its member variables corresponds to a child node. It should be noted that the tree structure of the first tree structure data and the second tree structure data are consistent.

[0104] In one possible implementation, after the variable comparison device of the programmable logic controller obtains the current variable data and the comparison variable data, it converts the current variable data and the comparison variable data into first tree structure data and second tree structure data respectively according to the main variable name and member variable name of the current variable data and the comparison variable data. The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0105] Step S2200: Convert the first tree structure data into the current table data, and convert the second tree structure data into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data.

[0106] In this embodiment, the variable comparison device of the programmable logic controller converts the current variable data and the comparison variable data into first tree structure data and second tree structure data, then converts the first tree structure data into current table data, and the second tree structure data into comparison table data.

[0107] In the technical solution provided in this embodiment, the variable comparison device of the programmable logic controller converts the current variable data into first tree structure data, and the comparison variable data into second tree structure data. Then, it converts the first tree structure data into current table data and the second tree structure data into comparison table data. This conversion is more efficient than directly converting variable data into table data, thus improving the efficiency of PLC variable comparison.

[0108] Example 3

[0109] Reference Figure 4 , Figure 4 This is a flowchart illustrating a third embodiment of the variable comparison method for a programmable logic controller according to the present invention. Based on embodiment two, the steps of S2100 above include:

[0110] Step S2110: Convert the current variable data into first table data and convert the comparison variable data into second table data;

[0111] Step S2120: Convert the first table data into third tree structure data and convert the second table data into fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data.

[0112] Step S2130: Adjust the tree structure of the third tree structure data to obtain the first tree structure data; and adjust the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0113] In this embodiment, for ease of comparison, the current table data and the comparison table data should have the same table structure. Correspondingly, the tree structures of the first tree structure data and the second tree structure data before conversion should also be the same. However, if the current variable data and the comparison variable data are directly converted into tree structure data and then into table data, their table structures may not be the same due to differences in the variable data. Therefore, the table structure needs to be adjusted.

[0114] In this embodiment, after acquiring the current variable data and the comparison variable data, the variable comparison device of the programmable logic controller first converts the current variable data into first table data and the comparison variable data into second table data. Then, it converts the first table data into third tree structure data and the second table data into fourth tree structure data. The table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data. Finally, the tree structure of the third tree structure data is adjusted to obtain the first tree structure data; and the tree structure of the fourth tree structure data is adjusted to obtain the second tree structure data, making the tree structure of the first tree structure data consistent with the tree structure of the second tree structure data. The conversion process and principle from variable data to table data and from table data to tree structure data are the same as those described in Embodiments 1 and 2, and will not be repeated here.

[0115] Optionally, the steps in S2130 above include:

[0116] Step S2131: Traverse the tree nodes of the third tree structure data layer by layer, and determine whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0117] The tree nodes of the fourth tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the third tree structure data. If the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0118] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0119] In this embodiment, when adjusting the third data structure and the fourth tree structure, a tree data comparison algorithm with a variable order can be invoked to perform adjustments by inserting empty tree nodes. The principle is to traverse the current tree node to check if the node exists in the comparison tree; if not, an empty node is inserted. This process is repeated to insert empty nodes into the comparison tree. The order of the tree nodes at this level is then adjusted so that identical nodes are in the same row. Finally, the next level of tree nodes is recursively compared.

[0120] In one possible implementation, the variable comparison device of the programmable logic controller traverses the tree nodes of the third tree structure data layer by layer and determines whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data. Similarly, by traversing the tree nodes of the fourth tree structure data layer by layer and determining whether the tree node exists in the third tree structure data, if the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data. This makes the tree structure of the first tree structure data the same as that of the second tree structure data.

[0121] Optionally, the steps in S2130 above include:

[0122] Step S2132: Traverse the tree nodes of the third tree structure data layer by layer and convert each tree node of the third tree structure data into the first text language; and traverse the tree nodes of the fourth tree structure data layer by layer and convert each tree node of the fourth tree structure data into the second text language.

[0123] Step S2133: Traverse the strings in the first text language and determine whether the string exists in the second text language. If the string does not exist in the second text language, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and,

[0124] Traverse the strings in the second text language and determine whether the string exists in the first text language. If the string does not exist in the first text language, insert an empty tree node at the corresponding position in the third tree structure data to obtain the first tree structure data.

[0125] The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0126] In this embodiment, when adjusting the third data structure and the fourth tree structure, an immutable tree data comparison algorithm can be invoked. The principle is to traverse the current tree node, concatenate the data into a string using newline characters, and then call a text comparison algorithm to compare the two strings. If the result line is empty, an empty tree node is inserted. The text comparison algorithm can be the LCS (Longest Common Subsequence) algorithm.

[0127] In one possible implementation, the variable comparison device of the programmable logic controller traverses the tree nodes of the third tree structure data layer by layer, converting each tree node into a first text language, and traverses the tree nodes of the fourth tree structure data layer by layer, converting each tree node into a second text language. Then, it traverses the strings in the first text language and determines whether the string exists in the second text language. If the string does not exist in the second text language, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data. Similarly, it traverses the strings in the second text language and determines whether the string exists in the first text language. If the string does not exist in the first text language, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data. This makes the tree structure of the first tree structure data identical to that of the second tree structure data.

[0128] In the technical solution provided in this embodiment, the current variable data is converted into first table data, and the comparison variable data is converted into second table data; the first table data is converted into third tree structure data, and the second table data is converted into fourth tree structure data. The table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data. The tree structure of the third tree structure data is adjusted to obtain the first tree structure data; and the tree structure of the fourth tree structure data is adjusted to obtain the second tree structure data. The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data. By adjusting the tree structures of the first and second tree structure data, it can be ensured that the table structures of the current table data and the comparison table data are consistent.

[0129] Example 4

[0130] Reference Figure 5 , Figure 5 This is a flowchart illustrating a fourth embodiment of the variable comparison method for a programmable logic controller according to the present invention. Based on embodiment one, after step S3000 above, the method further includes:

[0131] Step S4000: Upon receiving a variable synchronization instruction, determine the rows in the comparison table data that differ from the current table data;

[0132] In this embodiment, variable synchronization refers to synchronizing the attribute information of variables that differ in the comparison table data to the current table data, that is, restoring the attribute information of variables in the comparison table data in the current table data; variable synchronization instruction refers to the command that triggers the variable comparison device of the programmable logic controller to perform variable synchronization operation. The variable synchronization instruction can be triggered manually or automatically by the device. For example, a trigger control for variable synchronization instruction is set in the variable comparison device of the programmable logic controller. When the trigger control is clicked by the debugging personnel, the variable synchronization instruction is triggered.

[0133] In one possible implementation, the variable comparison device of the programmable logic controller (PLC) is equipped with a trigger control for variable synchronization instructions. After comparing the current table data with the comparison table data and determining the differences between the two tables, if the debugging personnel need to synchronize the difference information in the comparison table data to the current table data, they can click the trigger control for variable synchronization instructions to trigger the PLC's variable comparison device to perform variable synchronization operations. The PLC's variable comparison device then determines the rows in the comparison table data that differ from the current table data.

[0134] Step S5000: Determine whether the data in the differing rows supports synchronization;

[0135] In this embodiment, after identifying rows in the comparison table that differ from the current table data, the variable comparison device of the programmable logic controller determines whether the data in the differing rows supports synchronization. Since not all data in the comparison table supports synchronization—for example, data of the same data type as the data in the comparison table may not exist in the current table, or data whose data type structure would change after synchronization—it is necessary to determine whether the data in the differing rows supports synchronization.

[0136] Step S6000: When the data in the difference row supports synchronization, replace the data in the current table data that is the same as the difference row with the data in the difference row.

[0137] In this embodiment, when it is determined that the data in the differing row supports synchronization, the variable comparison device of the programmable logic controller replaces the data in the current table data that is the same as the data in the differing row with the data in the differing row.

[0138] In the technical solution provided in this embodiment, when the variable comparison device of the programmable logic controller receives a variable synchronization command, it identifies the difference rows in the comparison table data that differ from the current table data; determines whether the data in the difference rows supports synchronization; and if the data in the difference rows supports synchronization, replaces the data in the current table data that is the same as the difference rows with the data in the difference rows. This allows for the recovery of data from the comparison table data in the current table data when necessary, and subsequently, the recovery of data from the comparison project in the current project, facilitating debugging by personnel.

[0139] Furthermore, based on the above embodiments, the present invention also proposes a variable comparison device for a programmable logic controller, referring to... Figure 6 , Figure 6 This is a schematic diagram of the structure of a variable comparison device for a programmable logic controller according to an embodiment of the present invention, as shown below. Figure 6 As shown, in this embodiment, the variable comparison device of the programmable logic controller includes: an acquisition module 10, a conversion module 20, and a comparison module 30.

[0140] The acquisition module 10 is used to acquire the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project when a variable comparison instruction is received.

[0141] The conversion module 20 is used to convert the current variable data into current table data and the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data;

[0142] The comparison module 30 is used to compare the current table data with the comparison table data to determine the difference between the current table data and the comparison table data.

[0143] In some optional embodiments, the conversion module 20 is further configured to convert the current variable data into first tree structure data and convert the comparison variable data into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data; convert the first tree structure data into the current table data and convert the second tree structure data into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data.

[0144] In some optional embodiments, the conversion module 20 is further configured to convert the current variable data into first table data and the comparison variable data into second table data; convert the first table data into third tree structure data and the second table data into fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data; adjust the tree structure of the third tree structure data to obtain the first tree structure data; and adjust the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0145] In some optional embodiments, the conversion module 20 is further configured to traverse the tree nodes of the third tree structure data layer by layer, and determine whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and to traverse the tree nodes of the fourth tree structure data layer by layer, and determine whether the tree node exists in the third tree structure data. If the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data; wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0146] In some optional embodiments, the conversion module 20 is further configured to traverse the tree nodes of the third tree structure data layer by layer and convert each layer of tree nodes into a first text language, and traverse the tree nodes of the fourth tree structure data layer by layer and convert each layer of tree nodes into a second text language; traverse the strings in the first text language and determine whether the string exists in the second text language; if the string does not exist in the second text language, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and traverse the strings in the second text language and determine whether the string exists in the first text language; if the string does not exist in the first text language, insert an empty tree node at the corresponding position in the third tree structure data to obtain the first tree structure data; wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

[0147] In some optional embodiments, the conversion module 30 is further configured to obtain row attribute information of the same rows in the current table data and the comparison table data, wherein the row attribute information includes at least one of variable name, data type, initial value, power-off retention, network exposure, comment, soft device address, and allocation address; determine whether the row attribute information of the same rows in the current table data and the comparison table data are consistent, and determine the difference between the current table data and the comparison table data.

[0148] In some optional embodiments, the variable comparison device of the programmable logic controller further includes a synchronization module 40, which is used to determine, upon receiving a variable synchronization instruction, a difference row in the comparison table data that differs from the current table data; determine whether the data in the difference row supports synchronization; and, if the data in the difference row supports synchronization, replace the data in the current table data that is the same as the difference row with the data in the difference row.

[0149] Furthermore, based on the above embodiments, the present invention also proposes a variable comparison device for a programmable logic controller (PLC). The PLC variable comparison device includes: a memory, a processor, and a PLC variable comparison program stored in the memory and executable on the processor. When the PLC variable comparison program is executed by the processor, it implements the steps of the PLC variable comparison method of any of the above embodiments.

[0150] Furthermore, based on the above embodiments, the present invention also proposes a computer-readable storage medium for use in a computer. The computer-readable storage medium may be a non-volatile computer-readable storage medium, and a computer program is stored on the computer program. When the computer program is executed by a processor, it implements the variable comparison method of a programmable logic controller as described in any of the embodiments above.

[0151] Furthermore, based on the above embodiments, this application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the variable comparison method of a programmable logic controller as described in any of the embodiments above.

[0152] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically contain computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0153] The above is a detailed description of the preferred embodiments of this application. However, the embodiments of this application are not limited to the above-described implementation methods. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the embodiments of this application. All such equivalent modifications or substitutions are included within the scope defined by the claims of the embodiments of this application.

Claims

1. A variable comparison method for a programmable logic controller, characterized in that, The variable comparison method of the programmable logic controller includes: Upon receiving a variable comparison instruction, the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project are obtained. The current variable data is converted into current table data, and the comparison variable data is converted into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; Compare the current table data with the comparison table data to determine the differences between the current table data and the comparison table data; The steps of converting the current variable data into current table data and converting the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data, include: The current variable data is converted into first tree structure data, and the comparison variable data is converted into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data; The first tree structure data is converted into the current table data, and the second tree structure data is converted into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; The steps of converting the current variable data into first tree structure data and converting the comparison variable data into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include: Convert the current variable data into first table data, and convert the comparison variable data into second table data; The first table data is converted into a third tree structure data, and the second table data is converted into a fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data. The tree structure of the third tree structure data is adjusted to obtain the first tree structure data; and the tree structure of the fourth tree structure data is adjusted to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

2. The variable comparison method for a programmable logic controller as described in claim 1, characterized in that, The steps of adjusting the tree structure of the third tree structure data to obtain the first tree structure data, and adjusting the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include: The tree nodes of the third tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the fourth tree structure data. If the tree node does not exist in the fourth tree structure data, an empty tree node is inserted at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and, The tree nodes of the fourth tree structure data are traversed layer by layer, and it is determined whether the tree node exists in the third tree structure data. If the tree node does not exist in the third tree structure data, an empty tree node is inserted at the corresponding position in the third tree structure data to obtain the first tree structure data. The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

3. The variable comparison method for a programmable logic controller as described in claim 1, characterized in that, The steps of adjusting the tree structure of the third tree structure data to obtain the first tree structure data, and adjusting the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data, include: The tree nodes of the third tree structure data are traversed layer by layer, and each tree node at each level is converted into a first text language; the tree nodes of the fourth tree structure data are traversed layer by layer, and each tree node at each level is converted into a second text language. Traverse the strings in the first text language and determine whether the string exists in the second text language. If the string does not exist in the second text language, insert an empty tree node at the corresponding position in the fourth tree structure data to obtain the second tree structure data; and, Traverse the strings in the second text language and determine whether the string exists in the first text language. If the string does not exist in the first text language, insert an empty tree node at the corresponding position in the third tree structure data to obtain the first tree structure data. The tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data.

4. The variable comparison method for a programmable logic controller as described in claim 1, characterized in that, The step of comparing the current table data with the comparison table data to determine the difference between the current table data and the comparison table data includes: Obtain row attribute information for rows that are identical to the current table data and the comparison table data, wherein the row attribute information includes at least one of variable name, data type, initial value, power-down retention, network exposure, comment, soft device address, and allocation address; Determine whether the row attribute information of the same row in the current table data is consistent with that in the comparison table data, and determine the difference between the current table data and the comparison table data.

5. The variable comparison method for a programmable logic controller as described in claim 1, characterized in that, After the step of comparing the current table data with the comparison table data to determine the difference between the current table data and the comparison table data, the method further includes: Upon receiving a variable synchronization instruction, identify the rows in the comparison table data that differ from the current table data; Determine whether the data in the differing rows supports synchronization; When the data in the differing row supports synchronization, the data in the current table data that is the same as the differing row is replaced with the data in the differing row.

6. A variable comparison device for a programmable logic controller, characterized in that, The variable comparison device of the programmable logic controller includes: The acquisition module is used to acquire the current variable data of the current project of the programmable logic controller and the comparison variable data of the comparison project when a variable comparison instruction is received; A conversion module is used to convert the current variable data into current table data and the comparison variable data into comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; convert the current variable data into first tree structure data and the comparison variable data into second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data; convert the first tree structure data into the current table data and the second tree structure data into the comparison table data, wherein the table structure of the current table data is consistent with the table structure of the comparison table data; and convert the current variable data into first tree structure data into current table data and second tree structure data into comparison table data. The process involves converting the current variable data into a first table data and converting the comparison variable data into a second table data; converting the first table data into a third tree structure data and converting the second table data into a fourth tree structure data, wherein the table structure of the first table data corresponds to the tree structure of the third tree structure data, and the table structure of the second table data corresponds to the tree structure of the fourth tree structure data; adjusting the tree structure of the third tree structure data to obtain the first tree structure data; and adjusting the tree structure of the fourth tree structure data to obtain the second tree structure data, wherein the tree structure of the first tree structure data is consistent with the tree structure of the second tree structure data. The comparison module is used to compare the current table data with the comparison table data and determine the differences between the current table data and the comparison table data.

7. A variable comparison device for a programmable logic controller, characterized in that, The variable comparison device of the programmable logic controller includes: a memory, a processor, and a variable comparison program of the programmable logic controller stored in the memory and executable on the processor. When the variable comparison program of the programmable logic controller is executed by the processor, it implements the steps of the variable comparison method of the programmable logic controller as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a variable comparison program for a programmable logic controller, which, when executed by a processor, implements the steps of the variable comparison method for a programmable logic controller as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • PLC program processing method and device and server

    CN115903642A

  • Systems and methods for logical data processing

    US10853453B1