PLC ladder diagram drawing method and device, equipment and storage medium
By distinguishing the original content of storing ladder diagrams and drawing representation data in PLC hosting software, generating intermediate data and calling drawing functions, the problems of insufficient editing flexibility of ladder diagram editing module and single data structure design in the prior art are solved. A more efficient and convenient ladder diagram editing process is achieved.
Patent Information
- Application Number
- CN202411501294.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2044-10-25
AI Technical Summary
The existing PLC hosting software lacks editing flexibility in the ladder diagram editing module, and the data structure is designed in a single way, making it difficult to restore to its previous state in complex operations.
By distinguishing and independently storing the original content of the ladder diagram and drawing representation data, generating intermediate ontology data and intermediate drawing data, and calling drawing functions for drawing, flexible adjustment and editing of ladder diagrams are achieved.
While keeping the content of the ladder graph unchanged, it improves editing efficiency and flexibility, reduces the risk of errors introduced due to improper data processing, and enhances the convenience of programming and debugging.
Smart Images

Figure CN119472486A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet technology, and in particular to a method, device, equipment and storage medium for drawing a PLC ladder diagram. Background Art
[0002] With the rapid development of industrial automation technology, PLC (Programmable Logic Controller) devices have become the core component of modern industrial control and are widely used in various fields such as manufacturing, energy, and transportation. The widespread application of PLC devices has promoted the development of host computer software, which provides users with an intuitive and convenient way to design, edit, and control PLC programs. Among them, ladder diagrams are one of the most commonly used graphical programming languages in PLC programming, and their editing modules have become the core functional modules in host computer software.
[0003] However, although the PLC host computer software on the current market has made significant progress in functionality and ease of use, there are still some challenges in the design of the ladder diagram editing module. Specifically, the existing technology lacks sufficient flexibility in editing and modifying the ladder diagram. When the user needs to adjust the drawing parameters of the ladder diagram or perform complex operations, such as batch replacement of soft component content, the software often needs to reprocess the original data of the entire ladder diagram, which not only reduces the editing efficiency, but also may introduce errors due to improper data processing, affecting the accuracy of the ladder diagram and the stability of the system operation.
[0004] In addition, some PLC host software has a single data structure design problem, that is, a unified data structure is used to store and manage all ladder diagram data. This design simplifies the data processing process, but when faced with scenarios where complex operations need to be undone, due to the lack of intermediate state records required for undoing operations, users often cannot restore to the previous state after performing these operations, which brings inconvenience to programming and debugging. Summary of the invention
[0005] The main purpose of this application is to provide a PLC ladder diagram drawing method, device, equipment and storage medium, aiming to solve the technical problems of insufficient editing flexibility and single data structure design in the ladder diagram editing module of the current PLC host computer software.
[0006] To achieve the above object, the present application provides a method for drawing a PLC ladder diagram, and the method for drawing a PLC ladder diagram comprises the following steps:
[0007] Initialize the ladder diagram and obtain the initial drawing data of the initial ladder diagram;
[0008] Generating intermediate ontology data according to the initial drawing data;
[0009] Generate intermediate rendering data according to the intermediate ontology data and a preset parameter set;
[0010] The drawing function is called to draw according to the intermediate drawing data to obtain a result ladder diagram.
[0011] In one embodiment, after the step of initializing the ladder diagram and obtaining the initial drawing data of the initial ladder diagram, the step further includes:
[0012] Perform a ladder diagram check on the initial drawing data. If the check result is correct, execute the following steps: generate intermediate body data according to the initial drawing data.
[0013] In one embodiment, the step of generating intermediate ontology data according to the initial rendering data includes:
[0014] The non-ladder diagram body data in the initial drawing data is stored separately in a global singleton;
[0015] The initial drawing data is traversed, and the following operations are performed on each row of the initial drawing data:
[0016] If the end of the current line is a termination symbol, the content of the current line is stored as intermediate body data;
[0017] If the end of the current line is a line feed symbol, the current line and the adjacent line are merged into a single line and stored as intermediate body data.
[0018] In one embodiment, after the step of generating intermediate ontology data according to the initial drawing data, the step further includes:
[0019] The intermediate ontology data is normalized.
[0020] In one embodiment, the step of normalizing the intermediate ontology data includes:
[0021] Compiling the intermediate ontology data into text instructions;
[0022] The text instructions are decompiled to generate standardized intermediate ontology data.
[0023] In one embodiment, the step of generating intermediate rendering data according to the intermediate ontology data and the preset parameter set includes:
[0024] Traversing the intermediate ontology data, and performing a row processing operation on each row of the intermediate ontology data to obtain intermediate data;
[0025] Obtaining drawing parameter data of a ladder diagram according to the intermediate data and the preset parameters;
[0026] Traversing the intermediate data to obtain the drawing range data of the ladder diagram;
[0027] Based on the drawing parameter data and the drawing range data, intermediate drawing data is generated.
[0028] In one embodiment, the step of traversing the intermediate ontology data and performing a row processing operation on each row of the intermediate ontology data to obtain the intermediate data includes:
[0029] If the length of the current line is not greater than the preset maximum length, the content of the current line is stored as intermediate drawing data;
[0030] If the length of the current line is greater than the preset maximum length, the current line is split into two lines and stored as intermediate drawing data.
[0031] In addition, to achieve the above-mentioned purpose, the present application also provides a PLC ladder diagram drawing device, the PLC ladder diagram drawing device comprising:
[0032] A first acquisition module, used for initializing the ladder diagram and acquiring initial drawing data of the initial ladder diagram;
[0033] A second acquisition module, used to generate intermediate ontology data according to the initial drawing data;
[0034] A third acquisition module, used to generate intermediate rendering data according to the intermediate ontology data and a preset parameter set;
[0035] The drawing module is used to call the drawing function to draw a result ladder diagram according to the intermediate drawing data.
[0036] In addition, to achieve the above-mentioned purpose, the present application also provides a terminal device, which includes a memory, a processor, and a PLC ladder diagram drawing program stored in the memory and runnable on the processor, and the PLC ladder diagram drawing program, when executed by the processor, implements the steps of the PLC ladder diagram drawing method as described above.
[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a computer-readable storage medium, on which a PLC ladder diagram drawing program is stored. When the PLC ladder diagram drawing program is executed by a processor, the steps of the PLC ladder diagram drawing method as described above are implemented.
[0038] One or more technical solutions proposed in this application have at least the following technical effects:
[0039] The present application achieves flexible adjustment of the drawing parameters and appearance of the ladder diagram while keeping the content of the ladder diagram unchanged by distinguishing and independently storing the original content of the ladder diagram, namely the main body data, and the drawing representation data, namely the drawing data.
[0040] Specifically, the ladder diagram is first initialized and the initial drawing data of the initial ladder diagram is obtained. After the initial drawing data is obtained, the intermediate body data is generated. The intermediate drawing data is generated according to the intermediate body data and the preset parameter set, and the drawing function is called to draw the ladder diagram. Through this process, the user can flexibly adjust the appearance of the ladder diagram according to different drawing parameter requirements, such as the number of single-line contacts, annotation display, etc., without having to reprocess the original data of the entire ladder diagram. This not only improves editing efficiency, but also reduces the risk of errors introduced by improper data processing.
[0041] Compared with the prior art, the present application achieves a significant improvement in editing flexibility during the ladder diagram drawing process. Users can flexibly adjust the drawing parameters to meet different design requirements without changing the original content of the ladder diagram. At the same time, since two sets of data structures are used to store the original content and drawing representation data of the ladder diagram respectively, it is easier to restore to the previous state in complex editing operations, improving the convenience of programming and debugging. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A schematic flow chart of a first exemplary embodiment of a method for drawing a PLC ladder diagram of the present application;
[0043] Figure 2 A schematic flow chart of a second exemplary embodiment of a method for drawing a PLC ladder diagram of the present application;
[0044] Figure 3 A schematic flow chart of a third exemplary embodiment of a method for drawing a PLC ladder diagram of the present application;
[0045] Figure 4 A schematic diagram of the module structure of a device for drawing a PLC ladder diagram according to an embodiment of the present application;
[0046] Figure 5 It is a schematic diagram of the equipment structure of the hardware operating environment involved in the method for drawing a PLC ladder diagram in an embodiment of the present application.
[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] The main solution of the embodiment of the present application is: initialize the ladder diagram and obtain the initial drawing data of the initial ladder diagram; generate intermediate body data according to the initial drawing data; generate intermediate drawing data according to the intermediate body data and the preset parameter set; call the drawing function to draw according to the intermediate drawing data to obtain the result ladder diagram. Compared with the problems of insufficient editing flexibility and single data structure design in the PLC ladder diagram editing module in the prior art, by using two sets of data structures to store the original content and drawing representation data of the ladder diagram respectively, and based on these data structures, flexibly adjusting the drawing parameters and modifying the appearance, it is achieved that the flexibility and editing efficiency of the ladder diagram drawing are significantly improved without changing the original content of the ladder diagram.
[0050] The executor of the method of this embodiment can be a PLC ladder diagram drawing device, or it can be a PLC ladder diagram drawing terminal device or server. This embodiment takes a PLC ladder diagram drawing device as an example. The PLC ladder diagram drawing device can be integrated on a terminal device such as a smart phone, tablet computer, etc. with data processing function.
[0051] Specifically, the following are the detailed steps of an exemplary embodiment of the method for drawing a PLC ladder diagram:
[0052] Reference Figure 1 , Figure 1 The flowchart of the first exemplary embodiment of the method for drawing a PLC ladder diagram of the present application is shown in FIG. In this embodiment, the method for drawing a PLC ladder diagram includes steps S10 to S40:
[0053] Step S10, initializing the ladder diagram and obtaining initial drawing data of the initial ladder diagram;
[0054] It should be noted that, first, start the host computer software provided by the PLC manufacturer. After the software is opened, the user will be directed to the ladder diagram editing interface. This interface is the main working area for users to design, edit and modify ladder diagrams.
[0055] After the ladder diagram editing interface is loaded, the software will automatically perform a series of initialization operations to ensure the smooth progress of subsequent work. The key step is to create two sets of data structures: Ladder and LadderGraphics.
[0056] Ladder is used to store the content of the original ladder diagram, i.e. the main body data. This includes all the logical elements in the ladder diagram, such as input and output points, coils, contacts and the connection relationship between them. This data structure ensures the integrity and accuracy of the ladder diagram information, and provides a reliable basis for subsequent editing, simulation and downloading to PLC.
[0057] LadderGraphics is used to store all the data required for drawing ladder diagrams, i.e. drawing data. It contains the graphic information required for drawing ladder diagrams, such as the number of single-line contacts, whether declarations / annotations / soft component comments are displayed, the number of soft component comment lines, etc. This information is used to visualize the ladder diagram, so that users can intuitively see the layout and logical structure of the ladder diagram.
[0058] Specifically, after completing the initialization of the editing environment, the software system will further initialize an empty ladder diagram template. This template serves as the starting point for subsequent users to draw ladder diagrams, and some basic layout and property settings have been preset inside it. Data related to the initial ladder diagram drawing can be read from LadderGraphics, such as the default background color, grid line spacing, default component icons in the component library, etc., and then a basic ladder diagram framework can be drawn on the editing interface based on these data.
[0059] If the system provides a simple start / stop control logic as the initial ladder diagram by default, then when executing step S10, a ladder diagram frame including a start button, a stop button and an output coil appears on the user editing interface. The position, size, color and other attributes of these elements have been pre-set according to the data in LadderGraphics, and the user can directly perform further editing and expansion based on this.
[0060] Step S20, generating intermediate ontology data according to the initial drawing data;
[0061] In a feasible implementation, step S20 may include steps S21 to S23:
[0062] Step S21, storing the non-ladder diagram body data in the initial drawing data separately into a global singleton;
[0063] It should be noted that the non-ladder diagram ontology data in this step may include titles, captions, or other metadata that is not directly involved in drawing graphics. In order to ensure the availability and consistency of this data throughout the entire processing flow, the non-ladder diagram ontology data is extracted separately and stored in a global singleton object. The use of a global singleton ensures that these non-ladder diagram ontology data are only stored and accessed once throughout the entire application or processing process, avoiding data redundancy and access conflicts.
[0064] Step S22, traversing the initial drawing data, and performing the following operations on each line of the initial drawing data: if the end of the current line is an end symbol, storing the content of the current line as intermediate body data;
[0065] Specifically, the initial drawing data, that is, the content in LadderGraphics, is traversed. These data are generated based on the drawing parameters of the ladder diagram and additional content (such as declarations, annotations, etc.). They record in detail every piece of information required for drawing the ladder diagram. For each line of data in the traversal process, the following judgment will be made: check whether the end of the current line is an end symbol. In the representation of the ladder diagram, the end symbol usually marks the end of a complete instruction or a section of the ladder diagram content. If the end of the current line is indeed an end symbol, then this line of data will be directly regarded as part of the intermediate body data of the ladder diagram and stored. Here, the intermediate body data is actually a reconstruction of the original content of the ladder diagram. It removes redundant information related to drawing and retains only the core logic of the ladder diagram.
[0066] Step S23: if the end of the current line is a line feed symbol, the current line and the adjacent lines are merged into a single line and stored as intermediate ontology data.
[0067] Specifically, when a line ends with a newline symbol, the current line will not be immediately stored as an independent intermediate ontology data item when a newline symbol is detected. Instead, subsequent lines that are closely connected to the current line will be searched and merged until a new end symbol or the end of the file is encountered. This merging process ensures that even if a data item spans multiple lines, it can be correctly identified and processed as a single intermediate ontology data item for storage.
[0068] For example, suppose there is an initial drawing data, which represents a simple ladder diagram, which contains two lines of data. The end of the first line of data is a contact instruction followed by a line feed symbol; the beginning of the second line of data is a coil instruction and the end is an end symbol. When traversing these data, the first line is processed first. Since it ends with a line feed symbol, the next line, that is, the second line, is searched, and the two lines are merged into a complete instruction sequence (a contact instruction followed by a coil instruction), which is then stored as the intermediate body data. Since the second line ends with an end symbol, after merging, this complete instruction sequence also ends.
[0069] Step S30, generating intermediate rendering data according to the intermediate ontology data and a preset parameter set;
[0070] In a feasible implementation, step S30 may include steps S31 to S34:
[0071] Step S31, traversing the intermediate ontology data, performing a row processing operation on each row of the intermediate ontology data to obtain intermediate data;
[0072] In a feasible implementation, step S31 may include steps S311 to S312:
[0073] Step S311, if the length of the current line is not greater than the preset maximum length, the content of the current line is stored as intermediate drawing data;
[0074] Specifically, first check the length of the current line. The "length of the current line" refers to the number of characters or bytes contained in the line data, which depends on the data encoding method and system definition. If the length of the current line is not greater than the preset maximum length, directly store the content of the line as intermediate drawing data. The purpose of this is to maintain the integrity of the data and to be able to directly use these unmodified data in the subsequent graphics drawing process.
[0075] Step S312: if the length of the current line is greater than the preset maximum length, the current line is divided into two lines and stored as intermediate drawing data.
[0076] However, if the length of the current row exceeds the preset maximum length, the operation of step S412 is performed. Specifically, the overlong row data is divided into two or more parts, each of which is less than or equal to the preset maximum length, and the divided parts are respectively stored as intermediate drawing data. The purpose of this is to meet the display requirements of the graphical interface, ensure that the overlong data row does not exceed the display area, and also facilitate subsequent graphics drawing and display.
[0077] Step S32, obtaining drawing parameter data of the ladder diagram according to the intermediate data and the preset parameters;
[0078] It should be noted that in this step, the intermediate data generated in step S31 (i.e., the processed and possibly segmented row data) is analyzed, and the specific parameters required for drawing the ladder diagram are calculated in combination with a preset parameter set. The preset parameters may include the size, layout specification, color configuration, line thickness, etc. of the ladder diagram.
[0079] Specifically, first load the preset parameter set, which defines the overall appearance and behavior of the ladder diagram. Then, traverse the intermediate data, which is the row data stored in LadderGraphics, and calculate the specific position (such as horizontal and vertical coordinates), size (such as height, width), style (such as color, line type), etc. of each row on the ladder diagram according to the characteristics of each row of data (such as length, content, etc.) and preset parameters. Based on the above analysis, generate corresponding drawing parameter data for each row of data, which will be directly used for subsequent drawing operations.
[0080] Assume that the preset parameters specify that the width of the ladder diagram is 800 pixels, the height is adaptive, and the default color of all rows is black, and the line thickness is 1 pixel. When a certain intermediate data (such as "input signal X") is parsed, and its length is 20 characters, the position of the data on the ladder diagram (such as x = 100, y = the accumulated height of the current row) and the size (such as width = 20*character width unit, height = row height) are calculated, and these parameters are packaged together with information such as color and line thickness as drawing parameter data.
[0081] It should be noted that after obtaining the drawing parameters, optimization and adjustment are performed to ensure the best drawing effect.
[0082] Specifically, it checks whether there are conflicts between the generated drawing parameters (such as two rows of data overlapping on the ladder diagram). If a conflict is found, the position or size of the relevant rows is automatically adjusted according to the preset priority or algorithm logic. According to the complexity of the drawing and the performance characteristics of the target platform, the drawing parameters are fine-tuned to balance the drawing quality and rendering efficiency.
[0083] Step S33, traversing the intermediate data to obtain the drawing range data of the ladder diagram;
[0084] Specifically, the vertical coordinate of the top of each row of primitives is calculated based on the number of rows where the declaration and annotation are located and the height of each primitive, and then each LadCell object in LadderGraphics is traversed to calculate the coordinates and drawing range of each primitive based on the number of rows and columns where the object is located, the vertical coordinate of the top of the row, and the width of each primitive. This step ensures that when the ladder diagram is drawn, each element can be accurately positioned in the correct position on the canvas.
[0085] Step S34: generating intermediate drawing data based on the drawing parameter data and the drawing range data.
[0086] Specifically, after calculating the drawing parameters and ranges of all graphics elements, these data can be integrated into intermediate drawing data, namely LadderGraphics. At this point, LadderGraphics already contains all the information required to draw the ladder diagram, including the type, content, coordinates, size of the graphics element, and any related declarations, annotations, and soft component comments. Subsequently, these data will be passed to the drawing function to generate the final ladder diagram result.
[0087] Example 1, if the preset maximum length x is 10 graphic units; there is a line in the intermediate body data, and its content length y is 15 graphic units. The content of this line needs to be divided into two lines, and there is a line break between them, and the line break number is the same. The soft component comments are displayed in the global settings, and each soft component comment occupies 0.5 graphic unit height. There is a statement before the line content, which occupies 1 line and is 1 graphic unit high. The basic height of each line of the ladder diagram is 1 graphic unit (excluding soft component comments).
[0088] According to step S312, the original line with a length of 15 pixel units is divided into two lines. The length of the first line is 10 pixel units (the value of x). The length of the second line is 15-10+2=7 pixel units (the value of y+2-x), where +2 is to ensure that the two lines can be correctly connected through the line break.
[0089] Calculate the vertical coordinate of the top of each row of primitives: the declaration takes up 1 row, and the height is 1 primitive unit, so drawing starts from the second row. The vertical coordinate of the top of the first row of primitives is 1 (counting starts from 0, the first row is the declaration, and occupies 1 unit). The second row is immediately below the first row, so its vertical coordinate is 1+1+0.5=2.5 (the height of the first row 1 plus the soft component comment 0.5, if there are multiple comments, they are accumulated).
[0090] Calculate the coordinates and drawing range of each primitive:
[0091] Assuming the cell width is 1 cell unit, for each LadCell object in the first row (10 in total):
[0092] Located in the 1st row, the top vertical coordinate is 1.
[0093] The horizontal axis starts at 0 and increases by 1 unit for each primitive.
[0094] For each LadCell object in the second row (7 in total):
[0095] Located in the 2nd row, the top vertical coordinate is 2.5.
[0096] The horizontal axis starts at 0 and increases by 1 unit for each primitive.
[0097] Plot the result:
[0098] The first row starts at (0,1) and draws 10 primitives, ranging to (9,1).
[0099] The second line starts at (0,2.5) and draws 7 primitives, ranging to (6,2.5).
[0100] Step S40, calling a drawing function to draw according to the intermediate drawing data to obtain a result ladder diagram.
[0101] Specifically, the drawing process is prepared according to the information contained in the intermediate drawing data, such as the position, size, type (such as straight line, contact instruction, coil instruction, etc.) of each graphic element and the overall layout parameters of the ladder diagram. This information is calculated and stored in the intermediate drawing data to ensure that the drawn ladder diagram not only conforms to the content of the original ladder diagram, but also meets the drawing parameters set by the user, such as the number of single-line contacts, annotation display, etc.
[0102] Next, traverse each row of the intermediate drawing data and each primitive in each row. For each primitive, call the corresponding drawing function according to its type. For example, if the primitive is a straight line, the system will call the function for drawing the straight line and pass in the coordinates of the starting and ending points of the straight line, as well as parameters such as the thickness of the line; if the primitive is a touch point instruction, the system will call the function for drawing the touch point instruction and pass in parameters such as the position, size, shape of the touch point, and instruction content.
[0103] During the drawing process, graphics elements that need to display declarations, annotations or soft component comments are also processed. For these graphics elements, they are correctly drawn at the corresponding positions of the ladder diagram according to the declarations and annotations stored in the global singleton and the currently set display parameters.
[0104] Finally, when all the primitives are drawn correctly, check and draw the left and right current buses to ensure the integrity of the ladder diagram. The current buses are an important part of the ladder diagram. They are usually located on both sides of the ladder diagram and indicate the path of the current in the ladder diagram.
[0105] For example, suppose that the user is drawing a simple ladder diagram, which includes a contact instruction and a coil instruction, and the user sets the display annotation. In step S40, the contact instruction and the coil instruction are first drawn, and then the annotation is drawn below the contact instruction according to the annotation content stored in the global singleton. Finally, the left and right current buses are checked and drawn, thereby completing the drawing process of the entire ladder diagram.
[0106] In summary, step S40 realizes the process of converting the processed data into a visual ladder diagram by calling the drawing function and drawing according to the intermediate drawing data. This process not only ensures the accuracy of the ladder diagram, but also meets the user's demand for flexible setting of drawing parameters.
[0107] Further, refer to Figure 2 , Figure 2 This is a flow chart of the second embodiment of the method for drawing a PLC ladder diagram of the present application. Figure 1 In the embodiment shown, in this embodiment, step S10 may include step S50:
[0108] Step S50, performing ladder diagram verification on the initial drawing data, if the verification result is correct, executing the step: generating intermediate body data according to the initial drawing data.
[0109] Specifically, after the initialization of the ladder diagram is completed and the initial drawing data of the initial ladder diagram is successfully obtained, step S50 is executed for verification. The main purpose of this step is to ensure the accuracy and compliance of the initial drawing data so that the intermediate ontology data can be smoothly generated later.
[0110] When executing step S50, the initial drawing data is firstly subjected to a syntax check. This includes verifying whether the format and content of each instruction and each graphic element of the ladder diagram meet the preset standards. For example, it is possible to check whether the instruction type is correct (such as a straight line, contact instruction, coil instruction, etc.), whether the instruction content is complete and correct, and whether the coordinates and size of the graphic element on the canvas are properly set. In addition, it is also possible to check whether the logical relationship in the initial drawing data is consistent to ensure that the ladder diagram is logically correct.
[0111] If any error or non-compliance with the standard is found during the verification process, the error location will be immediately displayed in the error list interface, and the corresponding solution will be given. These error messages specify the location of the error and possible repair methods in detail, helping users to quickly locate and solve the problem.
[0112] Only when the initial drawing data passes the verification, that is, all syntax and logic checks are correct, will the subsequent steps be executed to generate intermediate ontology data based on the initial drawing data.
[0113] For example, suppose that in the initial drawing data, the user sets a ladder diagram containing multiple contacts and coils, and specifies the position and size of each primitive. In step S50, first check whether the settings of these primitives comply with the drawing rules of the ladder diagram, such as whether the contacts are correctly connected, whether the coils are placed in the appropriate position, etc. If all checks pass, the information is converted into intermediate body data to prepare for subsequent drawing work.
[0114] Further, refer to Figure 3 , Figure 3 This is a flow chart of the third embodiment of the method for drawing a PLC ladder diagram of the present application. Figure 1 In the embodiment shown, in this embodiment, step S20 may include step S60:
[0115] Step S60: normalize the intermediate ontology data.
[0116] In a feasible implementation, step S60 may include steps S61 to S62:
[0117] Step S61, compiling the intermediate ontology data into text instructions;
[0118] Specifically, in step S61, the intermediate body data is compiled into text instructions. The purpose of this step is to convert the intermediate body data, that is, the two-dimensional table structure data that records the original content of the ladder diagram (composed of LadCell structures, including information such as the row and column positions of the primitives, instruction types, instruction contents, and coordinate sizes), into a standardized text format, which is convenient for subsequent processing and verification. This text instruction is usually an intermediate representation that can clearly express the logical structure and instruction content of the ladder diagram, but does not contain specific drawing information. For example, a ladder diagram row containing contact instructions and coil instructions may be represented as "contact X" after being compiled into a text instruction. 0 , coil Y 1 "Such a form, where X 0 and Y 1 Represents the identifiers of contacts and coils respectively.
[0119] Step S62: decompile the text instructions to generate standardized intermediate ontology data.
[0120] Specifically, in step S62, these text instructions are decompiled back into standardized intermediate ontology data. This process is the reverse operation of the compilation process, and its purpose is to convert the text instructions back into a data structure that can be recognized inside the program. During the decompilation process, the text instructions will be checked to ensure that their syntax and content are correct. If errors or inconsistencies are found, the user will be prompted to make corrections. In this way, the intermediate ontology data after decompilation will be more standardized and standardized, providing a reliable data basis for the subsequent drawing process.
[0121] In addition, the present application also proposes a PLC ladder diagram drawing device, the PLC ladder diagram drawing device comprising:
[0122] A first acquisition module 10, used for initializing the ladder diagram and acquiring initial drawing data of the initial ladder diagram;
[0123] A second acquisition module 20, used to generate intermediate body data according to the initial drawing data;
[0124] A third acquisition module 30, configured to generate intermediate rendering data according to the intermediate ontology data and a preset parameter set;
[0125] The drawing module 40 is used to call a drawing function to draw a result ladder diagram according to the intermediate drawing data.
[0126] The PLC ladder diagram drawing device provided by the present application adopts the PLC ladder diagram drawing method in the above embodiment, aiming to solve the technical problems of insufficient editing flexibility and single data structure design in the ladder diagram editing module of the current PLC host computer software. Compared with the prior art, the beneficial effects of the PLC ladder diagram drawing device provided by the present application are the same as the beneficial effects of the PLC ladder diagram drawing method provided by the above embodiment, and other technical features in the PLC ladder diagram drawing device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0127] The present application provides a PLC ladder diagram drawing device, the PLC ladder diagram drawing device 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 PLC ladder diagram drawing method in the above-mentioned embodiment one.
[0128] Reference below Figure 5 , which shows a schematic diagram of the structure of a device for drawing a PLC ladder diagram for implementing an embodiment of the present application. The device for drawing a PLC ladder diagram 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 5 The PLC ladder diagram drawing device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0129] like Figure 5As shown, the drawing device of the PLC ladder diagram 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 drawing device of the PLC ladder diagram 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. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the drawing device of the PLC ladder diagram to communicate wirelessly or wired with other devices to exchange data. Although the drawing device of the PLC ladder diagram with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0130] 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.
[0131] The PLC ladder diagram drawing device provided by the present application adopts the PLC ladder diagram drawing method in the above embodiment, aiming to solve the technical problems of insufficient editing flexibility and single data structure design in the ladder diagram editing module of the current PLC host computer software. Compared with the prior art, the beneficial effects of the PLC ladder diagram drawing device provided by the present application are the same as the beneficial effects of the PLC ladder diagram drawing method provided by the above embodiment, and other technical features in the PLC ladder diagram drawing device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.
[0132] 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.
[0133] 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.
[0134] 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 method for drawing a PLC ladder diagram in the above-mentioned embodiment.
[0135] 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 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 that can be used by or in combination with an instruction execution 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.
[0136] The computer-readable storage medium may be included in the PLC ladder diagram drawing device; or may exist independently without being assembled into the PLC ladder diagram drawing device.
[0137] 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).
[0138] 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.
[0139] The modules involved in the embodiments described in the present 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.
[0140] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned method for drawing the PLC ladder diagram, and is intended to solve the technical problems that the current PLC host computer software has insufficient editing flexibility and a single data structure design in the ladder diagram editing module. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the method for drawing the PLC ladder diagram provided by the above-mentioned embodiment, and will not be repeated here.
[0141] The present application also provides a computer program product, including a computer program, which implements the steps of the method for drawing a PLC ladder diagram as described above when executed by a processor.
[0142] The computer program product provided by the present application is intended to solve the technical problems of insufficient editing flexibility and single data structure design in the ladder diagram editing module of the current PLC host computer software. 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 PLC ladder diagram drawing method provided by the above embodiment, which will not be repeated here.
[0143] Compared with the prior art, the drawing method, device, equipment, medium and computer product of the PLC ladder diagram proposed in the embodiment of the present application extracts the business characteristic information of the target business, performs data standardization processing on the business characteristic information, obtains standard characteristic data, performs hash processing on the standard characteristic data, obtains unique characteristic data, performs numerical processing and splicing processing on the unique characteristic data, obtains the first business characteristic value, accumulates the first business characteristic value of the target business, obtains the target business characteristic value, and finally compares the target business characteristic value with the characteristic value set to obtain the drawing result of the PLC ladder diagram. Compared with the traditional method of identifying repeated business by generating a unique key value or a continuous serial number for each business, it is more efficient, flexible and reliable. Based on the scheme of the present application, by subjecting the business of complex scenes to a series of simple transformations and finally converting it into a comparison of two numbers, the comparison process is very intuitive and efficient. The system only needs to simply compare whether the two values are equal to quickly determine whether the two businesses are exactly the same.
[0144] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0145] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0146] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, a controlled terminal, or a network device, etc.) to execute the method of each embodiment of the present application.
[0147] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for drawing a PLC ladder diagram, characterized in that: The method for drawing the PLC ladder diagram comprises: Initialize the ladder diagram and obtain the initial drawing data of the initial ladder diagram; Generating intermediate ontology data according to the initial drawing data; Generate intermediate rendering data according to the intermediate ontology data and a preset parameter set; The drawing function is called to draw according to the intermediate drawing data to obtain a result ladder diagram.
2. The method for drawing a PLC ladder diagram according to claim 1, characterized in that: After the step of initializing the ladder diagram and obtaining the initial drawing data of the initial ladder diagram, the following steps are further included: Perform a ladder diagram check on the initial drawing data. If the check result is correct, execute the following steps: generate intermediate body data according to the initial drawing data.
3. The method for drawing a PLC ladder diagram according to claim 1, characterized in that: The step of generating intermediate ontology data according to the initial drawing data comprises: The non-ladder diagram body data in the initial drawing data is stored separately in a global singleton; The initial drawing data is traversed, and the following operations are performed on each row of the initial drawing data: If the end of the current line is a termination symbol, the content of the current line is stored as intermediate body data; If the end of the current line is a line feed symbol, the current line and the adjacent line are merged into a single line and stored as intermediate body data.
4. The method for drawing a PLC ladder diagram according to claim 1, wherein: After the step of generating intermediate ontology data according to the initial drawing data, the following steps are further included: The intermediate ontology data is normalized.
5. The method for drawing a PLC ladder diagram according to claim 4, characterized in that: The step of normalizing the intermediate ontology data comprises: Compiling the intermediate ontology data into text instructions; The text instructions are decompiled to generate standardized intermediate ontology data.
6. The method for drawing a PLC ladder diagram according to claim 1, characterized in that: The step of generating intermediate rendering data according to the intermediate ontology data and the preset parameter set comprises: Traversing the intermediate ontology data, and performing a row processing operation on each row of the intermediate ontology data to obtain intermediate data; Obtaining drawing parameter data of a ladder diagram according to the intermediate data and the preset parameters; Traversing the intermediate data to obtain the drawing range data of the ladder diagram; Based on the drawing parameter data and the drawing range data, intermediate drawing data is generated.
7. The method for drawing a PLC ladder diagram according to claim 6, characterized in that: The step of traversing the intermediate ontology data and performing a row processing operation on each row of the intermediate ontology data to obtain the intermediate data comprises: If the length of the current line is not greater than the preset maximum length, the content of the current line is stored as intermediate drawing data; If the length of the current line is greater than the preset maximum length, the current line is split into two lines and stored as intermediate drawing data.
8. A PLC ladder diagram drawing device, characterized in that: The device comprises: A first acquisition module, used for initializing the ladder diagram and acquiring initial drawing data of the initial ladder diagram; A second acquisition module, used to generate intermediate ontology data according to the initial drawing data; A third acquisition module, used to generate intermediate rendering data according to the intermediate ontology data and a preset parameter set; The drawing module is used to call the drawing function to draw a result ladder diagram according to the intermediate drawing data.
9. A PLC 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 method for drawing a PLC ladder diagram according to any one of claims 1 to 7.
10. 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 method for drawing a PLC ladder diagram according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Devices, systems, and methods for configuring a programmable logic controller
CN101529351A
Ladder diagram compiling method, ladder diagram debugging method, electronic equipment and storage medium
CN113419723A
PLC ladder diagram editing method based on scene view structure
CN114237585A
Ladder diagram language multi-energy flow programming method and device and storage medium
CN117519677A
Ladder diagram folding display method and device and storage medium
CN117785090A