Search

CN-122018487-A - PLC program dependency detection method and system based on multidimensional dependency graph

CN122018487ACN 122018487 ACN122018487 ACN 122018487ACN-122018487-A

Abstract

The invention relates to a PLC program dependency detection method and system based on a multidimensional dependency graph, wherein the method carries out semantic analysis on source codes of a PLC program to extract all program organization units, metadata of each program organization unit and explicit association relations among the program organization units, deduces implicit dependency relations among the program organization units, takes the metadata of each program organization unit as an initial node, establishes explicit call dependency edges and implicit data dependency edges among the corresponding initial nodes based on the corresponding explicit call relations and the implicit dependency relations, so as to form the multidimensional dependency graph, and when the PLC program is modified, only carries out local update on the explicit call dependency edges and the implicit data dependency edges of the association nodes influenced by the modified program organization units, so as to obtain the multidimensional dependency graph after local update. Therefore, the invention realizes the coverage of the full-dimension dependence and simultaneously gives consideration to the analysis efficiency, thereby meeting the requirements of industrial practical application.

Inventors

  • ZENG ZHENZHEN
  • OU XINMU
  • FU CHUNQI
  • XU SHAOHUI
  • Zhou Honglv
  • NIE HUAXING
  • XIE LINJIAN

Assignees

  • 福建富昌维控电子科技股份有限公司

Dates

Publication Date
20260512
Application Date
20260204

Claims (10)

  1. 1. A PLC program dependency detection method based on a multidimensional dependency graph is characterized by comprising the following steps: Acquiring source codes of a PLC program, carrying out semantic analysis on the source codes to extract all program organization units, metadata of each program organization unit and explicit association relations among the program organization units, wherein the explicit association relations comprise explicit calling relations and explicit reading-writing relations; Deducing an implicit dependency relationship between program organization units based on the metadata of each program organization unit and the explicit association relationship between the program organization units, taking the metadata of each program organization unit as an initial node, establishing explicit call dependency edges between the initial nodes based on the corresponding explicit call relationship, and simultaneously establishing implicit data dependency edges between the initial nodes based on the corresponding implicit dependency relationship to form a multidimensional dependency graph containing the explicit call dependency edges and the implicit data dependency edges; When the PLC program is detected to be modified, only carrying out semantic analysis on source codes corresponding to the modified PLC program to extract modified program organization units, screening associated nodes influenced by the modified program organization units based on the multidimensional dependency graph, and carrying out local updating on explicit call dependency edges and implicit data dependency edges of the associated nodes to obtain a locally updated multidimensional dependency graph.
  2. 2. The PLC program dependency detection method according to claim 1, wherein the performing semantic analysis on the source code to extract all program organization units, metadata of each program organization unit, and explicit association between program organization units includes: Decomposing the source code into a standardized symbol sequence based on an IEC 61131-3 international standard, constructing the standardized symbol sequence into an abstract syntax tree based on a context-free grammar in the IEC 61131-3 international standard, and traversing the abstract syntax tree to extract all program organization units, metadata of each program organization unit and explicit association relations among the program organization units; The normalized token sequence includes an identifier, a keyword, an operator, and a separator.
  3. 3. The PLC program dependency detection method according to claim 1, wherein the metadata includes global variables and data blocks, the explicit read-write relationship includes explicit read-write relationship of global variables and explicit read-write relationship of data blocks, and deriving the implicit dependency relationship between program organization units based on the explicit read-write relationship between program organization units includes: Judging whether the global variable and/or the data block read by the first program organization unit in any two program organization units is the global variable and/or the data block written by the second program organization unit, and if so, deducing the implicit dependency relationship of the first program organization unit affected by the second program organization unit.
  4. 4. The PLC program dependency detection method according to claim 1, wherein the explicit call dependency edge and the implicit data dependency edge are directed edges, the explicit call dependency edge points to a called program organization unit for a main call, and the implicit data dependency edge points to a written program organization unit for a read program organization unit.
  5. 5. The PLC program dependency detection method according to claim 1, wherein the filtering the associated node affected by the modified program organization unit based on the multidimensional dependency graph, and locally updating the explicit call dependency edge and/or the implicit data dependency edge of the associated node to obtain the locally updated multidimensional dependency graph includes: Screening explicit call dependency edges existing with the modified program organization units from the multidimensional dependency graph, and/or taking initial nodes of the implicit data dependency edges as associated nodes influenced by the modified program organization units, and taking the corresponding explicit call dependency edges and/or the implicit data dependency edges as old dependency edges; Obtaining new metadata of the modified program organization unit and new explicit association relation between the modified program organization unit and the association node, deriving new implicit dependency relation, and carrying out local update on the old-fashioned dependency side based on the new explicit association relation and the new implicit dependency relation to obtain a multidimensional dependency graph after local update.
  6. 6. The PLC program dependency detection method based on a multi-dimensional dependency graph as claimed in claim 5, wherein the obtaining the locally updated multi-dimensional dependency graph comprises: Judging whether the associated node in the multi-dimensional dependency graph after local updating generates a new indirect influence node, if so, establishing a new explicit association relation between the new indirect influence node and the associated node and deducing a new implicit dependency relation so as to carry out multiple updating on the multi-dimensional dependency graph after local updating until no new indirect influence node is generated in the multi-dimensional dependency graph after multiple updating, thereby obtaining the final multi-dimensional dependency graph after local updating.
  7. 7. The PLC program dependency detection method based on a multi-dimensional dependency graph as claimed in claim 6, wherein the obtaining the final locally updated multi-dimensional dependency graph comprises: And carrying out consistency check on the final locally updated multidimensional dependency graph, judging whether the new explicit association relationship and the new implicit dependency relationship are consistent with the modified program organization unit and the execution logic of the association node, if so, outputting an abnormal explicit call dependency edge and/or an abnormal implicit data dependency edge by the final locally updated multidimensional dependency graph through the consistency check, otherwise.
  8. 8. The PLC program dependency detection method according to claim 1, wherein the obtaining the locally updated multi-dimensional dependency graph further comprises: Based on the locally updated multidimensional dependency graph, starting from any initial node, recursively traversing all explicit call dependency edges and/or adjacent nodes of implicit data dependency edges, if the same adjacent node is accessed more than once in the current traversing path in the recursion traversing process, generating the circularly dependent alarm information, and feeding back the circularly dependent alarm information to a PLC configuration software editing interface.
  9. 9. The PLC program dependency detection method based on a multi-dimensional dependency graph according to claim 1, wherein the locally updated multi-dimensional dependency graph is displayed in a visual form.
  10. 10. A PLC program dependency detection system based on a multi-dimensional dependency graph, comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 8 when executing the computer program.

Description

PLC program dependency detection method and system based on multidimensional dependency graph Technical Field The invention relates to the field of industrial control, in particular to a PLC program dependency detection method and system based on a multidimensional dependency graph. Background In the industrial control system, a PLC (Programmable Logic Controller ) is used as a core control unit, and the stability and reliability of the program directly determine the continuity and safety of industrial production. Along with the improvement of the industrial automation level, the complexity of the PLC program is greatly increased, and the PLC program not only relates to a multi-language mixed programming scene, but also has a great number of complex dependency relations. The dependence analysis of the current PLC program has a plurality of limitations, so that the requirements of industrial practical application are difficult to meet, firstly, the dependence coverage is incomplete, only the direct calling dependence of a function or function block level is detected, indirect dependence cannot be identified or the dependence cannot be found until the actual running of the PLC program is needed, the PLC program is unreliable and difficult to maintain, secondly, the analysis efficiency is low, and aiming at large projects, a full analysis mode is generally adopted, so that the time consumption is long and the suitability is poor. Therefore, a PLC program-dependent detection scheme that covers full-dimension dependence and gives consideration to analysis efficiency is needed to meet the needs of industrial practical applications. Disclosure of Invention The invention aims to solve the technical problem that the invention provides a PLC program dependency detection method and system based on a multidimensional dependency graph, which can realize the coverage of full-dimensional dependency and simultaneously consider analysis efficiency, thereby meeting the requirements of industrial practical application. In order to solve the technical problems, the invention adopts the following technical scheme: In a first aspect, the present invention provides a PLC program dependency detection method based on a multidimensional dependency graph, including: Acquiring source codes of a PLC program, carrying out semantic analysis on the source codes to extract all program organization units, metadata of each program organization unit and explicit association relations among the program organization units, wherein the explicit association relations comprise explicit calling relations and explicit reading-writing relations; Deducing an implicit dependency relationship between program organization units based on the metadata of each program organization unit and the explicit association relationship between the program organization units, taking the metadata of each program organization unit as an initial node, establishing explicit call dependency edges between the initial nodes based on the corresponding explicit call relationship, and simultaneously establishing implicit data dependency edges between the initial nodes based on the corresponding implicit dependency relationship to form a multidimensional dependency graph containing the explicit call dependency edges and the implicit data dependency edges; When the PLC program is detected to be modified, only carrying out semantic analysis on source codes corresponding to the modified PLC program to extract modified program organization units, screening associated nodes influenced by the modified program organization units based on the multidimensional dependency graph, and carrying out local updating on explicit call dependency edges and implicit data dependency edges of the associated nodes to obtain a locally updated multidimensional dependency graph. The method has the advantages that all program organization units, metadata of each program organization unit and explicit association relations among the program organization units are extracted through semantic analysis, implicit dependency relations among the program organization units are deduced based on the explicit association relations, a multidimensional dependency graph fused with explicit calling dependency edges and implicit data dependency edges is constructed, the limitation that only single explicit dependency can be identified by a traditional method is broken, full-dimensional dependency of a covered PLC program is achieved, and the problem of PLC debugging and positioning ambiguity caused by incomplete dependent carding is avoided. Aiming at the scene of the modified PLC program, only the source codes corresponding to the modified PLC program are subjected to semantic analysis again, the affected associated nodes are screened out, the local update of the explicit call dependency edges and the implicit data dependency edges is carried out, the full reconstruction of the multidimensional dependency graph is not n