Method, device, equipment and medium for generating CAD control process by PLC program
By converting the PLC program into XML format and parsing it, combining CAD interface drawing and breadth-first algorithm adjustment flow charts, the automatic generation of PLC programs is realized, solving the inefficiency and inconsistency of manually updating the flow charts in the existing technology, and improving work efficiency and accuracy.
Patent Information
- Application Number
- CN202411879328.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-15
AI Technical Summary
In the prior art, when optimizing PLC programs, it is necessary to manually update the control logic flow chart, resulting in inconsistent with the actual PLC program and inefficient.
By obtaining the PLC program, storing it as XML format, parsing the XML format program to determine the input and output pins and coordinate information of the functional block, drawing the flowchart using the CAD preset interface, and adjusting the flowchart through the breadth priority algorithm to achieve the automatically generated target flowchart.
Improve the work efficiency and accuracy of on-site maintenance personnel, ensure that the flow chart is highly consistent with the PLC program, and avoid inefficiency and errors of manual modification.
Smart Images

Figure CN119828581A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device, equipment and medium for generating a CAD control flow from a PLC program. Background Art
[0002] Programmable logic controller (PLC) is a control device widely used in the field of industrial automation. Its program needs to be continuously optimized and tested for logic defects throughout the life cycle of the equipment.
[0003] In the related technology, many automation equipments in current hydropower stations need to continuously update the corresponding control logic flow charts in the process of continuously optimizing PLC programs to meet the management requirements of technical documents. The current modification methods are based on the technical solutions issued by the technical management department. After modifying the program on site and verifying the program's functions, the control logic flow charts are manually updated.
[0004] Since this process is modified manually, it is inevitable that there will be deviations between the flowchart and the actual PLC program, and the efficiency of manually modifying the flowchart is too low. Summary of the invention
[0005] In view of the above problems, the present application provides a method, device, equipment and medium for generating CAD control flow from a PLC program, which avoids the manual drawing process and improves the work efficiency and accuracy of on-site maintenance personnel.
[0006] In a first aspect, an embodiment of the present application provides a method for generating a CAD control flow from a PLC program, the method comprising:
[0007] Acquire a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word;
[0008] Storing the PLC program as a program in XML format;
[0009] Parsing the program in the XML format to determine the contents of the input pins and the output pins in the function block and the coordinate information corresponding to the function block;
[0010] Based on the coordinate information, a flow chart is drawn using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain target input pins and target output pins and target translation interpretation words that meet the CAD coordinate system;
[0011] Determine the hierarchy of the program in the XML format, and process the program in the XML format using a breadth-first algorithm to determine the number of levels and target coordinates of each control flow in the function block;
[0012] The flowchart is adjusted based on the level, the number of layers and the target coordinates to obtain a target flowchart.
[0013] In some embodiments, the method for generating a CAD control flow from a PLC program further includes:
[0014] Add a standard diagram frame and traceability information to the target flow chart, wherein the traceability information includes: generation time and link object.
[0015] In some embodiments, the program for parsing the XML format includes:
[0016] Determine a first starting position of each variable table in the program in the XML format and a second starting position of each program segment in the program in the XML format;
[0017] The variable table is parsed one by one based on the first starting position to obtain the logical name of the variable and the Chinese comment of the variable. The program segment is parsed one by one based on the second starting position to obtain the file structure parsing information in XML format.
[0018] In some embodiments, the method for generating a CAD control flow from a PLC program further includes:
[0019] After parsing the program in the XML format, a structure is created;
[0020] The structure is used to store the logical name of the variable, the Chinese annotation of the variable and the file structure parsing information.
[0021] In some embodiments, adjusting the flowchart based on the level, the number of layers and the target coordinates to obtain a target flowchart includes:
[0022] Drawing a block diagram of the corresponding functional block in the CAD drawing based on the level, number of layers and target coordinates;
[0023] Determine the connection directions and connection relationships between adjacent block diagrams in the block diagram of the functional block;
[0024] Based on the connection directions and connection relationships, the various block diagrams are connected to form a tree-like flow chart.
[0025] In some embodiments, the method for generating a CAD control flow from a PLC program further includes:
[0026] Determine the maximum number of layers of the program in the XML format based on the breadth-first algorithm;
[0027] The coordinates of each functional block and the coordinates of the connection lines between the functional blocks are adjusted based on the maximum number of layers.
[0028] In some embodiments, the method for generating a CAD control flow from a PLC program further includes:
[0029] Determining a scaling ratio based on the preset requirements for generating a target flow chart in the PLC program, the program in the XML format, and the CAD;
[0030] The flow chart is adjusted based on the zoom ratio.
[0031] In a second aspect, an embodiment of the present application provides a device for generating a CAD control flow from a PLC program, the device comprising:
[0032] An acquisition module, used for acquiring a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word;
[0033] A storage module, used for storing the PLC program as a program in XML format;
[0034] A parsing module, used for parsing the program in XML format, determining the content of the input pins and the output pins in the function block and the coordinate information corresponding to the function block;
[0035] A drawing module, used for drawing a flow chart based on the coordinate information using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain a target input pin and a target output pin and a target translation interpretation word that meet the CAD coordinate system;
[0036] A determination module, used to determine the level of the program in the XML format, and process the program in the XML format using a breadth-first algorithm to determine the number of levels and target coordinates of each control flow in the function block;
[0037] An adjustment module is used to adjust the flowchart based on the level, the number of layers and the target coordinates to obtain a target flowchart.
[0038] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores program code that can be executed on the processor, and when the program code is executed by the processor, the method for generating a CAD control flow from a PLC program as described in any implementation method of the first aspect is implemented.
[0039] In a fourth aspect, an embodiment of the present application provides a computer storage medium storing one or more programs, which can be executed by the electronic device as described in the third aspect to implement the method for generating a CAD control flow from a PLC program as described in any implementation method of the first aspect.
[0040] The embodiments of the present application provide a method, device, equipment and medium for generating CAD control flow from a PLC program. The method obtains a PLC program, stores the PLC program as a program in XML format, parses the program in XML format, determines the contents of input pins and output pins in a function block and coordinate information corresponding to the function block, draws a flow chart using a preset interface in CAD based on the coordinate information, determines the hierarchy of the program in XML format, processes the program in XML format using a breadth-first algorithm to determine the number of layers and target coordinates of each control flow in the function block, adjusts the flow chart based on the hierarchy, number of layers and target coordinates to obtain a target flow chart, and automatically optimizes the block layout according to the number of layers contained in the flow chart. The method can automatically generate a standard frame and traceability information such as generation time and link objects, thereby greatly improving the work efficiency of on-site maintenance personnel and improving the accuracy of their work.
[0041] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Hereinafter, the present application will be described in more detail based on embodiments and with reference to the accompanying drawings.
[0043] Figure 1 A schematic diagram of a method for generating a CAD control flow from a PLC program proposed in an embodiment of the present application is shown;
[0044] Figure 2 A schematic diagram of an exemplary process proposed in an embodiment of the present application is shown;
[0045] Figure 3 An exemplary schematic diagram of obtaining the maximum number of layers of a specific process using a breadth-first algorithm proposed in an embodiment of the present application is shown;
[0046] Figure 4 A schematic diagram showing an exemplary flow chart adjustment proposed in an embodiment of the present application;
[0047] Figure 5 A schematic diagram showing an exemplary PLC function block program proposed in an embodiment of the present application is shown;
[0048] Figure 6A schematic diagram showing an exemplary AUTOCAD format flow chart proposed in an embodiment of the present application;
[0049] Figure 7 A schematic diagram showing an exemplary layout optimization and an AUTOCAD format flow chart after adding a standard drawing frame proposed in an embodiment of the present application is shown;
[0050] Figure 8 A schematic diagram showing an exemplary PLC program variable definition in XML format proposed in an embodiment of the present application is shown;
[0051] Fig. 9 A schematic diagram of an exemplary PLC program function block in XML format proposed in an embodiment of the present application is shown;
[0052] Fig.10 A schematic diagram showing an exemplary XML format file variable table description start position mark proposed in an embodiment of the present application;
[0053] Fig.11 A schematic diagram showing an exemplary XML format file program segment start position mark proposed in an embodiment of the present application;
[0054] Fig.12 A schematic diagram showing an exemplary XML format file function block proposed in an embodiment of the present application;
[0055] Fig.13 A schematic diagram of a program entry function in an exemplary Excel VAB environment proposed in an embodiment of the present application is shown;
[0056] Fig.14 A schematic diagram of the structure of a device for generating a CAD control flow from a PLC program proposed in an embodiment of the present application is shown;
[0057] Fig.15 A structural block diagram of an electronic device for executing the method for generating a CAD control flow from a PLC program according to an embodiment of the present application is shown;
[0058] Fig.16 A computer-readable storage medium for storing or carrying a method for generating a CAD control flow from a PLC program according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0059] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with embodiments and drawings. The exemplary embodiments of the present invention and their description are only used to explain the present invention and are not intended to limit the present invention.
[0060] Programmable logic controllers (PLCs) play a pivotal role in the field of industrial automation, especially in key facilities such as hydropower stations. As a control device, the PLC program is constantly optimized and tested for logic defects throughout the life cycle of the device.
[0061] In the current hydropower station automation equipment, with the continuous optimization of PLC programs, the corresponding control logic flow charts also need to be continuously updated to meet the strict technical document management requirements. However, the existing modification methods have obvious drawbacks. At present, the program is mainly modified on site and its function is verified according to the technical plan issued by the technical management department, and then the control logic flow chart is updated manually.
[0062] After research, it was found that this completely manual modification process would inevitably lead to a series of problems. On the one hand, it was easy for the flowchart to be inconsistent with the actual PLC program, which could cause serious errors and confusion in the subsequent equipment operation and maintenance. On the other hand, the efficiency of manually modifying the flowchart was extremely low, which seriously affected the work progress and the overall advancement of the project.
[0063] In view of this, a new technology is urgently needed to realize the automatic generation of control logic flow chart from PLC program. This can not only ensure the high consistency between the flow chart and the actual program and avoid potential error risks, but also greatly improve work efficiency and provide more reliable and efficient guarantee for the operation and management of automation equipment in hydropower stations.
[0064] In view of the above problems, the applicant has proposed a method, device, equipment and medium for generating a CAD control flow from a PLC program provided in an embodiment of the present application. The method for generating a CAD control flow from a PLC program obtains a PLC program, stores the PLC program as a program in XML format, parses the program in XML format, determines the content of the input pins and output pins in the function block and the coordinate information corresponding to the function block, draws a flowchart based on the coordinate information using a preset interface in CAD, determines the level of the program in XML format, processes the program in XML format using a breadth-first algorithm to determine the number of layers and target coordinates of each control flow in the function block, adjusts the flowchart based on the level, number of layers and target coordinates to obtain a target flowchart, and realizes automatic optimization of the block layout according to the number of levels contained in the flowchart, can automatically generate a standard drawing frame and traceability information such as generation time and link objects, greatly improving the work efficiency of on-site maintenance personnel and improving the accuracy of work. Among them, the method for generating a CAD control flow from a PLC program is described in detail in subsequent embodiments.
[0065] The following is an introduction to the application scenarios of the method for generating a CAD control flow from a PLC program provided in the embodiment of the present application:
[0066] See also Figure 1 , Figure 1 FIG. 1 is a flow chart of a method for generating a CAD control flow from a PLC program provided in an embodiment of the present application. In this embodiment, the method for generating a CAD control flow from a PLC program can be applied to the following: Fig.14 The PLC program generating CAD control flow device 300 shown in FIG. Fig.15 In the electronic device 200 shown, the electronic device 15 includes a computer, a mobile terminal, and the like. Figure 1 The process shown is described in detail, and the method for generating a CAD control process from a PLC program may include S110 to S160.
[0067] S110: Obtain a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word.
[0068] In an embodiment of the present application, when automatically drawing a control logic flow chart for a PLC program, it is necessary to ensure that each variable that needs to be output has a corresponding explanation, wherein the translation interpretation word may include a Chinese interpretation.
[0069] S120: Store the PLC program as a program in XML format.
[0070] S130: Parse the program in XML format to determine the contents of the input pins and output pins in the function block and the coordinate information corresponding to the function block.
[0071] Among them, the function blocks are different after being processed in multiple links. The original PLC program blocks can be referred to Figure 5 The schematic diagram of an exemplary PLC function block program shown in FIG. 1 can be referred to when converted into AUTOCAD format. Figure 6 A schematic diagram of an exemplary AUTOCAD format flowchart is shown.
[0072] S140: Drawing a flow chart based on the coordinate information using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain target input pins and target output pins and target translation interpretation words that satisfy the CAD coordinate system.
[0073] In an embodiment of the present application, VBA can be used to draw in AUTOCAD according to the information of each function block. Since the coordinates of the function blocks in the PLC program are from left to right and from top to bottom, it is necessary to map the coordinate points described in the PLC program first so that the relationship between the mapped coordinate points conforms to the coordinate system of AUTOCAD, draw the input and output pins, and use standard English variable names and Chinese comments.
[0074] S150: Determine the level of the program in XML format, and process the program in XML format using a breadth-first algorithm to determine the number of levels and target coordinates of each control flow in the function block.
[0075] S160: Adjust the flowchart based on the level, number of layers and target coordinates to obtain a target flowchart.
[0076] In an embodiment of the present application, the number of layers of a single control flow is obtained by using a breadth-first algorithm, and then the output AUTOCAD block positions are standardized (generally arranged in the center) according to the plane range (up and down and left and right) involved in each control flow chart and the number of levels included, so as to meet specific standardization requirements.
[0077] In some embodiments, the method for generating a CAD control flow from a PLC program further includes S170.
[0078] S170: Adding a standard frame and traceability information to the target flowchart, wherein the traceability information includes: generation time and link object.
[0079] In an embodiment of the present application, the block layout can be automatically optimized according to the number of levels contained in the flowchart, and the standard frame and traceability information such as generation time and linked objects can be automatically generated, which greatly improves the work efficiency of on-site maintenance personnel, avoids the manual drawing process, and improves the accuracy of the work.
[0080] For example, Figure 6 After adding standard frames and traceability information to the target flowchart, Figure 7 , see Figure 7 , providing a schematic diagram of an exemplary layout optimization and AUTOCAD format flow chart with a standard drawing frame.
[0081] In some embodiments, the procedure of parsing the XML format in S130 includes S131 to S132.
[0082] S131: Determine a first starting position of each variable table in the program in XML format and a second starting position of each program segment in the program in XML format.
[0083] Among them, see Figure 8 , Figure 8 A schematic diagram of the PLC program variable definition in XML format is provided.
[0084] S132: parsing the variable table one by one based on the first starting position to obtain the logical name of the variable and the Chinese comment of the variable, and parsing the program segment one by one based on the second starting position to obtain the file structure parsing information in XML format.
[0085] In the embodiment of the present application, considering that when writing a PLC program, the control logic of each device is often placed in a program segment, and each program segment often contains multiple control flows, it is necessary to retrieve the top-level function blocks, and then output each top-level function block and other linked function blocks accordingly, so as to realize the output of a single control flow.
[0086] In some embodiments, the method for generating a CAD control flow from a PLC program further includes S210 to S220.
[0087] S210: After parsing the program in XML format, a structure is established.
[0088] S220: Using a structure to store the logical name of the variable, the Chinese comment of the variable and the file structure parsing information.
[0089] In the embodiment of the present application, the corresponding information is stored through a structure so as to implement the steps of reversely generating a control logic flow chart from a PLC program in an exchangeable text format.
[0090] In some embodiments, S160 also includes S161 to S163.
[0091] S161: Draw the block diagram of the corresponding functional block in the CAD drawing based on the level, number of layers and target coordinates.
[0092] Among them, see Fig. 9 , Fig. 9 A schematic diagram of an exemplary PLC program function block in XML format provided for this application.
[0093] S162: Determine the connection directions and connection relationships between adjacent block diagrams in the block diagram of the functional block.
[0094] S163: Connect the various block diagrams to form a tree-like flow chart based on the connection directions and connection relationships.
[0095] In an embodiment of the present application, a breadth-first algorithm is used to obtain the number of layers of a single control flow, and then the output AUTOCAD block positions are standardized according to the plane range involved in each control flow chart and the number of levels included. The connection relationship and the corresponding connection method are then determined by using the corresponding generated standard frame to realize automatic drawing of the control logic flow chart in CAD.
[0096] For example, the maximum breadth optimization algorithm obtains the number of layers of a single control flow, which can be found in Figure 3 An exemplary schematic diagram of using a breadth-first algorithm to obtain the maximum number of layers for a specific process is shown.
[0097] In some embodiments, the method for generating a CAD control flow from a PLC program further includes S230 to S240.
[0098] S230: Determine the maximum number of layers of the program in XML format based on a breadth-first algorithm.
[0099] S240: Adjusting the coordinates of each functional block and the coordinates of the connecting lines between the functional blocks based on the maximum number of layers.
[0100] In the embodiments of this application, see Figure 4 , Figure 4 A schematic diagram of an exemplary flowchart adjustment provided in an embodiment of the present application, in which the coordinates of each functional block and the coordinates of the connecting lines are adjusted based on the maximum number of layers analyzed by a breadth-first algorithm.
[0101] In some embodiments, the method for generating a CAD control flow from a PLC program further includes S250 to S260.
[0102] S250: Determine a scaling ratio based on preset requirements for generating a target flow chart in the PLC program, the program in XML format, and the CAD.
[0103] S260: Adjust the flow chart based on the scaling ratio.
[0104] In the embodiment of the present application, the reduction ratio can be determined by comparing the width and height of the primitive with the drawable area of the frame, a smaller ratio is selected to ensure that the primitive is fully displayed in the frame, and the center point of the primitive is calculated so as to keep the center position of the primitive unchanged when it is reduced. Using the calculated scaling ratio, all primitives are scaled around the center point of the primitive to fit the drawable area of the frame.
[0105] As an exemplary implementation:
[0106] See also Figure 2 , Figure 2 An exemplary flow chart is provided for an embodiment of the present application, wherein:
[0107] Includes steps:
[0108] S1: Check the variables and comments integrity of the acquired PLC program;
[0109] S2: Convert the corresponding PLC program into a PLC program in XML format;
[0110] S3: XML format parsing program;
[0111] S4: Draw a flow chart using the COM interface of AUTOCAD;
[0112] S5: Adjust the flow chart format;
[0113] S6: Add annotation frame.
[0114] It should be noted that the example provided in the present invention provides a Schneider PLC program. For other types of PLC programs, since they also need to comply with the requirements of GB / T 15969.10-2023 "Programmable Controller Part 10: XML Open Interaction Format for PLC" (benchmarked with IEC 61131-10:2019), other types of PLCs can also be implemented by referring to the technical route provided in the present invention. Only some details need to be modified, and this application does not limit it.
[0115] First, you need to prepare the PLC program that needs to generate the flow chart, and then check the PLC program to see if it meets the requirements of automatic conversion.
[0116] Make sure that each variable used in the function block has a corresponding Chinese comment, otherwise the converted flowchart will lack Chinese information and will be difficult to read.
[0117] It should be noted that it is necessary to ensure that each address has only one variable. For the PLC program, there will be no error if each address has only one variable, but it will cause ambiguity.
[0118] After completing the variable check and modification of the PLC program, the program needs to be compiled to ensure that it can be executed normally.
[0119] The checked PLC is exported as a file in XML format. The XML format file extension of each PLC manufacturer may be different, and this application does not limit it.
[0120] See also Fig.12 , Fig.12 A schematic diagram of an exemplary XML format file functional blocks is provided.
[0121] To analyze PLC program files in XML format, the following information needs to be accurately restored:
[0122] Find the starting position of the variable table, such as Fig.10 The diagram shown is a schematic diagram of an exemplary XML format file variable table describing a starting position mark.
[0123] Parse the variable table one by one and store the logical name and Chinese comment of the variable.
[0124] Keywords property Function Remark <datablock> < / datablock> The starting position of the variable segment <variables Specific variable starting position name Variable Name typeName Variable Types topologicalAddress address comment Notes Used to explain the meaning of variables
[0125] Table 1
[0126] Find the starting position of the program segment, such as Fig.11 A schematic diagram of an exemplary XML format file program segment starting position mark is shown.
[0127] The following information is parsed: The following is the minimum information to implement this method.
[0128]
[0129]
[0130] Table 2
[0131] After completing the keyword parsing of the XML file structure information, it is necessary to design the corresponding structure to store the information.
[0132]
[0133]
[0134] In order to improve the efficiency of user input and modification of program running parameters, this embodiment uses Excel as the parameter input interface. The VBA development environment of EXCEL is used to call the automation interface of the AUTOCAD program to realize the flow chart drawing function.
[0135] See also Fig.13 , Fig.13 A schematic diagram of a program entry function in an exemplary Excel VAB environment of the present application is provided.
[0136] After designing the corresponding structure to store the PLC program information in XML format, write the corresponding sub-function to read the corresponding information.
[0137] Follow the steps below to parse:
[0138] Main program entry
[0139] Defines the MSXML2 object for reading and parsing XML format files.
[0140] Read the parameter table, obtain the XML format file, and obtain the path of the output CAD file.
[0141] Define the AutoCAD.AcadApplication object and define the AutoCAD.AcadDocument.
[0142] Create an AutoCAD.AcadApplication object entity.
[0143] Get all child nodes under the root node of the XML file.
[0144] Get all the variables nodes, count the number of nodes, and allocate space for the ClassVariables structure.
[0145] Read all variables node information and write the information into the ClassVariables structure.
[0146] Get all program nodes and calculate the number of program nodes.
[0147] Enter a for loop with a length equal to the number of program nodes and traverse all nodes.
[0148] Get the child nodes of the current program, calculate the number of function blocks, the number of connecting lines between function blocks, the amount of text information, and allocate space for the ClassFBLOCK structure, the ClassLinkFB structure, and the ClassTextBox structure.
[0149] Enter the next layer of for loop, the length of which is the number of child nodes of the current program structure information, and traverse all nodes
[0150] If the child node is FFBBlock, fill in the ClassFBLOCK structure information based on the FFBBlock attributes analyzed previously.
[0151] If the node is linkFB, fill in the ClassLinkFB structure information based on the FFBBlock attributes analyzed previously
[0152] Jump out of the loop of traversing the subnodes of the program structure
[0153] Loop through all linkFB structures
[0154] According to the linkSourceParentObjectName and linkDestinationParentObjectName information marked in the ClassLinkFB structure, find the corresponding ClassFBLOCK structure and write the strOutPutFBName information.
[0155] Jump out of the loop of traversing the subnodes of the linkFB structure
[0156] Define the top-level node quantity variable to record the number of all top-level nodes in the current program segment
[0157] Loop through all ClassFBLOCK structures
[0158] For a structure with empty strOutPutFBName information, define it as a top-level node of a minimum control flow, nTreeLevel is 0, and nTreeWidth is 1
[0159] The number of top-level nodes increases by 1
[0160] Jump out of the loop of traversing the subnodes of the ClassFBLOCK structure
[0161] Loop through all top-level node ClassFBLOCK structures
[0162] Call the sub-function, and input the ClassFBLOCK structure of the current top-level node and all ClassFBLOCK structures of this program segment
[0163] Search for ClassFBLOCK pointing to the top node and record the current structure
[0164] Fill the nTreeLevel and nTreeWidth variables of the ClassFBLOCK structure using a breadth-first algorithm.
[0165] Nested call of the current function, the input is the ClassFBLOCK structure currently pointing to the top node and all ClassFBLOCK structures in this program segment
[0166] Jump out of the loop of traversing the subnodes of the ClassFBLOCK structure
[0167] At this point, the information of the structure has been filled in. Next, we need to draw the complete tree structure contained in the top-level nodes one by one in order to realize the drawing of a single control flow graph.
[0168] Loop through all top-level node ClassFBLOCK structures
[0169] Create a new AutoCAD drawing
[0170] Get the ClassFBLOCK structure of the current top node containing the complete tree
[0171] Get the maximum number of layers and maximum width of the current top-level structure
[0172] Fix each layer of ClassFBLOCK, and the width corresponds to 200mm in the AUTOCAD drawing space (the correspondence between the AUTOCAD drawing space coordinates and the PLC program coordinates is 10:1).
[0173] Loop through the ClassFBLOCK structure of the current top node containing the complete tree
[0174] The horizontal coordinate of the starting point is determined by the number of layers of the ClassFBLOCK structure. The relationship is the maximum number of layers minus the number of layers of the ClassFBLOCK structure multiplied by 200 to obtain the coordinates of the corresponding AUTOCAD drawing space.
[0175] Modify the dbFBSTPoint(1) and dbRectSTPoint(1) variables of the ClassFBLOCK structure to correspond to the coordinates of the AUTOCAD drawing space.
[0176] Draw the current ClassFBLOCK structure
[0177] Break out of the loop
[0178] Loop through all linkFB structures
[0179] Get the linkFB structure related to the ClassFBLOCK structure of the current top-level node containing the complete tree, modify the number of layers of the start and end ClassFBLOCK structures pointed to by the linkFB structure, modify the start and end horizontal coordinates, and if there is a transfer node, the transfer node horizontal coordinate is defined as the midpoint of the start and end coordinates
[0180] Draw a polyline in the AUTOCAD drawing according to the coordinates provided by the linkFB structure.
[0181] Break out of the loop
[0182] Define 4 double-precision floating-point numbers to record the maximum and minimum horizontal and vertical coordinates of the drawing elements on the current drawing and initialize the variable values.
[0183] Loop through all elements of an AUTOCAD drawing
[0184] Use the GetRectangleBounds function to get the maximum rectangle.
[0185] Compare the coordinates of the rectangle with the four double-precision floating-point numbers defined previously. If the range is outside the current maximum and minimum horizontal and vertical coordinate ranges, record the updated maximum and minimum horizontal and vertical coordinate ranges and exit the loop.
[0186] Get the maximum and minimum horizontal and vertical coordinate ranges of the current drawing, calculate the zoom ratio, and do not enlarge the drawing currently. The drawing will only be reduced when it cannot fit in the standard A4 drawing frame.
[0187] Determine the reduction ratio by comparing the width and height of the graphic element to the drawable area of the frame. Choose a smaller ratio to ensure that the graphic element is fully displayed within the frame.
[0188] Calculate the center of the primitive: Calculate the center point of the primitive so that the center position of the primitive remains unchanged when it is reduced.
[0189] Reduce the primitive: Use the calculated scaling ratio to scale all primitives around their center points to fit into the drawable area of the frame. The scaling ratio is 1.0 or a positive real number less than 1.0.
[0190] Add Frame: Add a standard frame (such as A4 or A3) around the scaled element, making sure the center of the frame is aligned with the center of the element.
[0191] Move all the graphics elements as a whole so that the coordinates of the lower left and lower right corners of the frame are (0,0)
[0192] Save the AUTOCAD drawing to the CAD file directory specified in the parameter table. The file name uses the identProgram.name of the current program structure and the annotation information of the output pin of the top-level node.
[0193] Close the created AUTOCAD program entity
[0194] Jump out of the traversal of the top-level node ClassFBLOCK structure loop to complete the current program conversion to AUTOCAD drawing process
[0195] Complete the process of converting all programs into AUTOCAD drawings
[0196] Send a dialog message to the user to complete the task
[0197] See also Fig.14 , Fig.14 The present invention provides a schematic diagram of a PLC program generating a CAD control process device, wherein the PLC program generating a CAD control process device 300 includes: an acquisition module 310, a storage module 320, a parsing module 330, a drawing module 340, a determination module 350 and an adjustment module 360, wherein:
[0198] The acquisition module 310 is used to acquire a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word;
[0199] The storage module 320 is used to store the PLC program as a program in XML format;
[0200] The parsing module 330 is used to parse the program in XML format and determine the content of the input pins and output pins in the function block and the coordinate information corresponding to the function block;
[0201] The drawing module 340 is used to draw a flow chart based on the coordinate information using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain target input pins and target output pins and target translation interpretation words that meet the CAD coordinate system.
[0202] The determination module 350 is used to determine the level of the program in XML format, and uses a breadth-first algorithm to process the program in XML format to determine the number of levels and target coordinates of each control flow in the function block.
[0203] The adjustment module 360 adjusts the flowchart based on the level, number of levels and target coordinates to obtain a target flowchart.
[0204] It should be noted that the device embodiments in the present application correspond to each other with the aforementioned method embodiments. The specific principles in the device embodiments can be found in the contents of the aforementioned method embodiments and will not be repeated here.
[0205] In several embodiments provided in this embodiment, the coupling between modules may be electrical, mechanical or other forms of coupling.
[0206] In addition, each functional module in each embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of software functional modules.
[0207] See also Fig.15 , Fig.15 A structural block diagram of an electronic device 200 that can execute the above-mentioned method of generating a CAD control flow from a PLC program is provided in an embodiment of the present application.
[0208] The electronic device 200 further includes a processor 202 and a memory 204. The memory 204 stores a program that can execute the contents of the aforementioned embodiments, and the processor 202 can execute the program stored in the memory 204.
[0209] The processor 202 may include one or more cores and message matrix units for processing data. The processor 202 uses various interfaces and lines to connect the various parts of the entire ice maker 200, and executes various functions and processes data of the ice maker 200 by running or executing instructions, programs, code sets or instruction sets stored in the memory 204, and calling data stored in the memory 204. Optionally, the processor 202 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 202 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU), and a modulation decoder. Among them, the CPU mainly processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem is used to process wireless communications. It can be understood that the above-mentioned modulation decoder may not be integrated into the processor, but may be implemented separately through a communication chip.
[0210] The memory 204 may include a random access memory (RAM) or a read-only memory (ROM). The memory 204 may be used to store instructions, programs, codes, code sets or instruction sets. The memory 204 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (e.g., instructions for a user to obtain a random number), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (e.g., random numbers) created by the terminal during use, etc.
[0211] Please refer to Fig.16 , Fig.16 The computer-readable storage medium 400 stores program code 410, which can be called by a processor to execute the method described in the above method embodiment.
[0212] The computer-readable storage medium 400 may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read-only memory), an EPROM, a hard disk, or a ROM. Optionally, the computer-readable storage medium includes a non-transitory computer-readable storage medium. The computer-readable storage medium 400 has storage space for program codes 410 that perform any method steps in the above method. These program codes 410 can be read from or written to one or more computer program products. The program codes 410 can be compressed, for example, in an appropriate form.
[0213] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method for generating a CAD control flow from a PLC program described in the above various optional implementations.
[0214] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for generating a CAD control flow from a PLC program, characterized in that: include: Acquire a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word; Storing the PLC program as a program in XML format; Parsing the program in the XML format to determine the contents of the input pins and the output pins in the function block and the coordinate information corresponding to the function block; Based on the coordinate information, a flow chart is drawn using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain target input pins and target output pins and target translation interpretation words that meet the CAD coordinate system; Determine the hierarchy of the program in the XML format, and process the program in the XML format using a breadth-first algorithm to determine the number of levels and target coordinates of each control flow in the function block; The flowchart is adjusted based on the level, the number of layers and the target coordinates to obtain a target flowchart.
2. The method for generating a CAD control flow from a PLC program according to claim 1, characterized in that: The method for generating a CAD control flow from a PLC program also includes: Add a standard diagram frame and traceability information to the target flow chart, wherein the traceability information includes: generation time and link object.
3. The method for generating a CAD control flow from a PLC program according to claim 2, characterized in that: The program for parsing the XML format includes: Determine a first starting position of each variable table in the program in the XML format and a second starting position of each program segment in the program in the XML format; The variable table is parsed one by one based on the first starting position to obtain the logical name of the variable and the Chinese comment of the variable. The program segment is parsed one by one based on the second starting position to obtain the file structure parsing information in XML format.
4. The method for generating a CAD control flow from a PLC program according to claim 3, characterized in that: The method for generating a CAD control flow from a PLC program also includes: After parsing the program in the XML format, a structure is created; The structure is used to store the logical name of the variable, the Chinese annotation of the variable and the file structure parsing information.
5. The method for generating CAD control flow from PLC program according to claim 1, characterized in that: The step of adjusting the flowchart based on the level, the number of layers and the target coordinates to obtain a target flowchart includes: Drawing a block diagram of the corresponding functional block in the CAD drawing based on the level, number of layers and target coordinates; Determine the connection directions and connection relationships between adjacent block diagrams in the block diagram of the functional block; Based on the connection directions and connection relationships, the various block diagrams are connected to form a tree-like flow chart.
6. The method for generating CAD control flow from PLC program according to claim 1, characterized in that: The method for generating a CAD control flow from a PLC program also includes: Determine the maximum number of layers of the program in the XML format based on the breadth-first algorithm; The coordinates of each functional block and the coordinates of the connection lines between the functional blocks are adjusted based on the maximum number of layers.
7. The method for generating CAD control flow from PLC program according to claim 1, characterized in that: The method for generating a CAD control flow from a PLC program also includes: Determining a scaling ratio based on the preset requirements for generating a target flow chart in the PLC program, the program in the XML format, and the CAD; The flow chart is adjusted based on the zoom ratio.
8. A device for generating CAD control flow from a PLC program, characterized in that: The device comprises: An acquisition module, used for acquiring a PLC program, wherein each output variable of a function block in the PLC program has a corresponding translation interpretation word; A storage module, used for storing the PLC program as a program in XML format; A parsing module, used for parsing the program in XML format, determining the content of the input pins and the output pins in the function block and the coordinate information corresponding to the function block; A drawing module is used to draw a flow chart based on the coordinate information using a preset interface in the CAD, wherein the coordinate points described in the PLC program are mapped to obtain target input pins and target output pins and target translation interpretation words that meet the CAD coordinate system. The determination module is used to determine the level of the program in the XML format, and uses a breadth-first algorithm to process the program in the XML format to determine the number of levels and target coordinates of each control flow in the function block. An adjustment module adjusts the flowchart based on the level, the number of layers and the target coordinates to obtain a target flowchart.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor, wherein the memory stores a program code that can be executed on the processor, and when the program code is executed by the processor, the data evaluation method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program codes, which can be called by one or more processors to execute the data evaluation method according to any one of claims 1 to 7.