PLC program dependency detection method and system based on multi-dimensional dependency graph

By constructing a multi-dimensional dependency graph and performing local updates, the problems of incomplete and inefficient PLC program dependency analysis are solved, achieving full-dimensional coverage and efficient analysis, thus meeting the needs of industrial applications.

CN122018487APending Publication Date: 2026-05-12FUZHOU WECON ELECTRONICS TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
FUZHOU WECON ELECTRONICS TECH
Filing Date
2026-02-04
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

Existing PLC program dependency analysis suffers from incomplete coverage and low analysis efficiency, making it difficult to meet the needs of actual industrial applications.

Method used

A PLC program dependency detection method based on multi-dimensional dependency graphs is adopted. Metadata and explicit associations of program organization units are extracted through semantic analysis, implicit dependencies are derived, a multi-dimensional dependency graph is constructed, and local updates are performed when the PLC program is modified.

Benefits of technology

It achieves full-dimensional dependency coverage, improves analysis efficiency, meets the real-time and high-efficiency requirements of industrial applications, reduces analysis time, and improves the iteration and maintenance efficiency of PLC programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122018487A_ABST
    Figure CN122018487A_ABST
Patent Text Reader

Abstract

The invention relates to a PLC program dependency detection method and system based on a multi-dimensional dependency graph, and the method comprises the steps: carrying out the semantic analysis of a source code of a PLC program, so as to extract all program organization units, the metadata of each program organization unit, and the explicit incidence relation between the program organization units; the method comprises the following steps of: establishing an explicit calling dependency edge and an implicit data dependency edge between corresponding initial nodes on the basis of a corresponding explicit calling relationship and an implicit dependency relationship by taking metadata of each program organization unit as the initial node, so as to form a multi-dimensional dependency graph, and establishing an explicit calling dependency edge and an implicit data dependency edge between the initial nodes on the basis of the corresponding explicit calling relationship and the implicit dependency relationship; and when the PLC program is modified, only the explicit calling dependency edge and the implicit data dependency edge of the associated node influenced by the modified program organization unit are locally updated, so that a locally updated multi-dimensional dependency graph is obtained. Therefore, the analysis efficiency is considered while full-dimension dependence is covered, and the industrial practical application requirement is met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial control, and in particular to a PLC program dependency detection method and system based on a multi-dimensional dependency graph. Background Technology

[0002] In industrial control systems, the PLC (Programmable Logic Controller) serves as the core control unit, and the stability and reliability of its program directly determine the continuity and safety of industrial production. With the increasing level of industrial automation, the complexity of PLC programs has increased significantly, involving not only multi-language mixed programming scenarios but also numerous complex dependencies.

[0003] Currently, dependency analysis in PLC programs has many limitations and cannot meet the needs of actual industrial applications: First, dependency coverage is incomplete, only detecting direct call dependencies at the function or function block level, failing to identify indirect dependencies, or requiring the PLC program to be actually run to discover indirect dependencies, resulting in unreliable and difficult-to-maintain PLC programs; Second, analysis efficiency is low, for large projects, a full analysis mode is usually adopted, which is time-consuming and has poor adaptability.

[0004] Therefore, there is an urgent need for a PLC program dependency detection solution that covers all dimensions of dependency while also taking into account analysis efficiency, in order to meet the needs of practical industrial applications. Summary of the Invention

[0005] The technical problem to be solved by the present invention is: the present invention provides a PLC program dependency detection method and system based on multi-dimensional dependency graph, which can cover all dimensions of dependency while taking into account analysis efficiency, and meet the needs of actual industrial applications.

[0006] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: In a first aspect, the present invention provides a PLC program dependency detection method based on a multi-dimensional dependency graph, comprising: Obtain the source code of the PLC program, perform semantic analysis on the source code to extract all program organization units, the metadata of each program organization unit, and the explicit associations between program organization units. The explicit associations include explicit call relationships and explicit read-write relationships. Based on the metadata of each program organization unit and the explicit associations between program organization units, the implicit dependencies between program organization units are derived. Taking the metadata of each program organization unit as the initial node, explicit call dependency edges between the initial nodes are established based on the corresponding explicit call relationships. At the same time, implicit data dependency edges between the initial nodes are established based on the corresponding implicit dependencies, so as to form a multi-dimensional dependency graph containing explicit call dependency edges and implicit data dependency edges. When the PLC program is detected to have been modified, semantic analysis is performed only on the source code corresponding to the modified PLC program to extract the modified program organization unit. Based on the multi-dimensional dependency graph, the associated nodes affected by the modified program organization unit are selected, and the explicit call dependency edges and implicit data dependency edges of the associated nodes are locally updated to obtain the locally updated multi-dimensional dependency graph.

[0007] The beneficial effects of this invention are as follows: Semantic analysis extracts all program organizational units, the metadata of each program organizational unit, and the explicit relationships between program organizational units. Based on this, implicit dependencies between program organizational units are derived, constructing a multi-dimensional dependency graph that integrates explicit call dependencies and implicit data dependencies. This breaks the limitation of traditional methods that can only identify single explicit dependencies, achieving full-dimensional dependency coverage of PLC programs and avoiding the problem of unclear PLC debugging and positioning due to incomplete dependency analysis. For scenarios where PLC programs are modified, semantic analysis is only performed on the source code corresponding to the modified PLC program to filter out affected related nodes and perform partial updates of explicit call dependencies and implicit data dependencies. This eliminates the need for a full reconstruction of the multi-dimensional dependency graph, significantly reducing the time consumption of dependency analysis in PLC projects, improving analysis efficiency, and balancing the real-time nature and efficiency of PLC program iteration to meet the needs of practical industrial applications.

[0008] Optionally, the step of performing semantic analysis on the source code to extract all program organizational units, the metadata of each program organizational unit, and the explicit associations between program organizational units includes: Based on the IEC 61131-3 international standard, the source code is decomposed into a standardized notation sequence, and based on the context-free grammar in the IEC 61131-3 international standard, the standardized notation sequence is constructed into an abstract syntax tree. The abstract syntax tree is traversed to extract all program organization units, the metadata of each program organization unit, and the explicit associations between program organization units. The standardized notation sequence includes identifiers, keywords, operators, and delimiters.

[0009] As described above, clarifying the specific structure of the standardized notation sequence makes source code decomposition more operable and avoids ambiguity in the obtained standardized notation sequence. Based on the IEC 61131-3 international standard, the source code is decomposed and an abstract syntax tree is constructed to achieve compatibility with various source codes of multiple languages ​​that conform to this international standard. This ensures the accuracy of the extracted program organization units, the metadata of each program organization unit, and the explicit relationships between program organization units, and avoids problems such as metadata omission and mis-extraction caused by non-standards.

[0010] Optionally, the metadata includes global variables and data blocks, the explicit read-write relationships include explicit read-write relationships of global variables and explicit read-write relationships of data blocks, and the derivation of implicit dependencies between program organizational units based on explicit read-write relationships between program organizational units includes: Determine whether the global variables and / or data blocks read by the first program organization unit in any two program organization units are the same global variables and / or data blocks written by the second program organization unit. If so, deduce the implicit dependency relationship between the first program organization unit and the second program organization unit.

[0011] As described above, explicit read-write relationships include two types of data objects. This avoids the omission of implicit dependencies due to incomplete coverage of data objects, improves the comprehensiveness and accuracy of the derived implicit dependencies, and ensures the consistency of the derivation logic in different scenarios by using clear read-write judgment rules, thereby improving the reliability of the derived implicit dependencies.

[0012] Optionally, both the explicit call dependency edge and the implicit data dependency edge are directed edges. The explicit call dependency edge points from the calling program organization unit to the called program organization unit, and the implicit data dependency edge points from the reading program organization unit to the writing program organization unit.

[0013] As described above, explicitly invoking the directionality of dependency edges and privacy data dependency edges enables the multi-dimensional dependency graph to intuitively reflect the flow of dependency relationships, facilitating rapid tracing of dependency paths, improving readability, and reducing the complexity of analysis.

[0014] Optionally, the step of filtering out the associated nodes affected by the modified program organization unit based on the multi-dimensional dependency graph, and locally updating the explicit call dependency edges and / or implicit data dependency edges of the associated nodes to obtain a locally updated multi-dimensional dependency graph includes: The initial nodes that have explicit call dependency edges and / or implicit data dependency edges with the modified program organization unit are selected from the multidimensional dependency graph as the associated nodes affected by the modified program organization unit, and the corresponding explicit call dependency edges and / or implicit data dependency edges are designated as old dependency edges. Obtain the new metadata of the modified program organization unit and the new explicit association relationship with the associated node, and deduce the new implicit dependency relationship. Based on the new explicit association relationship and the new implicit dependency relationship, locally update the old dependency edge to obtain the locally updated multi-dimensional dependency graph.

[0015] As described above, the initial node that has explicit call edges and / or implicit data dependency edges with the modified program organization unit is taken as the associated node. This ensures the objectivity of the obtained associated nodes. When performing local updates, the focus is also on the old dependency edges to perform local updates, avoiding invalid operations on irrelevant initial nodes and irrelevant dependency edges, and improving the accuracy of local updates.

[0016] Optionally, obtaining the locally updated multi-dimensional dependency graph includes: Determine whether the associated nodes in the partially updated multidimensional dependency graph generate new indirectly affected nodes. If so, establish new explicit associations between the new indirectly affected nodes and the associated nodes and derive new implicit dependencies. Perform multiple updates on the partially updated multidimensional dependency graph until no new indirectly affected nodes are generated in the multidimensional dependency graph after multiple updates, so as to obtain the final partially updated multidimensional dependency graph.

[0017] As described above, by taking into account the new indirectly affected nodes generated by associated nodes, we can avoid local updates that only cover directly associated nodes and miss the indirectly affected nodes with chain reactions caused by the dependency changes of associated nodes. This enables full-link updates of the multi-dimensional dependency graph and improves the completeness and reliability of the multi-dimensional dependency graph after the final local update.

[0018] Optionally, obtaining the final locally updated multi-dimensional dependency graph includes: Perform a consistency check on the final partially updated multi-dimensional dependency graph to determine whether the new explicit associations and new implicit dependencies are consistent with the modified program organization unit and the execution logic of the associated nodes. If so, the final partially updated multi-dimensional dependency graph passes the consistency check; otherwise, output abnormal explicit call dependency edges and / or abnormal implicit data dependency edges.

[0019] As described above, consistency checks ensure that the new explicit associations and implicit dependencies in the final partially updated multi-dimensional dependency graph are consistent with the modified program organization units and the execution logic of the associated nodes. This effectively avoids invalid or erroneous explicit call dependency edges and / or implicit data dependency edges in the final partially updated multi-dimensional dependency graph, improving its reliability. Furthermore, for cases where consistency checks fail, the system precisely locates and outputs abnormal explicit call dependency edges and / or abnormal implicit data dependency edges, rather than issuing general alerts. This provides engineers with clear indications of the anomalies, shortening troubleshooting time.

[0020] Optionally, obtaining the locally updated multi-dimensional dependency graph further includes: Based on the locally updated multi-dimensional dependency graph, starting from any initial node, recursively traverse all adjacent nodes of explicit call dependency edges and / or implicit data dependency edges. If the same adjacent node is visited more than once in the current traversal path during the recursive traversal, a circular dependency alarm message is generated and the circular dependency alarm message is fed back to the PLC configuration software editing interface.

[0021] As described above, the automatic detection of circular dependencies in the multi-dimensional dependency graph after partial updates avoids the problems of missed detections, false detections, and low efficiency of manual traversal detection, improves the accuracy of circular dependency detection, and directly feeds circular dependency alarm information to the PLC configuration software editing interface, achieving seamless integration with engineering development scenarios. This allows engineers to perceive circular dependency alarms in real time without having to query across platforms, thus improving the efficiency of risk investigation.

[0022] Optionally, the locally updated multidimensional dependency graph is displayed in a visual form.

[0023] As described above, displaying the multi-dimensional dependency graph after partial updates in a visual format allows engineers to intuitively obtain various types of information, improving the overall efficiency of PLC program development, debugging, and maintenance.

[0024] Secondly, the present invention provides a PLC program dependency detection system based on a multi-dimensional dependency graph, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the PLC program dependency detection method based on a multi-dimensional dependency graph described in the first aspect.

[0025] The technical effects of the PLC program dependency detection system based on multi-dimensional dependency graph provided in the second aspect are the same as those of the PLC program dependency detection method based on multi-dimensional dependency graph provided in the first aspect. Attached Figure Description

[0026] Figure 1 This is a flowchart of a PLC program dependency detection method based on a multi-dimensional dependency graph provided in this embodiment; Figure 2 This is a schematic diagram of the overall process of a PLC program dependency detection method based on a multi-dimensional dependency graph provided in this embodiment; Figure 3 This is a schematic diagram of the structure of a PLC program dependency detection system based on a multi-dimensional dependency graph provided in this embodiment.

[0027] [Explanation of Labels in the Attached Image] 1. A PLC program dependency detection system based on a multi-dimensional dependency graph; 2. Processor; 3. Memory. Detailed Implementation

[0028] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.

[0029] Example 1 Please refer to Figures 1 to 2 This invention provides a PLC program dependency detection method based on a multi-dimensional dependency graph, comprising the following steps: S1. Obtain the source code of the PLC program, perform semantic analysis on the source code to extract all program organization units, the metadata of each program organization unit, and the explicit association relationships between program organization units. The explicit association relationships include explicit call relationships and explicit read / write relationships. In this embodiment, as Figure 2 As shown, the source code of the PLC program is obtained, and semantic analysis is performed on the source code to extract all program organizational units, the metadata of each program organizational unit, and the explicit relationships between program organizational units. The metadata includes: global variables, data blocks, function blocks, functions, program names, types, etc. The explicit relationships include explicit call relationships and explicit read-write relationships. Explicit call relationships refer to the call relationship between functions or function blocks, and explicit read-write relationships refer to the read and write operations between global variables and data blocks.

[0030] At this point, the semantic analysis of the source code in step S1 to extract all program organizational units, the metadata of each program organizational unit, and the explicit associations between program organizational units includes: S11. Based on the IEC 61131-3 international standard, the source code is decomposed into a standardized token sequence, and based on the context-free grammar in the IEC 61131-3 international standard, the standardized token sequence is constructed into an abstract syntax tree. The abstract syntax tree is traversed to extract all program organization units, the metadata of each program organization unit, and the explicit associations between program organization units. The standardized notation sequence includes identifiers, keywords, operators, and delimiters.

[0031] In this embodiment, as Figure 2As shown, based on the IEC 61131-3 international standard, the source code is decomposed into a standardized token sequence. The source code can be in various languages, such as structured text, function block diagrams, and ladder diagrams. The standardized token sequence includes identifiers, keywords, operators, and delimiters. Based on the context-free grammar in the IEC 61131-3 international standard, the standardized token sequence is constructed into an abstract syntax tree. That is, an AST is constructed, and the abstract syntax tree is traversed to extract all program organization units. At the same time, the metadata of each program organization unit and the explicit associations between program organization units are parsed and extracted.

[0032] S2. Based on the metadata of each program organization unit and the explicit association between program organization units, deduce the implicit dependency relationship between program organization units. Taking the metadata of each program organization unit as the initial node, establish explicit call dependency edges between the initial nodes based on the corresponding explicit call relationship, and at the same time establish implicit data dependency edges between the initial nodes based on the corresponding implicit dependency relationship, so as to form a multi-dimensional dependency graph containing explicit call dependency edges and implicit data dependency edges. In this embodiment, as Figure 2 As shown, implicit dependencies between program organizational units are derived based on the metadata of each program organizational unit and the explicit associations between them. Each program organizational unit's metadata serves as an initial node, containing corresponding node information, including a unique ID, the name of a global variable, and the node type. Explicit call dependency edges are established between the initial nodes based on the corresponding explicit call relationships. These explicit call dependency edges are directed edges, pointing from the calling program organizational unit to the called program organizational unit. Simultaneously, implicit data dependency edges are established between the initial nodes based on the corresponding implicit dependencies. These implicit data dependency edges are also directed edges, pointing from the reading program organizational unit to the writing program organizational unit. Both explicit call dependency edges and implicit data dependency edges contain corresponding dependency information, including edge type, context information, and edge information. The context information includes the access location information, and the edge information includes the specific calling and reading / writing program organizational units.

[0033] At this point, the metadata mentioned in step S2 includes global variables and data blocks, the explicit read-write relationship includes the explicit read-write relationship of global variables and the explicit read-write relationship of data blocks, and the derivation of the implicit dependency relationship between program organizational units based on the explicit read-write relationship between program organizational units includes: S21. Determine whether the global variables and / or data blocks read by the first program organization unit in any two program organization units are the same global variables and / or data blocks written by the second program organization unit. If so, deduce the implicit dependency relationship between the first program organization unit and the second program organization unit.

[0034] In this embodiment, as Figure 2 As shown, the derivation of implicit dependencies is achieved by determining whether the global variables and / or data blocks read by the first program organization unit are the same global variables and / or data blocks written by the second program organization unit. If so, it indicates that there is an implicit dependency between the two, namely: an implicit dependency in which the first program organization unit is affected by the second program organization unit.

[0035] For example: if the global variable read by the first program organization unit A is V, then the record is: A→V (read dependency); If the global variable written by the second program organization unit B is V, then the record is: B→V (write dependency); Therefore, it can be concluded that the execution result of the first program organization unit A is affected by the global variable V, and the global variable V is written by the second program organization unit B. Thus, we obtain the implicit dependency relationship that the first program organization unit A is affected by the second program organization unit B, and the constructed implicit data dependency edge is: A→B.

[0036] S3. When the PLC program is detected to have been modified, semantic analysis is performed only on the source code corresponding to the modified PLC program to extract the modified program organization unit. Based on the multi-dimensional dependency graph, the associated nodes affected by the modified program organization unit are selected. The explicit call dependency edges and implicit data dependency edges of the associated nodes are locally updated to obtain the locally updated multi-dimensional dependency graph.

[0037] At this point, step S3, which involves filtering out the associated nodes affected by the modified program organization unit based on the multi-dimensional dependency graph, and locally updating the explicit call dependency edges and / or implicit data dependency edges of the associated nodes to obtain the locally updated multi-dimensional dependency graph, includes: S31. Select the initial nodes that have explicit call dependency edges and / or implicit data dependency edges with the modified program organization unit from the multidimensional dependency graph as the associated nodes affected by the modified program organization unit, and take the corresponding explicit call dependency edges and / or implicit data dependency edges as old dependency edges. S32. Obtain the new metadata of the modified program organization unit and the new explicit association relationship with the associated node, and deduce the new implicit dependency relationship. Based on the new explicit association relationship and the new implicit dependency relationship, locally update the old dependency edge to obtain the locally updated multi-dimensional dependency graph.

[0038] In this embodiment, as Figure 2 As shown, when a modification to the PLC program is detected, semantic analysis is performed only on the source code corresponding to the modified PLC program to extract the modified program organization unit. Then, based on the multi-dimensional dependency graph, the initial node that has explicit call dependency edge and / or implicit data dependency edge with the modified program organization unit is selected as the associated node affected by the modified program organization unit. The explicit call dependency edge and / or implicit data dependency edge corresponding to the associated node, that is, the explicit call dependency edge and / or implicit data dependency edge existing in the previous step, is taken as the old dependency edge. The system retrieves new metadata of the modified program organization unit and new explicit associations with associated nodes, and derives new implicit dependencies. Based on the new explicit associations and new implicit dependencies, it performs local updates on the old dependency edges to obtain a locally updated multi-dimensional dependency graph. The locally updated multi-dimensional dependency graph is then displayed in a visual format. When an engineer selects the initial node in the locally updated multi-dimensional dependency graph, the system displays the node information and dependency information of that initial node, and provides navigation operations such as "Go to Definition" and "Find Reference," as well as direct navigation to related associated nodes.

[0039] At this point, the step S32 described in obtaining the locally updated multi-dimensional dependency graph includes: S321. Determine whether the associated nodes in the partially updated multidimensional dependency graph generate new indirectly affected nodes. If so, establish a new explicit association between the new indirectly affected nodes and the associated nodes and derive a new implicit dependency relationship to perform multiple updates on the partially updated multidimensional dependency graph until no new indirectly affected nodes are generated in the multidimensional dependency graph after multiple updates, so as to obtain the final partially updated multidimensional dependency graph.

[0040] In this embodiment, as Figure 2As shown, if a new indirectly affected node is generated in the locally updated multidimensional dependency graph, that is, if the explicit call relationship and / or implicit dependency relationship between the associated node and other initial nodes changes due to this locally updated node, then the corresponding other initial nodes are the new indirectly affected nodes. A new explicit association relationship is established between the new indirectly affected node and the associated node, and a new implicit dependency relationship is derived. This involves using the new indirectly affected node as the new associated node and repeating the locally updated process of steps S31-S32 to perform multiple updates on the locally updated multidimensional dependency graph until no new indirectly affected nodes are generated in the multidimensional dependency graph after multiple updates, thus obtaining the final locally updated multidimensional dependency graph.

[0041] At this point, the step S321, which involves obtaining the final locally updated multi-dimensional dependency graph, includes: S3211. Perform a consistency check on the final partially updated multi-dimensional dependency graph to determine whether the new explicit associations and new implicit dependencies are consistent with the modified program organization unit and the execution logic of the associated nodes. If so, the final partially updated multi-dimensional dependency graph passes the consistency check; otherwise, output abnormal explicit call dependency edges and / or abnormal implicit data dependency edges.

[0042] In this embodiment, as Figure 2 As shown, a new consistency check step is added to perform consistency check on the final locally updated multi-dimensional dependency graph. If the new explicit associations and new implicit dependencies are consistent with the execution logic of the modified program organization units and associated nodes, then the consistency check is passed. Otherwise, abnormal explicit call dependency edges and / or abnormal implicit data dependency edges are output.

[0043] At this point, step S3, which involves obtaining the locally updated multi-dimensional dependency graph, also includes: S33. Based on the locally updated multi-dimensional dependency graph, starting from any initial node, recursively traverse all adjacent nodes of explicit call dependency edges and / or implicit data dependency edges. If the same adjacent node is visited more than once in the current traversal path during the recursive traversal, a circular dependency alarm message is generated and the circular dependency alarm message is fed back to the PLC configuration software editing interface.

[0044] In this embodiment, as Figure 2As shown, the obtained locally updated multi-dimensional dependency graph will also undergo cyclic dependency detection. Starting from any initial node, all adjacent nodes of explicitly invoked dependent edges and / or implicit data dependent edges are recursively traversed. If the same adjacent node is visited more than once in the current traversal path during the recursive traversal, a cyclic dependency alarm is generated and fed back to the PLC configuration software editing interface. The PLC configuration software editing interface will highlight this with a red underline and generate a list of cyclic dependency paths corresponding to the cyclic dependency alarm. The list of cyclic dependency paths clearly indicates the adjacent nodes and the type of dependent edges involved in the cyclic dependency, i.e., whether it is an explicitly invoked dependent edge or an implicit data dependent edge.

[0045] Example 2 Please refer to Figure 3 The present invention provides a PLC program dependency detection system 1 based on a multi-dimensional dependency graph, including a memory 3, a processor 2, and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, it implements the steps in Embodiment 1.

[0046] Since the systems / devices described in the above embodiments of the present invention are systems / devices used to implement the methods of the above embodiments of the present invention, those skilled in the art can understand the specific structure and modifications of the systems / devices based on the methods described in the above embodiments of the present invention, and therefore will not be repeated here. All systems / devices used in the methods of the above embodiments of the present invention fall within the scope of protection of the present invention.

[0047] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0048] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions.

[0049] It should be noted that any reference numerals placed between parentheses in the claims should not be construed as limiting the claims. The word "comprising" does not exclude the presence of components or steps not listed in the claims. The word "a" or "an" preceding a component does not exclude the presence of a plurality of such components. The invention can be implemented by means of hardware comprising several different components and by means of a suitably programmed computer. In claims that enumerate several means, several of these means may be embodied by the same hardware. The use of the terms first, second, third, etc., is merely for convenience of expression and does not indicate any order. These terms can be understood as part of the component names.

[0050] Furthermore, it should be noted that in the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0051] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the claims should be interpreted to include both the preferred embodiments and all changes and modifications falling within the scope of the invention.

[0052] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, then this invention should also include these modifications and variations.

Claims

1. A PLC program dependency detection method based on a multi-dimensional dependency graph, characterized in that, include: Obtain the source code of the PLC program, perform semantic analysis on the source code to extract all program organization units, the metadata of each program organization unit, and the explicit associations between program organization units. The explicit associations include explicit call relationships and explicit read-write relationships. Based on the metadata of each program organization unit and the explicit associations between program organization units, the implicit dependencies between program organization units are derived. Taking the metadata of each program organization unit as the initial node, explicit call dependency edges between the initial nodes are established based on the corresponding explicit call relationships. At the same time, implicit data dependency edges between the initial nodes are established based on the corresponding implicit dependencies, so as to form a multi-dimensional dependency graph containing explicit call dependency edges and implicit data dependency edges. When the PLC program is detected to have been modified, semantic analysis is performed only on the source code corresponding to the modified PLC program to extract the modified program organization unit. Based on the multi-dimensional dependency graph, the associated nodes affected by the modified program organization unit are selected, and the explicit call dependency edges and implicit data dependency edges of the associated nodes are locally updated to obtain the locally updated multi-dimensional dependency graph.

2. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, The semantic analysis of the source code to extract all program organizational units, the metadata of each program organizational unit, and the explicit associations between program organizational units includes: Based on the IEC 61131-3 international standard, the source code is decomposed into a standardized notation sequence, and based on the context-free grammar in the IEC 61131-3 international standard, the standardized notation sequence is constructed into an abstract syntax tree. The abstract syntax tree is traversed to extract all program organization units, the metadata of each program organization unit, and the explicit associations between program organization units. The standardized notation sequence includes identifiers, keywords, operators, and delimiters.

3. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, The metadata includes global variables and data blocks; the explicit read-write relationships include explicit read-write relationships of global variables and explicit read-write relationships of data blocks; the implicit dependencies between program organizational units derived from the explicit read-write relationships between program organizational units include: Determine whether the global variables and / or data blocks read by the first program organization unit in any two program organization units are the same global variables and / or data blocks written by the second program organization unit. If so, deduce the implicit dependency relationship between the first program organization unit and the second program organization unit.

4. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, Both the explicit call dependency edge and the implicit data dependency edge are directed edges. The explicit call dependency edge points from the calling program organization unit to the called program organization unit, and the implicit data dependency edge points from the reading program organization unit to the writing program organization unit.

5. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, The process of filtering out associated nodes affected by the modified program organization unit based on the multi-dimensional dependency graph, and locally updating the explicit call dependency edges and / or implicit data dependency edges of the associated nodes to obtain a locally updated multi-dimensional dependency graph includes: The initial nodes that have explicit call dependency edges and / or implicit data dependency edges with the modified program organization unit are selected from the multidimensional dependency graph as the associated nodes affected by the modified program organization unit, and the corresponding explicit call dependency edges and / or implicit data dependency edges are designated as old dependency edges. Obtain the new metadata of the modified program organization unit and the new explicit association relationship with the associated node, and deduce the new implicit dependency relationship. Based on the new explicit association relationship and the new implicit dependency relationship, locally update the old dependency edge to obtain the locally updated multi-dimensional dependency graph.

6. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 5, characterized in that, The process of obtaining the locally updated multi-dimensional dependency graph includes: Determine whether the associated nodes in the partially updated multidimensional dependency graph generate new indirectly affected nodes. If so, establish new explicit associations between the new indirectly affected nodes and the associated nodes and derive new implicit dependencies. Perform multiple updates on the partially updated multidimensional dependency graph until no new indirectly affected nodes are generated in the multidimensional dependency graph after multiple updates, so as to obtain the final partially updated multidimensional dependency graph.

7. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 6, characterized in that, The process of obtaining the final locally updated multi-dimensional dependency graph includes: Perform a consistency check on the final partially updated multi-dimensional dependency graph to determine whether the new explicit associations and new implicit dependencies are consistent with the modified program organization unit and the execution logic of the associated nodes. If so, the final partially updated multi-dimensional dependency graph passes the consistency check; otherwise, output abnormal explicit call dependency edges and / or abnormal implicit data dependency edges.

8. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, The process of obtaining the locally updated multi-dimensional dependency graph also includes: Based on the locally updated multi-dimensional dependency graph, starting from any initial node, recursively traverse all adjacent nodes of explicit call dependency edges and / or implicit data dependency edges. If the same adjacent node is visited more than once in the current traversal path during the recursive traversal, a circular dependency alarm message is generated and the circular dependency alarm message is fed back to the PLC configuration software editing interface.

9. The PLC program dependency detection method based on a multi-dimensional dependency graph as described in claim 1, characterized in that, The partially updated multidimensional dependency graph is displayed in a visual format.

10. A PLC program dependency detection system based on a multi-dimensional dependency graph, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.