Ladder diagram drawing method, device, storage medium and computer program product
By introducing ladder drawing method in PLC configuration software, using global singleton objects to manage ladder drawing data, compiling and decompiling to generate standardized logical tables, the problems of inefficient ladder drawing and frequent errors in the existing technology are solved. , realizes efficient and reliable ladder drawing.
Patent Information
- Application Number
- CN202411449103.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-10-17
AI Technical Summary
The ladder drawing function module of the existing PLC configuration software is complicated to operate, resulting in low ladder drawing efficiency and lack of standardized constraints, resulting in frequent errors and difficulty in detecting.
A ladder diagram drawing method is proposed. By obtaining the ladder diagram drawing elements input by the user, reading the initial global singleton object, compiling and decompiling, generating a normalized ladder diagram logic table, traversing the table to draw the initial ladder diagram, and providing the ladder diagram Redraw mechanism.
It effectively reduces the ladder drawing error rate, improves the drawing reliability, optimizes the drawing process, and realizes efficient drawing of ladder drawing.
Smart Images

Figure CN118963773B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of industrial automation technology, and in particular to a ladder diagram drawing method, device, storage medium and computer program product. Background Art
[0002] Ladder diagrams have a wide range of application scenarios in the field of industrial automation. They simplify the PLC programming process in a graphical way and improve the reliability and efficiency of industrial automation systems. With the development of industrial automation, the scale of projects is expanding, and the efficiency requirements for ladder diagram drawing and debugging are getting higher and higher: it is required to quickly build complex control logic, complete the drawing of ladder diagrams, and conduct efficient testing and debugging. However, the current PLC configuration software ladder diagram drawing function module requires manual adjustment of the position and connection relationship of the graphics elements, which is cumbersome to operate, resulting in low efficiency of ladder diagram drawing. In addition, there is a lack of standardized constraints in the current ladder diagram drawing process, which leads to frequent errors and difficulty in error detection.
[0003] Therefore, how to effectively reduce the error rate of ladder diagram drawing and improve the drawing reliability under the premise of efficiently drawing the ladder diagram has become an urgent problem to be solved in this application.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present application is to provide a ladder diagram drawing method, device, storage medium and computer program product, aiming to solve the technical problem of how to effectively reduce the ladder diagram drawing error rate and improve the drawing reliability under the premise of efficient ladder diagram drawing.
[0006] To achieve the above purpose, the present application proposes a ladder diagram drawing method, which is applied to a ladder diagram drawing function module, and the method includes:
[0007] Obtaining a ladder diagram drawing element input by a user, and reading the ladder diagram drawing element into an initialized global singleton object to obtain a ladder diagram data object;
[0008] Compiling and decompiling the ladder diagram data object to obtain compilation and decompile results;
[0009] Generate a normalized ladder diagram logic table according to the compilation and decompilation results, and traverse the normalized ladder diagram logic table to draw an initial ladder diagram;
[0010] The initial ladder diagram is redrawn based on the ladder diagram modification data acquired in advance to obtain a redrawn ladder diagram.
[0011] In one embodiment, the step of obtaining the ladder diagram drawing element input by the user and reading the ladder diagram drawing element into the initialized global singleton object to obtain the ladder diagram data object comprises:
[0012] Get the ladder diagram drawing elements input by the user;
[0013] Create a global singleton object according to preset ladder diagram syntax semantics and initialize member variables of the global singleton object to default values to obtain an initialized global singleton object;
[0014] The ladder diagram drawing element is read into the initialized global singleton object to obtain a ladder diagram data object.
[0015] In one embodiment, the step of compiling and decompiling the ladder diagram data object to obtain the compilation and decompilation results includes:
[0016] Performing format conversion on the ladder diagram data object, and detecting the legality of the content of the ladder diagram data object after format conversion;
[0017] When the content of the ladder diagram data object after format conversion is legal, compiling the ladder diagram data object into text instructions;
[0018] Decompile the text instructions to obtain compilation and decompilation results.
[0019] In one embodiment, the step of generating a normalized ladder diagram logic table according to the compilation and decompilation results, and traversing the normalized ladder diagram logic table to draw an initial ladder diagram comprises:
[0020] Convert the compilation and decompilation results into Ladder objects;
[0021] Accessing compilation and decompilation member variables, and determining whether the Ladder object has been compiled and decompiled according to the compilation and decompilation member variables;
[0022] When the Ladder object has been compiled and decompiled, generating a normalized ladder logic table according to the Ladder object;
[0023] Traversing the normalized ladder diagram logic table to determine the ladder diagram annotation situation and calculate the primitive drawing range;
[0024] An initial ladder diagram is drawn based on the ladder diagram annotation situation and the primitive drawing range.
[0025] In one embodiment, the step of traversing the normalized ladder diagram logic table to determine the ladder diagram annotation situation and calculate the primitive drawing range includes:
[0026] Traversing the normalized ladder logic table to calculate the length value of each row of elements in the normalized ladder logic table;
[0027] Performing line break processing on the normalized ladder diagram logic table according to the maximum number of graphic elements displayed in each line of the ladder diagram data object and the length value of the element in each line;
[0028] Based on the ladder diagram data object and the normalized ladder diagram logic table after line break processing, the ladder diagram annotation situation is determined and the primitive drawing range is calculated.
[0029] In one embodiment, the step of redrawing the initial ladder diagram based on the pre-acquired ladder diagram modification data to obtain the redrawn ladder diagram includes:
[0030] Traverse the normalized ladder logic table, initialize the member variables of the normalized ladder logic table to default values, and obtain the initialized ladder Figure 2 Dimension table;
[0031] Selecting a corresponding graphic primitive object in the normalized ladder diagram logic table according to the pre-acquired ladder diagram change data and modifying the graphic primitive object;
[0032] Based on the modified primitive object and the initialization trapezoid Figure 2 The dimension table redraws the initial ladder diagram to obtain a redrawn ladder diagram.
[0033] In one embodiment, after the step of redrawing the initial ladder diagram based on the pre-acquired ladder diagram modification data to obtain the redrawn ladder diagram, the step further includes:
[0034] The normalized ladder diagram logic table and the ladder diagram data object are saved, and an error information log is output.
[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a ladder diagram drawing device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the ladder diagram drawing method described above.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the ladder diagram drawing method described above are implemented.
[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the ladder diagram drawing method described above are implemented.
[0038] One or more technical solutions proposed in this application have at least the following technical effects:
[0039] This embodiment provides a ladder diagram drawing method, which is applied to the ladder diagram drawing function module, reads the ladder diagram drawing elements input by the user into the initialized global singleton object, uses the global singleton object to manage the ladder diagram data, and ensures the consistency and security of the ladder diagram drawing elements; compiles and decompiles the ladder diagram data object to generate a standardized ladder diagram logic table, effectively avoiding drawing errors caused by user input errors or logic errors; traverses the standardized ladder diagram logic table, draws the initial ladder diagram, and allows the user to verify the correctness of the ladder diagram in a visual manner; provides a ladder diagram redrawing mechanism, converts the initial ladder diagram into the initial ladder diagram logic table, and redraws the ladder diagram based on the pre-acquired ladder diagram change data to obtain a redrawn ladder diagram, ensuring the reliability of the ladder diagram display content. By reading the ladder diagram drawing elements into the initialized global singleton object, compiling and decompiling operations, the drawing process is optimized, and while achieving efficient drawing of the ladder diagram, the drawing error rate is effectively reduced and the drawing reliability is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0042] Figure 1 A schematic diagram of a process flow provided for the first embodiment of the ladder diagram drawing method of the present application;
[0043] Figure 2 A schematic diagram of a flow chart provided for the second embodiment of the ladder diagram drawing method of the present application;
[0044] Figure 3 A schematic diagram of a process flow provided for the third embodiment of the ladder diagram drawing method of the present application;
[0045] Figure 4 A schematic diagram of a flow chart provided for the fourth embodiment of the ladder diagram drawing method of the present application;
[0046] Figure 5 This is a schematic diagram of the module structure of the ladder diagram drawing device according to an embodiment of the present application;
[0047] Figure 6It is a schematic diagram of the device structure of the hardware operating environment involved in the ladder diagram drawing method in the embodiment of the present application.
[0048] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0049] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0050] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0051] The embodiments of the present application take into account that ladder diagrams have a wide range of application scenarios in the field of industrial automation, and simplify the PLC programming process in a graphical way, thereby improving the reliability and efficiency of industrial automation systems. With the development of industrial automation, the scale of projects is expanding, and the efficiency requirements for ladder diagram drawing and debugging are getting higher and higher: it is required to quickly build complex control logic, complete the drawing of ladder diagrams, and perform efficient testing and debugging. However, the current PLC configuration software ladder diagram drawing function module requires manual adjustment of the position and connection relationship of the graphics elements, which is cumbersome to operate, resulting in low efficiency in ladder diagram drawing, and the lack of standardized constraints in the current ladder diagram drawing process leads to frequent errors and difficulty in error detection.
[0052] Therefore, the present application provides a solution, which reads the ladder diagram drawing elements input by the user into the initialized global singleton object, uses the global singleton object to manage the ladder diagram data, and ensures the consistency and security of the ladder diagram drawing elements; compiles and decompiles the ladder diagram data object to generate a standardized ladder diagram logic table, effectively avoiding drawing errors caused by user input errors or logic errors; traverses the standardized ladder diagram logic table, draws the initial ladder diagram, and allows users to verify the correctness of the ladder diagram in a visual way; provides a ladder diagram redrawing mechanism, converts the initial ladder diagram into the initial ladder diagram logic table, and redraws the ladder diagram based on the pre-acquired ladder diagram change data to obtain a redrawn ladder diagram, ensuring the reliability of the ladder diagram display content. By reading the ladder diagram drawing elements into the initialized global singleton object, compiling and decompiling operations, the drawing process is optimized, and efficient ladder diagram drawing is achieved, while effectively reducing the drawing error rate and improving drawing reliability.
[0053] Based on this, the present application embodiment provides a method for drawing a ladder diagram, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the ladder diagram drawing method of the present application.
[0054] In this embodiment, the ladder diagram drawing method includes steps S10 to S40:
[0055] Step S10, obtaining a ladder diagram drawing element input by a user, and reading the ladder diagram drawing element into an initialized global singleton object to obtain a ladder diagram data object;
[0056] The user inputs the ladder diagram elements that he wants to draw by clicking and dragging the mouse, or by using keyboard shortcuts or menu options provided by the ladder diagram drawing function module of the PLC configuration software. The ladder diagram drawing elements include various elements used to draw ladder diagrams, such as instruction primitives, instruction parameters, comments, program pointers, and execution steps. Through different ladder diagram drawing elements input by different users, the ladder diagram drawing function module of the PLC configuration software can draw different ladder diagrams and perform different operations on the ladder diagrams, including redrawing, deleting, and modifying.
[0057] Initialize the global singleton object to store all the drawing elements used to draw a ladder diagram. Read the ladder diagram drawing elements input by the user into the initialized global singleton object to obtain the ladder diagram data object: Class Ladder Data. The data members of the Class LadderData of the ladder diagram drawing elements are as follows:
[0058] A two-dimensional table LIST_ROW Ladder that records the connection relationship between each element of the ladder diagram, where the rows and columns of the two-dimensional table record the connection relationship between the elements in a non-wrapped manner. Each element of the two-dimensional table is an object of the LadCell type, which is used to record the content of the instruction corresponding to a single element, where the LadCell.*pItem member is nullptr;
[0059] The maximum number of items that can be displayed in each row Max Item Amount Per Row;
[0060] Program comments and the left side mark of the ladder diagram, including: line number-declaration content, line number-annotation, soft element-annotation and other elements that affect the drawing of the ladder diagram;
[0061] The pixel size occupied by a single primitive and the entire trapezoidal diagram, where the pixel size occupied by a single primitive and the entire trapezoidal diagram includes the pixel value of the length of a single primitive, the pixel value of the height of a single primitive, and other elements that affect the drawing of the trapezoidal diagram.
[0062] It should be noted that the ladder diagram drawing function module of the PLC configuration software implements the construction of the ladder diagram data object through C++ code, for example:
[0063] int MaxItemAmountPerRow: the maximum number of items that can be displayed in each row;
[0064] Bool isDeclarationShowed: whether to display the declaration;
[0065] Bool isCommentsShowed: whether to display comments;
[0066] Bool isRegisterCommentsShowed: whether to display soft component comments;
[0067] Bool isLadderCompiled: Whether Ladder has been compiled and decompiled;
[0068] QMap<int, QString> ContentOfDeclaration: Line number - declaration content;
[0069] QMap<int, QString> ContentOfComments: number of lines - comments;
[0070] QMap<QString, QString> ContentOfRegisterComments: soft component-comments;
[0071] QMap<int, QString> ProgramPointers: line number - P, I program pointer;
[0072] QMap<int, int> ProgramStep: number of lines - number of execution steps;
[0073] QMap<int,int> VerticalCoordinatesOfEachRow: The vertical coordinate of the top of each row of the ladder diagram;
[0074] Int LineBreakAmount: the number of line breaks;
[0075] Double DisplayScale: The display scale of the ladder diagram is 50%-200%;
[0076] Const int BaseWidthOfEachUnit: the basic pixel value of the length of a single block of graphics elements, that is, the length of the graphics element when the display ratio is 100%;
[0077] Int WidthOfEachUnit: length of a single block of pixels;
[0078] Const int BaseHeightOfEachUnit: the basic pixel value of the height of a single unit, that is, the height of the unit when the display ratio is 100%;
[0079] Int HeightOfEachUnit: The height of a single block of graphics elements in pixels.
[0080] It can be understood that the above C++ code example is only to better illustrate the process of the ladder diagram drawing function module of the PLC configuration software obtaining the ladder diagram data object through the ladder diagram drawing elements input by the user, and does not mean that the ladder diagram drawing function module of the PLC configuration software uses the above code as the only implementation method to obtain the ladder diagram data object.
[0081] Step S20, compiling and decompiling the ladder diagram data object to obtain compilation and decompile results;
[0082] The ladder diagram data object Class Ladder Data includes a two-dimensional table LIST_ROW Ladder for recording the connection relationship between various graphics elements of the ladder diagram. It should be noted that LIST_ROW Ladder is a two-dimensional table for recording the connection relationship between the graphics elements of the ladder diagram in a non-line-breaking manner.
[0083] The ladder diagram drawing function module of the PLC configuration software passes the LIST_ROW Ladder to the compilation module and the decompilation module. The compilation module compiles the LIST_ROW Ladder into text instruction content and passes it to the decompilation module. The decompilation module decompiles the text instruction content into a two-dimensional table LIST_ROW object and passes it to the ladder diagram drawing function module of the PLC configuration software.
[0084] Step S30, generating a normalized ladder diagram logic table according to the compilation and decompilation results, and traversing the normalized ladder diagram logic table to draw an initial ladder diagram;
[0085] The ladder diagram drawing function module of the PLC configuration software converts the two-dimensional table LIST_ROW object into a normalized ladder diagram logic table LadderGraphics after compilation and decompilation, that is, one of the data members of the ladder diagram drawing function module of the PLC configuration software: the two-dimensional table LIST_ROW LadderGraphics that records the ladder diagram drawn on the canvas.
[0086] It can be understood that the two-dimensional table LIST_ROW LadderGraphics recording the ladder diagram drawn on the canvas is an initialized two-dimensional table and does not have the drawing elements required for drawing the ladder diagram, while the normalized ladder diagram logic table LadderGraphics after compilation and decompilation has the drawing elements required for drawing the ladder diagram.
[0087] The ladder diagram drawing function module of the PLC configuration software traverses the standardized ladder diagram logic table LadderGraphics, draws the initial ladder diagram according to the ladder diagram drawing elements in the standardized ladder diagram logic table LadderGraphics, and converts the logic data into visual graphic elements, such as contacts, coils, connecting lines, etc., so as to display and edit them on the canvas.
[0088] Step S40, redrawing the initial ladder diagram based on the ladder diagram modification data acquired in advance to obtain a redrawn ladder diagram.
[0089] Since the user usually modifies the initial ladder diagram after it is drawn, in order to respond to various operations and settings of the user, it is necessary to convert the normalized ladder diagram logic table into the initial ladder diagram logic table, clear the previous element drawing information, modify the drawing data in the initial ladder diagram logic table in combination with the ladder diagram change data modified by the user, re-traverse the modified initial ladder diagram logic table, redraw the initial ladder diagram, and obtain a redrawn ladder diagram.
[0090] This embodiment provides a ladder diagram drawing method, which is applied to the ladder diagram drawing function module, reads the ladder diagram drawing elements input by the user into the initialized global singleton object, uses the global singleton object to manage the ladder diagram data, and ensures the consistency and security of the ladder diagram drawing elements; compiles and decompiles the ladder diagram data object to generate a standardized ladder diagram logic table, effectively avoiding drawing errors caused by user input errors or logic errors; traverses the standardized ladder diagram logic table, draws the initial ladder diagram, and allows the user to verify the correctness of the ladder diagram in a visual manner; provides a ladder diagram redrawing mechanism, converts the initial ladder diagram into the initial ladder diagram logic table, and redraws the ladder diagram based on the pre-acquired ladder diagram change data to obtain a redrawn ladder diagram, ensuring the reliability of the ladder diagram display content. By reading the ladder diagram drawing elements into the initialized global singleton object, compiling and decompiling operations, the drawing process is optimized, and while achieving efficient drawing of the ladder diagram, the drawing error rate is effectively reduced and the drawing reliability is improved.
[0091] In a feasible implementation, step S10 may include steps S11 to S13:
[0092] Step S11, obtaining the ladder diagram drawing element input by the user;
[0093] The PLC configuration software ladder diagram drawing function module provides a variety of interfaces for program calls. The PLC configuration software ladder diagram drawing function module rewrites the mouse movement, click, double-click and press events to handle the user's interaction with the canvas; rewrites the keyboard press event to handle keyboard input. The key trigger event rewritten by the PLC configuration software ladder diagram drawing function module can meet the user's various needs for inputting ladder diagram drawing elements and obtain the ladder diagram drawing elements input by the user.
[0094] Step S12, creating a global singleton object according to preset ladder diagram syntax semantics and initializing member variables of the global singleton object to default values to obtain an initialized global singleton object;
[0095] The global singleton object created according to the semantics of the ladder diagram syntax stores all the data used to draw a ladder diagram, including the instruction content of each element of the ladder diagram, the connection relationship between the elements, the content of the annotation, and the program pointer and program steps recorded on the left side of the ladder diagram. The software can only open and edit one ladder diagram at a time, and the global singleton LadderData object of the program is used to record the data of the ladder diagram currently opened and edited.
[0096] Initialize all member variables in the global singleton object to default values to obtain the initialized global singleton object. For example, the global singleton object contains a two-dimensional table LIST_ROW Ladder that records the connection relationship between each graphics element in the ladder diagram. The rows and columns of the two-dimensional table record the connection relationship between the graphics elements in a non-line-breaking manner; each element of the two-dimensional table is an object of the LadCell type, which is used to record the content of the instruction corresponding to a single graphics element. The LadCell.*pItem member is initialized to nullptr to implement the initialization of the global singleton.
[0097] Step S13, reading the ladder diagram drawing element into the initialized global singleton object to obtain a ladder diagram data object.
[0098] The ladder diagram drawing elements input by the user are read into the initialized global singleton object, the member data in the initialized global singleton object is read into the corresponding ladder diagram drawing elements, and the member variables are changed from the default values to the data values used for ladder diagram drawing, thereby obtaining the ladder diagram data object LadderData for initial ladder diagram drawing that meets the user's ladder diagram drawing requirements.
[0099] In a feasible implementation, step S20 may include steps S21 to S23:
[0100] Step S21, performing format conversion on the ladder diagram data object, and detecting the legality of the content of the ladder diagram data object after format conversion;
[0101] The two-dimensional table LIST_ROWLadder in the ladder diagram data object that records the connection relationship between each ladder diagram primitive is converted into a format that can be recognized by the compilation function module, which is the same as the LIST_ROW format processed by the previous compilation module. The main operation of the format conversion is to replace the single block contact comparison instruction primitive with a contact comparison instruction primitive and two straight line primitives.
[0102] Check the legality of the two-dimensional table LIST_ROWLadder in the ladder diagram data object, which records the connection relationship between each element of the ladder diagram, such as open circuit, short circuit, cross, whether there is an end line, and whether there is a contact before the end line. If the test is illegal, a pop-up window will be displayed to terminate the operation.
[0103] Step S22, when the content of the ladder diagram data object is legal, compile the ladder diagram data object into text instructions;
[0104] When the content of the ladder diagram data object is legal, the LIST_ROW Ladder in the ladder diagram data object is compiled into a text instruction.
[0105] Step S23, decompile the text instruction to obtain compilation and decompilation results.
[0106] Decompile the text instructions into a LIST_ROW, and this LIST_ROW two-dimensional table is the compilation and decompilation result.
[0107] Based on the first embodiment of the present application, the second embodiment of the present application is proposed. In the second embodiment of the present application, the same or similar contents as those of the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following.
[0108] On this basis, please refer to Figure 2 , Figure 2 A schematic flow chart of a second embodiment of the ladder diagram drawing method provided in the present application.
[0109] In this embodiment, a normalized ladder diagram logic table is generated according to the compilation and decompilation results, and step S30 of traversing the normalized ladder diagram logic table to draw an initial ladder diagram may include steps S31 to S35:
[0110] Step S31, converting the compilation and decompilation results into a Ladder object;
[0111] Compile and decompile the two-dimensional table LIST_ROW Ladder that records the connection relationship between each figure element of the ladder diagram in the ladder diagram data object LadderData, compile the connection relationship between each figure element of the ladder diagram recorded in the two-dimensional table LIST_ROW Ladder into a text instruction, and then decompile the text instruction content into a LIST_ROW object. The compilation and decompilation result is the LIST_ROW object decompiled according to the text instruction content. The process of compiling and decompiling to obtain the LIST_ROW object will be described in detail in the subsequent embodiments.
[0112] The ladder diagram drawing function module of the PLC configuration software receives the compilation and decompilation results sent by the compilation and decompilation module: decompiles the LIST_ROW object according to the text instruction content, deletes the redundant blanks at the end of the branch row in the LIST_ROW object, deletes the redundant horizontal connecting lines used to place the end element at the end, and reassigns the value of the processed LIST_ROW object to the two-dimensional table LIST_ROW Ladder to obtain the Ladder object.
[0113] Step S32, accessing the compilation and decompilation member variables, and judging whether the Ladder object has been compiled and decompiled according to the compilation and decompilation member variables;
[0114] The ladder diagram drawing function module of the PLC configuration software calls the TransLadderIntoLadderGraphics() function to draw the initial ladder diagram. The TransLadderIntoLadderGraphics() function first accesses the Boolean member variable in the LadderData object: Bool isLadderCompiled: Ladder, to determine whether the two-dimensional table LIST_ROW Ladder, i.e., the Ladder object, has been compiled and decompiled. If the value of isLadderCompiled is true, it means that the ladder diagram has been compiled and decompiled; if the value of isLadderCompiled is false, it means that the ladder diagram has not been compiled or the compilation has failed.
[0115] Step S33, when the Ladder object has been compiled and decompiled, generating a normalized ladder logic table according to the Ladder object;
[0116] The initial ladder diagram is drawn only when the Ladder object has been compiled and decompiled. If the Ladder object has not been compiled and decompiled, the ladder diagram drawing function module of the PLC configuration software pops up a prompt and terminates the operation.
[0117] It should be noted that the data members of the ladder diagram drawing function module of the PLC configuration software for ladder diagram drawing include a two-dimensional table LIST_ROW LadderGraphics for recording the ladder diagram drawn on the canvas and LIST_ROW LadderCopyItem for temporarily storing the copied graphic element content in the two-dimensional table.
[0118] It can be understood that the two-dimensional table LIST_ROW LadderGraphics that records the ladder diagram drawn on the canvas is consistent with the two-dimensional table LIST_ROW Ladder, that is, the data structure of the Ladder object. The rows and columns of the two-dimensional table LIST_ROW LadderGraphics that records the ladder diagram drawn on the canvas record the connection relationship (including line breaks) between the graphics elements of the ladder diagram drawn on the CPlcScene canvas in a line-breaking manner; the *pItem member of each LadCell type element of the two-dimensional table is the graphics element of the instruction corresponding to the LadCell, and each LadCell.*pItem has a strict one-to-one correspondence with the LadCell; *pItem is a pointer of the ElementBaseItem type, which records the drawing range coordinates and appearance of the graphics element on the canvas. The various drawing-related functions of the CPlcScene class, such as inserting / deleting rows / columns, copying / pasting, etc., will access and change the content of this two-dimensional table, and change the ladder diagram drawn on the canvas according to its content.
[0119] Therefore, the value of the Ladder object is assigned to the LadderGraphics whose member variable is the initial value to obtain the normalized ladder diagram logic table LadderGraphics. The ladder diagram can be drawn through the normalized ladder diagram logic table LadderGraphics.
[0120] Step S34, traversing the standardized ladder diagram logic table to determine the ladder diagram annotation situation, calculate the primitive drawing range and create a primitive object;
[0121] Specifically, in a feasible implementation manner, step S34 may include steps S341 to S343:
[0122] Step S341, traversing the normalized ladder logic table to calculate the length value of each row of elements in the normalized ladder logic table;
[0123] First, traverse each row of the normalized ladder logic table LadderGraphics and all LadCell elements in each row. Sum the length values of all elements in each row and assign them to the variable int RowLength to obtain the length value of each row element in the normalized ladder logic table.
[0124] Step S342, performing line wrapping processing on the normalized ladder diagram logic table according to the maximum number of graphic elements displayed in each line of the ladder diagram data object and the length value of the element in each line;
[0125] According to the data member of the ladder data object LadderData: the maximum number of graphics elements that can be displayed in each row intMaxItemAmountPerRow, it is determined whether a line break is required. If RowLength is greater than MaxItemAmountPerRow, this line cannot hold too many components and needs to be wrapped; if RowLength is less than or equal to MaxItemAmountPerRow, this line can hold components and continue to traverse the next line, thus completing the traversal of the entire standardized ladder logic table LadderGraphics.
[0126] It should be noted that when RowLength is greater than MaxItemAmountPerRow, the detailed operation for line wrapping is as follows: divide the content of this row into multiple rows according to the value of MaxItemAmountPerRow. For example, if MaxItemAmountPerRow == 9, and the sizes of the instruction primitives in this row are 1, 3, 3, 1, 1, 3, 4, then divide this row into two rows, with the sizes of the instruction primitives in the first row being 1, 3, 3, 1, 1, and the sizes of the instruction primitives in the second row being 3, 4. Replace the content of this row with the content of the first row, and add a line break at the end. Traverse LadderGraphics backward from this row until a row is accessed whose first element is not blank and is not a line break. Insert a row above this row, add a line break at the beginning of the newly inserted row, and add the content of the second row to the newly inserted row. After the line wrapping operation is completed, continue to judge RowLength and MaxItemAmountPerRow, perform the traversal operation, and continue to traverse the next row.
[0127] Step S343, based on the ladder diagram data object and the normalized ladder diagram logic table after line break processing, determine the ladder diagram annotation situation, calculate the primitive drawing range and create the primitive object.
[0128] Access the data members isDeclarationShowed, isCommentsShowed, and isRegisterCommentsShowed of the ladder diagram data object LadderData to determine whether the comments of the ladder diagram need to be displayed. Access the data members QMap ContentOfDeclaration, ContentOfComments, and ContentOfRegisterComments in the ladder diagram data object LadderData to determine which row of the ladder diagram and which soft components have comments. Determine the comments of the ladder diagram by accessing the data members in the ladder diagram data object.
[0129] Furthermore, the vertical coordinate of the top of the graphic element in each row of the normalized ladder logic table LadderGraphics after the line break processing is calculated and stored in the corresponding QMap VerticalCoordinatesOfEachRow.
[0130] Furthermore, the LadCell elements of each row of the normalized ladder diagram logic table LadderGraphics after the line break processing are traversed, and according to the EComponentType type of the instruction corresponding to each element, the hash table CmdInfoData of the global singleton object of the GlobalCmdInfo type is queried, and the result is a structure CmdInfo that records the information of the instruction. Query CmdInfo.paraAmount to obtain the length required to draw the instruction on the ladder diagram. According to the length occupied by each instruction in this row and the vertical coordinates of the top of each primitive in this row, the size and upper left corner coordinates of the drawing range of each primitive in this row are calculated, thereby determining the primitive drawing range.
[0131] Step S35, drawing an initial ladder diagram based on the ladder diagram annotation, the primitive drawing range, and the primitive object.
[0132] The drawing range (QRectF), instruction type type, and soft component parameter content varialableNum of each LadCell element are passed as parameters to the ElementBaseItem constructor to create a new ElementBaseItem object. The object is assigned to LadCell.*pItem. The member function addItem() of QGraphicsScene is called to draw the instruction element corresponding to the LadCell at the corresponding position.
[0133] Call ProgramStep, ContentOfDeclaration, ContentOfRegisterComments, ContentOfComments, draw the declaration, annotation, comment, program pointer, and execution steps of the ladder diagram to complete the drawing of the initial ladder diagram.
[0134] In this embodiment, the LIST_ROW object obtained by compilation and decompilation is converted into a Ladder object, and only when the Ladder object has been compiled and decompiled, a standardized ladder logic table is generated according to the Ladder object. The syntax check and standardization processing of compilation and decompilation ensure the logical correctness of the ladder diagram, making the standardized ladder data structure easier to maintain and modify. When the ladder diagram needs to be modified, the relevant graphics can be more accurately located and modified, improving maintenance efficiency; traversing the standardized ladder logic table to determine the annotation of the ladder diagram and calculate the graphics drawing range, drawing the initial ladder diagram according to the annotation of the ladder diagram and the graphics drawing range, traversing the standardized ladder logic table to ensure the logical order and hierarchy of the ladder diagram, and a reasonable traversal process can optimize the drawing efficiency. Drawing the initial ladder diagram displays the user's drawing requirements in a visual way, and the user can make real-time adjustments and optimizations according to the initial ladder diagram to ensure the drawing quality of the final ladder diagram, improve the reliability of the ladder diagram drawing, and effectively reduce the error rate of the ladder diagram drawing.
[0135] Based on the first embodiment and / or the second embodiment of the present application, the third embodiment of the present application is proposed. In the third embodiment of the present application, the same or similar contents as those of the first embodiment and / or the second embodiment can be referred to the above introduction, and will not be repeated in the following.
[0136] On this basis, please refer to Figure 3 , Figure 3 A schematic flow chart of a third embodiment of the ladder diagram drawing method provided in the present application.
[0137] In this embodiment, the step S40 of redrawing the initial ladder diagram based on the pre-acquired ladder diagram modification data to obtain the redrawn ladder diagram may include steps S41 to S43:
[0138] Step S41, traverse the normalized ladder logic table, initialize the member variables of the normalized ladder logic table to default values, and obtain the initialized ladder logic table. Figure 2 Dimension table;
[0139] Traverse all rows in the normalized ladder diagram logic table LadderGraphics and all LadCell objects in each row, assign the member *pItem of each LadCell object to nullptr, and clear the data related to the drawing information.
[0140] If the type of the LadCell object is the end line break, remove the object from the row where the LadCell object is located. Add the elements of the row starting with the end line break of the object and the corresponding beginning line break to this row in order, retain the command content of the primitive drawing, and finally obtain an initialization ladder containing only the command content, which is convenient for various modification operations. Figure 2 Dimension table.
[0141] Step S42, selecting a corresponding graphic primitive object in the normalized ladder diagram logic table according to the pre-acquired ladder diagram modification data and modifying the graphic primitive object;
[0142] The ladder diagram drawing function module of the PLC configuration software calls the getSelectItem() function and the getSelectCellData(LadCell&cell) function to select the ElementBaseItem graphic element, and obtains the LadCell object and its data corresponding to the graphic element, so as to perform the modification operation.
[0143] Specifically, the getSelectItem() function is used to get the currently selected ElementBaseItem primitive object. The ElementBaseItem class inherits from QGraphicsItem and represents the instruction primitive in the ladder diagram. The getSelectCellData(LadCell&cell) function is used to get the LadCell object and its data corresponding to the currently selected ElementBaseItem primitive, and store the data in the cell parameter. The LadCell class represents the cell in the normalized ladder diagram logic table LadderGraphics, which contains information such as instruction content and connection relationships.
[0144] Through these two functions, detailed information of the selected graphic element is obtained, and corresponding operations are performed. For example, according to the connection relationship in the LadCell object and the ladder diagram change data input by the user, it is determined whether a branch can be added, or according to the instruction type in the LadCell object and the ladder diagram change data input by the user, the appropriate instruction is selected for replacement, thereby realizing the modification of the graphic element object.
[0145] It should be noted that the modification of image objects needs to be handled according to different situations. If a non-end component is used to replace an end component, it is not allowed and an error message will pop up.
[0146] If you use an end component to replace a non-end component: If there is already an end component in this row, it is not allowed and an error message will pop up. If there is a non-end component after the replacement position, delete all the components after it and replace them with blanks. If there is no end component in this row, place the end component at the end of this row and fill the empty space in the middle with a horizontal connecting line. Calculate the length of the end component that can be drawn based on the length of the empty space between the last non-connecting line and blank component in this row and the end of this row. If the length of the replaced component exceeds the drawable length, add a new row after this row and draw line breaks at the end of this row and the beginning of the new row. Draw the new end component at the end of the new row. Then call the function VoidRapaintRows(int StartRow, int InsertedRows), traverse the rows after the new row, modify the drawing range of each primitive, and redraw the ladder diagram on the canvas.
[0147] If the end element is replaced with an end element: first remove the LadCell and *pItem corresponding to the replaced end element to release the corresponding storage space. Then, calculate the length of the end element that can be drawn based on the length of the space between the last non-connected line and blank element in this row and the end of this row. If the length of the replaced element exceeds the drawable length, add a new row after this row, and draw line breaks at the end of this row and the beginning of the new row. Draw the new end element at the end of the new row. Then call the function Void RapaintRows(int StartRow, intInsertedRows), traverse the rows after the new row, modify the drawing range of each graphic element, and redraw the ladder diagram on the canvas.
[0148] If a non-end element is replaced with a non-end element: First, calculate the length of the non-end element that can be drawn based on the first non-connected line and blank element after the non-end element, and the length of the space between the replaced non-end element. If the length of the replaced element exceeds the length that can be drawn, a pop-up window will pop up to indicate that it cannot be drawn, and prompt the user to increase the maximum number of graphics that can be displayed per row. If it can be drawn, remove the LadCell and *pItem corresponding to the replaced non-end element to release the corresponding storage space. Replace it with the non-end element to be drawn.
[0149] In addition, it should be noted that the operation of inserting a blank row above / below the currently selected row is as follows: If a blank row is inserted above the nth row: add a row between the n-1th row and the nth row of LIST_ROW LadderGraphics, with the content of MaxItemAmountPerRow blank graphics. Call the function Void RapaintRows(int StartRow, intInsertedRows), traverse the rows after the newly added row, modify the drawing range of each graphics element, and redraw the ladder diagram on the canvas. Update the content of Ladder;
[0150] If a blank row is inserted below the nth row: Traverse the nth row of LIST_ROW LadderGraphics.
[0151] If there is no element with a branch in the nth row of LIST_ROW LadderGraphics, add a row between the nth and n+1th rows of LIST_ROWLadderGraphics, with the content of MaxItemAmountPerRow blank elements. Call the function Void RapaintRows(int StartRow, int InsertedRows), traverse the rows after the added row, modify the drawing range of each element, and redraw the ladder diagram on the canvas. Update the content of the ladder.
[0152] If there is a graphic element with branches in the nth row of LIST_ROW Ladder, add a row between the nth and n+1th rows of LIST_ROW LadderGraphics, with the content of MaxItemAmountPerRow blank graphics elements. The blank graphics element below the graphic element with branches in the nth row also has branches. Call the function Void RapaintRows(intStartRow, int InsertedRows), traverse the rows after the newly added row, modify the drawing range of each graphic element, and redraw the ladder diagram on the canvas. Update the content of Ladder: int insertRowsBackward(const int row_count);
[0153] If you need to remove a row: remove the nth LIST_CELL element of the LIST_ROW LadderGraphics representing the nth row of the ladder diagram. Call the function Void RapaintRows(int StartRow, int InsertedRows), traverse the rows after the nth row, modify the drawing range of each graphic element, redraw the ladder diagram on the canvas and update the content of the ladder.
[0154] Step S43, based on the modified primitive object and the initialization trapezoid Figure 2 The dimension table redraws the initial ladder diagram to obtain a redrawn ladder diagram.
[0155] Return the modified element data to the initialization ladder Figure 2 In the dimension table, according to the initialization ladder with modified data Figure 2 The dimension table redraws the initial ladder diagram to obtain the redrawn ladder diagram. Revisit LadderDate and obtain the hidden or displayed soft component comments based on the values of isDeclarationShowed, isCommentsShowed, and isRegisterCommentsShowed. After the hidden / displayed state of the soft component comments changes, traverse all elements of LadderGraphics and change the drawing range of all graphics.
[0156] Furthermore, the LadderGraphics is traversed from the int StartRow row to each row, and the drawing range of each row is changed according to the number of newly added rows int InsertedRows, and the primitives are redrawn. The width and height of a single primitive are determined according to the set display scale DisplayScale, whether to display soft component comments isRegisterCommentsShowed, and the base width and height of a single primitive BaseWidthOfEachUnit and BaseHeightOfEachUnit, thereby completing the redrawing of the ladder diagram.
[0157] In this embodiment, the normalized ladder diagram logic table is converted into an initial ladder diagram logic table, and the initial ladder diagram is redrawn based on the pre-acquired ladder diagram change data to obtain a redrawn ladder diagram. Since operations such as adding, deleting, modifying primitives, and adjusting primitive positions will cause changes in the content of the ladder diagram, it needs to be redrawn to reflect the latest ladder diagram structure. By redrawing the ladder diagram, the error rate of ladder diagram drawing is effectively reduced and the drawing reliability is improved.
[0158] Based on the above embodiments of the present application, a fourth embodiment of the present application is proposed. In the fourth embodiment of the present application, the same or similar contents as those of the above embodiments can be referred to the above introduction, and will not be described in detail later.
[0159] On this basis, refer to Figure 4 , Figure 4 This is a flow chart of the fourth embodiment of the ladder diagram drawing method of the present application.
[0160] In this embodiment, the initial ladder diagram is redrawn based on the pre-acquired ladder diagram modification data, and step S40 of obtaining the redrawn ladder diagram further includes step S50:
[0161] Step S50, saving the normalized ladder diagram logic table and the ladder diagram data object, and outputting an error information log.
[0162] The ladder diagram data object LadderData stores all the data and status information of the ladder diagram, including instruction content, connection relationship, comments, program pointer, number of steps, etc. Saving the LadderData object can easily restore the program status, for example, when the program is reopened after a crash or accidental closure, it can be restored to the previous editing state.
[0163] The normalized ladder logic table LadderGraphics stores the drawing information of the ladder diagram on the canvas, including the coordinates and appearance of the graphics elements. Saving the LadderGraphics object can ensure the consistent display effect of the ladder diagram. Even if the program is restarted or switched to monitoring mode and then returned to editing mode, the ladder diagram can be displayed correctly.
[0164] Outputting error logs can help developers track problems that occur during program operation, such as syntax errors, runtime errors, etc. By analyzing error logs, problems can be quickly located and fixed.
[0165] In this embodiment, saving the data in the LadderData object and the LadderGraphics object, and outputting the error log are important measures to ensure the stable operation and convenient maintenance of the ladder diagram drawing function module of the PLC configuration software, so as to improve the drawing reliability.
[0166] This application also provides a ladder diagram drawing device, please refer to Figure 5 , the ladder diagram drawing device comprises:
[0167] A ladder diagram data object generation module 10 is used to obtain a ladder diagram drawing element input by a user, and read the ladder diagram drawing element into an initialized global singleton object to obtain a ladder diagram data object;
[0168] The initialized global singleton object stores all drawing elements used to draw a ladder diagram, and the ladder diagram drawing elements input by the user are read into the initialized global singleton object to obtain the ladder diagram data object: Class Ladder Data.
[0169] A compiling and decompiling module 20 compiles and decompiles the ladder diagram data object to obtain compiling and decompiling results;
[0170] The LIST_ROW Ladder is passed to the compiling module and the decompiling module. The compiling module compiles the LIST_ROW Ladder into text instruction content and then passes it to the decompiling module. The decompiling module decompiles the text instruction content into a two-dimensional table LIST_ROW object.
[0171] An initial ladder diagram drawing module 30, used to generate a normalized ladder diagram logic table according to the compilation and decompilation results, and traverse the normalized ladder diagram logic table to draw an initial ladder diagram;
[0172] The ladder diagram drawing function module of the PLC configuration software traverses the standardized ladder diagram logic table LadderGraphics, draws the initial ladder diagram according to the ladder diagram drawing elements in the standardized ladder diagram logic table LadderGraphics, and converts the logic data into visual graphic elements, such as contacts, coils, connecting lines, etc., so as to display and edit them on the canvas.
[0173] The ladder diagram redrawing module 40 is used to transform the normalized ladder diagram logic table into an initial ladder diagram logic table, and redraw the initial ladder diagram based on the pre-acquired ladder diagram modification data to obtain a redrawn ladder diagram.
[0174] Since the user usually modifies the initial ladder diagram after it is drawn, in order to respond to various operations and settings of the user, it is necessary to convert the normalized ladder diagram logic table into the initial ladder diagram logic table, clear the previous element drawing information, modify the drawing data in the initial ladder diagram logic table in combination with the ladder diagram change data modified by the user, re-traverse the modified initial ladder diagram logic table, redraw the initial ladder diagram, and obtain a redrawn ladder diagram.
[0175] The ladder diagram drawing device provided by the present application adopts the ladder diagram drawing method in the above embodiment, which can solve the technical problem of ladder diagram drawing. Compared with the prior art, the beneficial effects of the ladder diagram drawing device provided by the present application are the same as the beneficial effects of the ladder diagram drawing method provided by the above embodiment, and other technical features in the ladder diagram drawing device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0176] The present application provides a ladder diagram drawing device, which includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the ladder diagram drawing method in the above-mentioned embodiment one.
[0177] Reference below Figure 6, which shows a schematic diagram of the structure of a ladder diagram drawing device suitable for implementing the embodiment of the present application. The ladder diagram drawing device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The ladder diagram drawing device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0178] like Figure 6 As shown, the ladder diagram drawing device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the ladder diagram drawing device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the ladder diagram drawing device to communicate wirelessly or wired with other devices to exchange data. Although the figure shows a ladder diagram drawing device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or provided instead.
[0179] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0180] The ladder diagram drawing device provided by the present application adopts the ladder diagram drawing method in the above embodiment, which can solve the technical problem of ladder diagram drawing. Compared with the prior art, the beneficial effects of the ladder diagram drawing device provided by the present application are the same as the beneficial effects of the ladder diagram drawing method provided by the above embodiment, and the other technical features in the ladder diagram drawing device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0181] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0182] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0183] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the ladder diagram drawing method in the above-mentioned embodiment.
[0184] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0185] The computer-readable storage medium may be included in the ladder diagram drawing device; or may exist independently without being assembled into the ladder diagram drawing device.
[0186] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the ladder diagram drawing device, the ladder diagram drawing device: obtains the ladder diagram drawing elements input by the user, and reads the ladder diagram drawing elements into the initialized global singleton object to obtain a ladder diagram data object; compiles and decompiles the ladder diagram data object to obtain compilation and decompilation results; generates a normalized ladder diagram logic table according to the compilation and decompilation results, traverses the normalized ladder diagram logic table to draw an initial ladder diagram; redraws the initial ladder diagram based on the pre-acquired ladder diagram change data to obtain a redrawn ladder diagram.
[0187] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0188] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0189] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0190] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned ladder diagram drawing method, and can solve the technical problem of ladder diagram drawing. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the ladder diagram drawing method provided in the above-mentioned embodiment, and will not be repeated here.
[0191] The present application also provides a computer program product, including a computer program, which implements the steps of the ladder diagram drawing method as described above when executed by a processor.
[0192] The computer program product provided by the present application can solve the technical problem of ladder diagram drawing. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the ladder diagram drawing method provided by the above embodiment, which will not be repeated here.
[0193] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A ladder diagram drawing method, characterized in that: The method comprises: Get the ladder diagram drawing elements input by the user; Create a global singleton object according to preset ladder diagram syntax semantics and initialize member variables of the global singleton object to default values to obtain an initialized global singleton object; Read the ladder diagram drawing element into the initialized global singleton object to obtain a ladder diagram data object; Compiling and decompiling the ladder diagram data object to obtain compilation and decompile results; Convert the compilation and decompilation results into Ladder objects; Accessing compilation and decompilation member variables, and determining whether the Ladder object has been compiled and decompiled according to the compilation and decompilation member variables; When the Ladder object has been compiled and decompiled, generating a normalized ladder logic table according to the Ladder object; Traversing the normalized ladder diagram logic table to determine the ladder diagram annotation situation and calculate the primitive drawing range; Draw an initial ladder diagram based on the ladder diagram annotation situation and the primitive drawing range; Traversing the normalized ladder diagram logic table, initializing the member variables of the normalized ladder diagram logic table to default values, and obtaining an initialized ladder diagram two-dimensional table; Selecting the corresponding primitive object in the normalized ladder diagram logic table according to the pre-acquired ladder diagram change data and modifying the primitive object based on the end element and non-end element replacement rules; The initial ladder diagram is redrawn based on the modified primitive object and the initialization ladder diagram two-dimensional table to obtain a redrawn ladder diagram.
2. The method according to claim 1, characterized in that The step of compiling and decompiling the ladder diagram data object to obtain the compilation and decompile results comprises: Performing format conversion on the ladder diagram data object, and detecting the legality of the content of the ladder diagram data object after format conversion; When the content of the ladder diagram data object after format conversion is legal, compiling the ladder diagram data object into text instructions; Decompile the text instructions to obtain compilation and decompilation results.
3. The method according to claim 1, characterized in that The step of traversing the normalized ladder diagram logic table to determine the ladder diagram annotation situation and calculate the primitive drawing range comprises: Traversing the normalized ladder logic table to calculate the length value of each row of elements in the normalized ladder logic table; Performing line break processing on the normalized ladder diagram logic table according to the maximum number of graphic elements displayed in each line of the ladder diagram data object and the length value of the element in each line; Based on the ladder diagram data object and the normalized ladder diagram logic table after line break processing, the ladder diagram annotation situation is determined and the primitive drawing range is calculated.
4. The method according to claim 1, characterized in that After the step of redrawing the initial ladder diagram based on the modified primitive object and the initialization ladder diagram two-dimensional table to obtain the redrawn ladder diagram, the step further includes: The normalized ladder diagram logic table and the ladder diagram data object are saved, and an error information log is output.
5. A ladder diagram drawing device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the ladder diagram drawing method according to any one of claims 1 to 4.
6. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the ladder diagram drawing method according to any one of claims 1 to 4 are implemented.
7. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the ladder diagram drawing method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Method for converting PLC instruction list into ladder diagram based on generator set controller
CN104460489A
PLC ladder diagram editing method based on scene view structure
CN114237585A