Methods, apparatus, equipment, and storage media for drawing PLC ladder diagrams

By using two sets of data structures in the PLC host computer software to store the original content of the ladder diagram and the drawing representation data respectively, the problems of insufficient editing flexibility and single data structure are solved, the flexibility and efficiency of ladder diagram editing are improved, and users are supported to flexibly adjust the drawing parameters and restore the editing status.

CN119472486BActive Publication Date: 2025-10-28SHENZHEN GUMEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411501294.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-10-28
Estimated Expiration
2044-10-25

AI Technical Summary

Technical Problem

Existing PLC host computer software suffers from insufficient editing flexibility and a simplistic data structure design in its ladder diagram editing module, resulting in low editing efficiency and difficulty in restoring the state before complex operations.

Method used

Two sets of data structures are used to store the original content and drawing representation data of the ladder diagram respectively. By initializing and generating intermediate body data and drawing data, the drawing function is called to flexibly adjust the drawing parameters and appearance of the ladder diagram.

Benefits of technology

It improves the flexibility and efficiency of ladder diagram editing, reduces data processing errors, allows users to flexibly adjust drawing parameters without changing the original content, and makes it easier to restore to the previous state.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119472486B_ABST
    Figure CN119472486B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, and storage medium for drawing ladder diagrams in a PLC. The method includes: initializing the ladder diagram and obtaining initial drawing data for the initial ladder diagram; generating intermediate body data based on the initial drawing data; generating intermediate drawing data based on the intermediate body data and a preset parameter set; and calling a drawing function to draw the ladder diagram based on the intermediate drawing data to obtain the final ladder diagram. This application distinguishes and independently stores the original content of the ladder diagram (body data) and the drawing representation data (drawing data), thus enabling flexible adjustment of its drawing parameters while maintaining the original content of the ladder diagram.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet technology, and in particular to a method, apparatus, device and storage medium for drawing PLC ladder diagrams. Background Technology

[0002] With the rapid development of industrial automation technology, PLC (Programmable Logic Controller) devices have become a core component of modern industrial control, widely used in manufacturing, energy, transportation, and other fields. The widespread application of PLC devices has promoted the development of host computer software, which provides users with intuitive and convenient ways to design, edit, and control PLC programs. Among these, ladder diagrams, as one of the most commonly used graphical programming languages ​​for PLC programming, have become a core functional module in host computer software.

[0003] However, despite significant advancements in functionality and ease of use in current PLC host computer software, challenges remain in the design of ladder diagram editing modules. Specifically, existing technologies lack sufficient flexibility in editing and modifying ladder diagrams. When users need to adjust the drawing parameters or perform complex operations, such as batch replacement of software components, the software often requires reprocessing the entire original ladder diagram data. This not only reduces editing efficiency but may also introduce errors due to improper data processing, affecting the accuracy of the ladder diagram and the stability of system operation.

[0004] Furthermore, some PLC host computer software suffers from a lack of diversity in its data structure design, employing a uniform data structure to store and manage all ladder diagram data. While this simplifies data processing, it presents challenges when dealing with scenarios requiring the undoing of complex operations. The absence of intermediate state records necessary for undoing these operations often prevents users from restoring the previous state, causing inconvenience for programming and debugging. Summary of the Invention

[0005] The main purpose of this application is to provide a method, apparatus, device and storage medium for drawing ladder diagrams for PLCs, aiming to solve the technical problems of insufficient editing flexibility and simple data structure design in the current ladder diagram editing module of PLC host computer software.

[0006] To achieve the above objectives, this application provides a method for drawing a PLC ladder diagram, which includes the following steps:

[0007] Initialize the ladder diagram and obtain the initial drawing data for the initial ladder diagram;

[0008] Based on the initial drawing data, intermediate ontology data is generated;

[0009] Intermediate rendering data is generated based on the intermediate ontology data and the preset parameter set;

[0010] The plotting function is called to draw a trapezoidal graph based on the intermediate plotting data.

[0011] In one embodiment, after the step of initializing the ladder diagram and obtaining the initial drawing data of the initial ladder diagram, the method further includes:

[0012] Perform a ladder diagram verification on the initial drawing data. If the verification result is correct, proceed to the following step: generate intermediate ontology data based on the initial drawing data.

[0013] In one embodiment, the step of generating intermediate ontology data based on the initial drawing data includes:

[0014] Store the non-trapezoidal graph ontology data in the initial drawing data separately into a global singleton;

[0015] Iterate through the initial drawing data and perform the following operations on each row of the initial drawing data:

[0016] If the end of the current line is a line terminator, then the content of the current line will be stored as intermediate ontology data;

[0017] If the current line ends with a newline character, then the current line and the adjacent lines are merged into a single line and stored as intermediate ontology data.

[0018] In one embodiment, the step of generating intermediate ontology data based on the initial drawing data further includes:

[0019] The intermediate ontology data is then standardized.

[0020] In one embodiment, the step of normalizing the intermediate ontology data includes:

[0021] Compile 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 based on the intermediate ontology data and a preset parameter set includes:

[0024] Traverse the intermediate ontology data and perform row processing operations on each row of the intermediate ontology data to obtain intermediate data;

[0025] Based on the intermediate data and the preset parameters, the drawing parameter data of the trapezoidal diagram is obtained;

[0026] By traversing the intermediate data, the drawing range data of the ladder diagram is obtained;

[0027] Intermediate drawing data is generated based on the drawing parameter data and the drawing range data.

[0028] In one embodiment, the step of traversing the intermediate ontology data and performing row processing operations on each row of the intermediate ontology data to obtain intermediate data includes:

[0029] If the length of the current line is not greater than the preset maximum length, store the content of the current line as intermediate drawing data;

[0030] If the length of the current row is greater than the preset maximum length, the current row will be split into two rows and stored as intermediate drawing data.

[0031] Furthermore, to achieve the above objectives, this application also provides a PLC ladder diagram drawing device, the PLC ladder diagram drawing device comprising:

[0032] The first acquisition module is used to initialize the ladder diagram and acquire the initial drawing data of the initial ladder diagram;

[0033] The second acquisition module is used to generate intermediate ontology data based on the initial drawing data;

[0034] The third acquisition module is used to generate intermediate drawing data based on the intermediate ontology data and the preset parameter set;

[0035] The drawing module is used to call drawing functions to draw the resulting trapezoidal diagram based on the intermediate drawing data.

[0036] In addition, to achieve the above objectives, this application also provides a terminal device, which includes a memory, a processor, and a PLC ladder diagram drawing program stored in the memory and executable on the processor. When the PLC ladder diagram drawing program is executed by the processor, it implements the steps of the PLC ladder diagram drawing method as described above.

[0037] In addition, to achieve the above objectives, this application also provides a computer-readable storage medium storing a PLC ladder diagram drawing program, which, when executed by a processor, implements the steps of the PLC ladder diagram drawing method described above.

[0038] One or more technical solutions proposed in this application have at least the following technical effects:

[0039] This 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 storing the original content, i.e., ontology data, and drawing representation data, i.e., drawing data.

[0040] Specifically, the process begins by initializing the ladder diagram and obtaining its initial drawing data. After obtaining the initial drawing data, intermediate ontology data is generated. Based on the intermediate ontology data and a preset parameter set, intermediate drawing data is then generated, and the drawing function is called to draw the ladder diagram. Through this process, users can flexibly adjust the appearance of the ladder diagram according to different drawing parameter requirements, such as the number of single-row touch points and annotation display, without having to reprocess the entire original ladder diagram data. This not only improves editing efficiency but also reduces the risk of errors introduced by improper data processing.

[0041] Compared with existing technologies, this application significantly improves the editing flexibility during ladder diagram drawing. Users can flexibly adjust drawing parameters to meet different design needs without changing the original content of the ladder diagram. Furthermore, by employing two sets of data structures to store the original content and drawing representation data of the ladder diagram separately, it is easier to restore the previous state during complex editing operations, improving the convenience of programming and debugging. Attached Figure Description

[0042] Figure 1 This is a flowchart illustrating a first exemplary embodiment of the method for drawing a PLC ladder diagram according to this application.

[0043] Figure 2 This is a flowchart illustrating a second exemplary embodiment of the method for drawing a PLC ladder diagram according to this application.

[0044] Figure 3 This is a flowchart illustrating a third exemplary embodiment of the method for drawing a PLC ladder diagram according to this application.

[0045] Figure 4 This is a schematic diagram of the module structure of the PLC ladder diagram drawing device according to an embodiment of this application;

[0046] Figure 5 This is a schematic diagram of the hardware operating environment involved in the PLC ladder diagram drawing method in this application embodiment.

[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0048] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.

[0049] The main solution of this application embodiment is as follows: 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 a 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 simple data structure design in the existing PLC ladder diagram editing module, by using two sets of data structures to store the original content of the ladder diagram and the drawing representation data respectively, and making flexible adjustment of drawing parameters and appearance modification based on these data structures, the flexibility and editing efficiency of ladder diagram drawing are significantly improved without changing the original content of the ladder diagram.

[0050] The execution subject of the method in this embodiment can be a PLC ladder diagram drawing device, or 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 into terminal devices such as smartphones and tablets with data processing functions.

[0051] Specifically, the following are detailed steps of an exemplary embodiment of the method for drawing a ladder diagram for a PLC:

[0052] Reference Figure 1 , Figure 1 This is a flowchart illustrating a first exemplary embodiment of the PLC ladder diagram drawing method of this application. In this embodiment, the PLC ladder diagram drawing method includes steps S10 to S40:

[0053] Step S10: Initialize the ladder diagram and obtain the initial drawing data of the initial ladder diagram;

[0054] It should be noted that, first, the host computer software provided by the PLC manufacturer must be launched. After the software is opened, the user will be guided 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 automatically performs a series of initialization operations to ensure the smooth progress of subsequent work. A key step is to create two sets of data structures: Ladder and LadderGraphics.

[0056] The ladder diagram is used to store the original ladder diagram content, i.e., the core data. This includes all logical elements in the ladder diagram, such as input / output points, coils, contacts, and their connections. This data structure ensures the integrity and accuracy of the ladder diagram information, providing a reliable foundation for subsequent editing, simulation, and downloading to the PLC.

[0057] LadderGraphics stores all the data needed to draw ladder diagrams, i.e., the drawing data. It contains graphical information required for drawing the ladder diagram, such as the number of contacts per row, whether declarations / annotations / software component comments are displayed, and the number of lines of software component comments. This information is used to visualize the ladder diagram implementation, allowing users to intuitively see its layout and logical structure.

[0058] Specifically, after initializing the editing environment, the software system further initializes an empty ladder diagram template. This template serves as the starting point for subsequent ladder diagram drawing by the user, and it already has some basic layout and attribute settings preset. Data related to the initial ladder diagram drawing can be read from LadderGraphics, such as the default background color, grid line spacing, and default component icons in the component library. Then, based on this data, a basic ladder diagram framework is drawn on the editing interface.

[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 framework containing 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 based on the data in LadderGraphics, and the user can directly perform further editing and expansion on this basis.

[0060] Step S20: Generate intermediate ontology data based on the initial drawing data;

[0061] In one feasible implementation, step S20 may include steps S21 to S23:

[0062] Step S21: Store the non-ladder graph ontology 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, descriptive text, or other metadata that is not directly involved in drawing the graph. 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 this non-ladder diagram ontology data is stored and accessed only once throughout the entire application or processing, avoiding data redundancy and access conflicts.

[0064] Step S22: Traverse the initial drawing data and perform the following operations on each row of the initial drawing data: If the end of the current row is an end symbol, then store the content of the current row as intermediate body data;

[0065] Specifically, the initial drawing data, i.e., the content in LadderGraphics, is traversed. This data is generated based on the drawing parameters of the ladder diagram and additional content (such as declarations, annotations, etc.), and it records in detail every piece of information required for the ladder diagram to be drawn. For each row of data during the traversal, the following judgment is made: check whether the end of the current row is an end symbol. In the representation of a ladder diagram, an end symbol usually marks the end of a complete instruction or a section of ladder diagram content. If the end of the current row is indeed an end symbol, then this row of data is directly regarded as part of the intermediate ontology data of the ladder diagram and stored. Here, the intermediate ontology 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 newline character, then merge the current line and the adjacent lines into a single line and store it as intermediate body data.

[0067] Specifically, for cases where the line ends with a newline character, upon detecting a newline character, the current line is not immediately stored as an independent intermediate ontology data item. Instead, subsequent lines closely connected to the current line are searched and merged until a new end-of-line character 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 we have initial drawing data representing a simple ladder diagram, containing two lines of data. The first line ends with a contact instruction followed by a newline character; the second line begins with a coil instruction and ends with an end symbol. When traversing this data, the first line is processed first. Since it ends with a newline character, the next line, the second line, is searched for, and these two lines are merged into a complete instruction sequence (a contact instruction followed by a coil instruction), which is then stored as intermediate body data. The second line, ending with an end symbol, concludes this complete instruction sequence after the merge.

[0069] Step S30: Generate intermediate drawing data based on the intermediate ontology data and the preset parameter set;

[0070] In one feasible implementation, step S30 may include steps S31 to S34:

[0071] Step S31: Traverse the intermediate ontology data and perform row processing operations on each row of the intermediate ontology data to obtain intermediate data;

[0072] In one 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, store the content of the current line as intermediate drawing data;

[0074] Specifically, the length of the current line is checked first. The "length of the current line" refers to the number of characters or bytes contained in that line of data, depending on the data encoding method and system definition. If the length of the current line is not greater than the preset maximum length, the content of that line is directly stored as intermediate drawing data. This is done to maintain data integrity and to ensure that this unmodified data can be directly used in subsequent graphics drawing processes.

[0075] Step S312: If the length of the current row is greater than the preset maximum length, the current row is divided into two rows and stored as intermediate drawing data.

[0076] However, if the length of the current row exceeds the preset maximum length, then step S412 is executed. Specifically, the excessively long row data is divided into two or more parts, each with a length less than or equal to the preset maximum length, and these divided parts are stored as intermediate drawing data. The purpose of this is to adapt to the display requirements of the graphical interface, ensuring that excessively long data rows do not exceed the display area, and also facilitating subsequent graphic drawing and display.

[0077] Step S32: Obtain the drawing parameter data of the trapezoidal diagram based on 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 conjunction with a preset parameter set. The preset parameters may include the size of the ladder diagram, layout specifications, color scheme, line thickness, etc.

[0079] Specifically, first, a pre-defined set of parameters is loaded, which defines the overall appearance and behavior of the ladder diagram. Then, intermediate data—row data stored in LadderGraphics—is traversed. Based on the characteristics of each row (such as length and content) and the pre-defined parameters, the specific position (such as x and y coordinates), dimensions (such as height and width), and style (such as color and line type) of each row on the ladder diagram are calculated. Based on this analysis, corresponding drawing parameter data is generated for each row, which will be directly used in subsequent drawing operations.

[0080] Assuming the preset parameters specify a ladder diagram width of 800 pixels, adaptive height, and all rows as black by default with a line thickness of 1 pixel, when parsing an intermediate data point (such as "input signal X") with a length of 20 characters, the position of this data point on the ladder diagram is calculated (e.g., x=100, y=current row cumulative height), and its dimensions (e.g., width=20 * character width units, height=row height). These parameters, along with information such as color and line thickness, are then packaged into drawing parameter data.

[0081] It should be noted that after obtaining the drawing parameters, optimization and adjustments are made to ensure the best drawing results.

[0082] Specifically, the system checks for conflicts between generated drawing parameters (such as two rows of data overlapping on a ladder diagram). If a conflict is found, the position or size of the relevant rows is automatically adjusted according to preset priorities or algorithm logic. The drawing parameters are then fine-tuned based on the complexity of the drawing and the performance characteristics of the target platform to balance drawing quality and rendering efficiency.

[0083] Step S33: Traverse the intermediate data to obtain the drawing range data of the trapezoidal diagram;

[0084] Specifically, based on the row number of the declarations and annotations, and the height of each primitive, the y-coordinate of the top of each primitive in a row is calculated. Then, each LadCell object in LadderGraphics is traversed, and the coordinates and drawing range of each primitive are calculated based on the row and column number of the object, the y-coordinate of the top of the row, and the width of each primitive. This step ensures that each element of the ladder diagram is accurately positioned on the canvas during drawing.

[0085] Step S34: Generate 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 primitives, this data can be integrated into intermediate drawing data, namely LadderGraphics. At this point, LadderGraphics contains all the information needed to draw the ladder diagram, including the type, content, coordinates, size of the primitives, and any related declarations, annotations, and soft component comments. Subsequently, this data is passed to the drawing function to generate the final ladder diagram result.

[0087] Example 1: If the preset maximum length x is 10 primitive units; there is a row in the intermediate ontology data with a content length y of 15 primitive units. This row needs to be split into two lines connected by a newline character with the same newline character number. Soft element comments are displayed in the global settings, and each soft element comment occupies 0.5 primitive units of height. A declaration precedes this row of content, occupying one line with a height of 1 primitive unit. The basic height of each row of primitives in the ladder diagram is 1 primitive unit (excluding soft element comments).

[0088] According to step S312, the original row with a length of 15 primitive units is divided into two rows. The first row has a length of 10 primitive units (the value of x). The second row has a length of 15 - 10 + 2 = 7 primitive units (the value of y + 2 - x), where +2 is to ensure that the two rows can be correctly connected by a newline character.

[0089] Calculate the y-coordinate of the top of each row of primitives: Declarations occupy 1 row and have a height of 1 primitive unit, so drawing starts from the second row. The y-coordinate of the top of the primitives in the first row is 1 (counting from 0, the first row is a declaration, occupying 1 unit). The second row immediately follows the first row below, so its top y-coordinate is 1 + 1 + 0.5 = 2.5 (the height of the first row is 1 plus the soft element comment's 0.5; if multiple comments exist, they are added together).

[0090] Calculate the coordinates and drawing area of ​​each graphic element:

[0091] Assuming the primitive width is 1 primitive unit, for each LadCell object in the first row (10 in total):

[0092] Located in row 1, with a top vertical coordinate of 1.

[0093] The horizontal axis starts from 0, and each element increases by 1 unit.

[0094] For each LadCell object in the second row (7 in total):

[0095] Located in the 2nd row, with a top vertical coordinate of 2.5.

[0096] The horizontal axis starts from 0, and each element increases by 1 unit.

[0097] Drawing results:

[0098] The first row starts at (0,1) and draws 10 primitives, ranging up to (9,1).

[0099] The second row starts at (0, 2.5) and draws 7 primitives, ranging to (6, 2.5).

[0100] Step S40: Call the drawing function to draw according to the intermediate drawing data and obtain the resulting trapezoidal diagram.

[0101] Specifically, the drawing process is prepared based on the information contained in the intermediate drawing data, such as the position, size, and type of each graphic element (e.g., line, contact instruction, coil instruction, etc.) 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 conforms to the content of the original ladder diagram and meets the drawing parameters set by the user, such as the number of contacts per row and annotation display.

[0102] Next, the system iterates through each row of the intermediate drawing data and each graphic element within that row. For each graphic element, the corresponding drawing function is called based on its type. For example, if the graphic element is a straight line, the system calls the function to draw the line, passing in the coordinates of the start and end points of the line, as well as parameters such as the line thickness; if the graphic element is a touch command, the system calls the function to draw the touch command, passing in parameters such as the touch point's position, size, shape, and command content.

[0103] During the drawing process, primitives that require display of declarations, annotations, or soft component comments are also processed. For these primitives, based on the declarations and annotations stored in the global singleton and the currently set display parameters, they are correctly drawn in the corresponding positions in the ladder diagram.

[0104] Finally, after all the elements have been drawn correctly, check and draw the left and right current buses to ensure the integrity of the ladder diagram. Current buses are an important component of the ladder diagram; they are typically located on both sides of the diagram and represent the paths of the current.

[0105] For example, suppose a user is drawing a simple ladder diagram containing a contact instruction and a coil instruction, and the user has set up display annotations. In step S40, the contact instruction and the coil instruction are first drawn, and then annotations are drawn below the contact instruction based on the annotation content stored in the global singleton. Finally, the left and right current buses are checked and drawn, thus completing the entire ladder diagram drawing process.

[0106] In summary, step S40, by calling the plotting function and drawing based on the intermediate plotting data, transforms the processed data into a visual ladder diagram. This process ensures the accuracy of the ladder diagram while also meeting the user's need for flexible setting of plotting parameters.

[0107] Furthermore, referring to Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the method for drawing PLC ladder diagrams according to this application. Based on the above... Figure 1 In the illustrated embodiment, step S10 may be followed by step S50:

[0108] Step S50: Perform a ladder diagram verification on the initial drawing data. If the verification result is correct, proceed to step: generate intermediate ontology data based on the initial drawing data.

[0109] Specifically, after the ladder diagram initialization 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 intermediate ontology data can be generated smoothly in the future.

[0110] When executing step S50, the initial drawing data is first subjected to a syntax check. This includes verifying whether the format and content of each instruction and each element in the ladder diagram conform to preset standards. For example, it can be checked whether the instruction type is correct (such as line, contact instruction, coil instruction, etc.), whether the instruction content is complete and error-free, and whether the coordinates and size of the elements on the canvas are set appropriately. In addition, it can also be checked whether the logical relationships in the initial drawing data are consistent to ensure that the ladder diagram is logically correct.

[0111] If any errors or non-compliance with standards are found during the verification process, the error location will be immediately displayed in the error list interface, along with corresponding solutions. These error messages detail the location of the error and possible fixes, helping users quickly locate and resolve the problem.

[0112] Only after the initial drawing data passes validation, meaning all syntax and logic checks are correct, will subsequent steps be executed to generate intermediate ontology data based on the initial drawing data.

[0113] For example, suppose in the initial drawing data, the user sets up a ladder diagram containing multiple contacts and coils, specifying the position and size of each element. In step S50, the settings of these elements are first checked to ensure they conform to the drawing rules of the ladder diagram, such as whether the contacts are correctly connected and whether the coils are placed in the appropriate positions. If all checks pass, this information is converted into intermediate ontology data to prepare for subsequent drawing work.

[0114] Furthermore, referring to Figure 3 , Figure 3 This is a flowchart illustrating the third embodiment of the PLC ladder diagram drawing method of this application. Based on the above... Figure 1 In the illustrated embodiment, step S20 may be followed by step S60:

[0115] Step S60: Standardize the intermediate ontology data.

[0116] In one feasible implementation, step S60 may include steps S61-S62:

[0117] Step S61: Compile the intermediate ontology data into text instructions;

[0118] Specifically, in step S61, the intermediate ontology data is compiled into text instructions. The purpose of this step is to convert the intermediate ontology data—that is, the two-dimensional table structure data (composed of LadCell structures, containing information such as the row and column positions of primitives, instruction types, instruction content, and coordinate sizes) that records the original content of the ladder diagram—into a standardized text format. This format facilitates subsequent processing and verification. These text instructions are typically an intermediate representation that clearly expresses 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, after being compiled into text instructions, might be represented as "Contact X0, Coil Y1," where X0 and Y1 represent the identifiers of the contact and coil, 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 normalized intermediate ontology data. This process is the reverse of the compilation process, aiming to convert the text instructions back into data structures that the program can recognize. During decompilation, the text instructions are validated to ensure their syntax and content are correct. If errors or inconsistencies are found, the user is prompted to make corrections. In this way, the decompiled intermediate ontology data becomes more normalized and standardized, providing a reliable data foundation for the subsequent rendering process.

[0121] Furthermore, this application also proposes a PLC ladder diagram drawing device, which includes:

[0122] The first acquisition module 10 is used to initialize the ladder diagram and acquire the initial drawing data of the initial ladder diagram;

[0123] The second acquisition module 20 is used to generate intermediate ontology data based on the initial drawing data;

[0124] The third acquisition module 30 is used to generate intermediate drawing data based on the intermediate ontology data and the preset parameter set;

[0125] The drawing module 40 is used to call the drawing function to draw the result trapezoidal diagram based on the intermediate drawing data.

[0126] The PLC ladder diagram drawing device provided in this application adopts the PLC ladder diagram drawing method in the above embodiments, aiming to solve the technical problems of insufficient editing flexibility and simple data structure design in the current PLC host computer software ladder diagram editing module. Compared with the prior art, the beneficial effects of the PLC ladder diagram drawing device provided in this application are the same as the beneficial effects of the PLC ladder diagram drawing method provided in the above embodiments, and other technical features in the PLC ladder diagram drawing device are the same as the features disclosed in the above embodiment methods, and will not be repeated here.

[0127] This application provides a PLC ladder diagram drawing device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the PLC ladder diagram drawing method in the above embodiment 1.

[0128] The following is for reference. Figure 5 This document illustrates a schematic diagram of a device for drawing PLC ladder diagrams to implement embodiments of this application. The device for drawing PLC ladder diagrams in these embodiments may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital radio receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 5 The PLC ladder diagram drawing device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.

[0129] like Figure 5As shown, the PLC ladder diagram drawing device may include a processing unit 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1002 or the program loaded from the storage device 1003 into the random access memory (RAM) 1004. The RAM 1004 also stores various programs and data required for the operation of the PLC ladder diagram drawing device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the PLC ladder diagram drawing device to communicate wirelessly or wiredly with other devices to exchange data. Although PLC ladder diagram drawing devices with various systems are 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 can be implemented alternatively.

[0130] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.

[0131] The PLC ladder diagram drawing device provided in this application adopts the PLC ladder diagram drawing method in the above embodiments, aiming to solve the technical problems of insufficient editing flexibility and simple data structure design in the current PLC host computer software in terms of ladder diagram editing module. Compared with the prior art, the beneficial effects of the PLC ladder diagram drawing device provided in this application are the same as the beneficial effects of the PLC ladder diagram drawing method provided in the above embodiments, and other technical features in the PLC ladder diagram drawing device are the same as the features disclosed in the previous embodiment method, and will not be repeated here.

[0132] It should be understood that the various parts disclosed in this application can be implemented using 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 suitable manner in one or more embodiments or examples.

[0133] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0134] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, which are used to execute the PLC ladder diagram drawing method in the above embodiments.

[0135] The computer-readable storage medium provided in this 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 thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. 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 conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0136] The aforementioned computer-readable storage medium may be included in the PLC ladder diagram drawing device; or it may exist independently and not be assembled into the PLC ladder diagram drawing device.

[0137] Computer program code for performing the operations of this application can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0138] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0139] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.

[0140] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described PLC ladder diagram drawing method. This aims to solve the technical problems of insufficient editing flexibility and simplistic data structure design in current PLC host computer software's ladder diagram editing module. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the PLC ladder diagram drawing method provided in the above embodiments, and will not be elaborated upon here.

[0141] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the PLC ladder diagram drawing method described above.

[0142] The computer program product provided in this application aims to solve the technical problems of insufficient editing flexibility and simplistic data structure design in the ladder diagram editing module of current PLC host computer software. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the PLC ladder diagram drawing method provided in the above embodiments, and will not be repeated here.

[0143] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0144] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0145] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, controlled terminal, or network device, etc.) to execute the methods of each embodiment of this application.

[0146] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for drawing a PLC ladder diagram, characterized in that, The method for drawing the PLC ladder diagram includes: Create a first data structure Ladder and a second data structure LadderGraphics. The first data structure Ladder is used to store the ontology data of the ladder diagram, which includes intermediate ontology data. The second data structure LadderGraphics is used to store the drawing data of the ladder diagram, which includes initial drawing data, intermediate drawing data, and intermediate data. Initialize the ladder diagram and obtain the initial drawing data of the initial ladder diagram; The intermediate ontology data is generated based on the initial drawing data, including: storing the non-ladder diagram ontology data in the initial drawing data separately in a global singleton; 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, then store the content of the current line as intermediate ontology data; if the end of the current line is a newline symbol, then merge the current line with the adjacent lines into a single line and store it as intermediate ontology data. Generating intermediate drawing data based on the intermediate ontology data and a preset parameter set includes: traversing the intermediate ontology data and performing row processing operations on each row of the intermediate ontology data to obtain the intermediate data; obtaining drawing parameter data of the trapezoidal diagram based on the intermediate data and the preset parameters; traversing the intermediate data to obtain drawing range data of the trapezoidal diagram; and generating the intermediate drawing data based on the drawing parameter data and the drawing range data. The plotting function is called to draw a trapezoidal graph based on the intermediate plotting data.

2. The method for drawing a PLC ladder diagram as described in claim 1, characterized in that, The steps of initializing the ladder diagram and obtaining the initial drawing data of the initial ladder diagram further include: Perform a ladder diagram verification on the initial drawing data. If the verification result is correct, proceed to the following step: generate intermediate ontology data based on the initial drawing data.

3. The method for drawing a PLC ladder diagram as described in claim 1, characterized in that, The step of generating intermediate ontology data based on the initial drawing data further includes: The intermediate ontology data is then standardized.

4. The method for drawing a PLC ladder diagram as described in claim 3, characterized in that, The step of normalizing the intermediate ontology data includes: Compile the intermediate ontology data into text instructions; The text instructions are decompiled to generate standardized intermediate ontology data.

5. The method for drawing a PLC ladder diagram as described in claim 1, characterized in that, The step of traversing the intermediate ontology data and performing row processing operations on each row of the intermediate ontology data to obtain intermediate data includes: If the length of the current line is not greater than the preset maximum length, store the content of the current line as intermediate drawing data; If the length of the current row is greater than the preset maximum length, the current row will be split into two rows and stored as intermediate drawing data.

6. A PLC ladder diagram drawing device, characterized in that, The device includes: A creation module is used to create a first data structure Ladder and a second data structure LadderGraphics. The first data structure Ladder is used to store the ontology data of the ladder diagram, which includes intermediate ontology data. The second data structure LadderGraphics is used to store the drawing data of the ladder diagram, which includes initial drawing data, intermediate drawing data, and intermediate data. The first acquisition module is used to initialize the ladder diagram and acquire the initial drawing data of the initial ladder diagram; The second acquisition module is used to generate the intermediate ontology data based on the initial drawing data, including: storing the non-ladder diagram ontology data in the initial drawing data separately in a global singleton; 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, then storing the content of the current line as intermediate ontology data; if the end of the current line is a newline symbol, then merging the current line with the adjacent lines into a single line and storing it as intermediate ontology data; The third acquisition module is used to generate the intermediate drawing data based on the intermediate ontology data and the preset parameter set, including: traversing the intermediate ontology data and performing row processing operations on each row of the intermediate ontology data to obtain the intermediate data; obtaining the drawing parameter data of the trapezoidal diagram based on the intermediate data and the preset parameters; traversing the intermediate data to obtain the drawing range data of the trapezoidal diagram; and generating the intermediate drawing data based on the drawing parameter data and the drawing range data. The drawing module is used to call drawing functions to draw the resulting trapezoidal diagram based on the intermediate drawing data.

7. A PLC ladder diagram drawing device, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the method for drawing a PLC ladder diagram as described in any one of claims 1 to 5.

8. 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, it implements the steps of the PLC ladder diagram drawing method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Ladder diagram folding display method and device and storage medium

    CN117785090A