The invention discloses a method for automatically generating a configuration program based on an SAMA graph, which comprises the following steps: step 1, a preprocessing process: identifying and analyzing SAMA graph legend files of different sources and predefined legend
code segment files, matching legends and code segments, and storing the matched legends and code segments as a component
library; step 2, project file analysis and
information extraction: reading a real SAMA graph, analyzing the project file of the SAMA graph, and obtaining legend and
line segment information; step 3,
error checking and correction: analyzing the
layout and the structure in the SAMA graph, and providing a correction prompt to correct the error; step 4, identifying a connection relationship among legends in the SAMA graph, and storing the connection relationship as a graph-like structure; and 5, traversing the graphic structure, converting the converted graphic structure into an
XML format, and storing the converted graphic structure. According to the method, the SAMA graph can be converted into the corresponding configuration program more quickly and accurately, so that the
workload of engineers is reduced, and the design and implementation efficiency of a
control system is improved.