Ladder diagram to instruction list conversion method, device, and host computer for programmable logic controller.

By dividing the ladder diagram into input and output regions and converting it into a directed graph and a binary tree to generate an instruction table, the problem of inaccurate parsing of multi-input function instructions in the prior art is solved, and the correct conversion from ladder diagram to instruction table is realized.

CN123113646APending Publication Date: 2026-11-17GREE ELECTRIC APPLIANCE INC OF ZHUHAI
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611121702.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-27
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

When processing multi-input function instructions, the existing ladder diagram to instruction table method cannot effectively distinguish the input signals of each branch, resulting in incorrect conversion results or conversion failure.

Method used

The single-output ladder diagram is divided into at least one input region and one output region, which are then converted into directed graphs and binary trees to finally generate an instruction table.

Benefits of technology

It effectively solves the problem of parsing multi-input function commands that cannot be handled in existing technologies, ensuring the accuracy and success of the conversion results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123113646A_ABST
    Figure CN123113646A_ABST
Patent Text Reader

Abstract

This application provides a ladder diagram to instruction list conversion method, apparatus, and host computer for a programmable logic controller. The method includes: acquiring a single-output ladder diagram, the ladder diagram including multi-input function instructions or single-input function instructions; dividing the single-output ladder diagram into at least one input region and one output region, where one input region corresponds to one input of a multi-input function instruction or a single-input function instruction, and the output region corresponds to the input of a multi-input function instruction or a single-input function instruction; converting the input region and the output region into directed graphs respectively to obtain multiple target directed graphs; converting the multiple target directed graphs into binary trees to obtain multiple target binary trees; and generating an instruction list based on the multiple target binary trees. This solves the problem in the prior art that the ladder diagram to instruction list conversion method does not support the parsing of multi-input function instructions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of industrial control, and more specifically, to a ladder diagram to instruction list method, apparatus, computer-readable storage medium, computer program product, and host computer for a programmable logic controller. Background Technology

[0002] Programmable Logic Controllers (PLCs) are core control devices in industrial automation. Among PLC programming languages, ladder diagrams are the most widely used in engineering applications due to their intuitive logic and high similarity to relay control schematics; while instruction lists are closer to the machine's underlying structure and are suitable for CPU parsing and execution. Therefore, efficiently and accurately converting ladder diagrams into instruction lists is an indispensable core function of PLC host computer compilation software.

[0003] Existing ladder diagram to instruction list conversion technologies are relatively mature in handling networks containing only basic components (such as contacts or single coils) and single-input function instructions. However, when faced with the "multi-input function instructions" widely used in modern PLC programming, publicly available technologies generally suffer from the problem that the intermediate data structure (single tree or single graph) fails to effectively distinguish the ownership of multiple input branches. Due to the lack of a scientific region partitioning and logical mapping mechanism, existing methods often lead to logically disordered instruction sequences or even conversion failures when parsing such ladder diagrams. Therefore, the industry urgently needs a new ladder diagram to instruction list conversion method that can be compatible with complex networks and perfectly support the parsing of multi-input function instructions. Summary of the Invention

[0004] The main objective of this application is to provide a ladder diagram to instruction list conversion method, apparatus, computer-readable storage medium, computer program product, and host computer for a programmable logic controller, so as to at least solve the problem that the existing ladder diagram to instruction list conversion method does not support the parsing of multi-input function instructions.

[0005] To achieve the above objectives, according to one aspect of this application, a method for converting a ladder diagram to an instruction list is provided, comprising: obtaining a single-output ladder diagram, the single-output ladder diagram including a multi-input function instruction or a single-input function instruction; dividing the single-output ladder diagram into at least one input region and an output region, one input region corresponding to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponding to the input of the multi-input function instruction or the single-input function instruction; converting the input region and the output region into directed graphs respectively to obtain multiple target directed graphs; converting the multiple target directed graphs into binary trees to obtain multiple target binary trees; and generating an instruction list based on the multiple target binary trees.

[0006] Optionally, obtaining a single-output ladder diagram includes: obtaining an initial ladder diagram; splitting the initial ladder diagram according to the ladder level to obtain at least one single-output ladder diagram, wherein the single-output ladder diagram corresponds one-to-one with the output of the initial ladder diagram.

[0007] Optionally, dividing the single-output ladder diagram into at least one input region and one output region includes: when the ladder diagram includes the multi-input function instruction, dividing the region that generates each input of the multi-input function instruction into an independent region to obtain multiple input regions, and dividing the region that generates the output of the multi-input function instruction into an independent region to obtain one output region; when the ladder diagram includes the single-input function instruction, dividing the region that generates the input of the single-input function instruction into an independent region to obtain one input region, and dividing the region that generates the output of the single-input function instruction into an independent region to obtain one output region.

[0008] Optionally, the input region and the output region are converted into directed graphs to obtain multiple target directed graphs, including: mapping the logical elements of the input region and the output region to physical nodes, and mapping the intersection points of the routes between the logical elements of the input region and the output region to virtual nodes; storing the directed graph using a cross-linked list, the cross-linked list including vertex nodes and arc nodes, each vertex node recording element information and in-degree, out-degree, first in-arc and out-arc pointers, each arc node recording arc head, arc tail index, and same-head or same-tail arc pointers; determining the energy flow direction of the signal according to the cross-linked list, and establishing directed edges on the physical nodes and the virtual nodes according to the energy flow direction of the signal to generate multiple target directed graphs.

[0009] Optionally, the multiple target directed graphs are converted into binary trees to obtain multiple target binary trees, including: removing the virtual nodes in the directed graphs whose out-degree and in-degree are both 1; a first merging step, merging two serially connected first nodes into one serial node, where one first node has an out-degree of 1 and the other first node has an in-degree of 1; a second merging step, merging two parallelly connected second nodes into one parallel node, where one second node has an out-degree of 1 and the other second node has an out-degree of 1 and an in-degree of 1; repeating the first merging step and the second merging step at least once until there is only one root node in the directed graph, thus obtaining the target binary tree corresponding to the target directed graph.

[0010] Optionally, generating an instruction table based on multiple target binary trees includes: generating corresponding instructions based on the node types and relationships of all the target directed graphs to obtain the instruction table. The instructions include instructions for leaf nodes, instructions for the serial nodes, and instructions for the parallel nodes. The leaf nodes are nodes other than the serial nodes and the parallel nodes.

[0011] According to another aspect of this application, a ladder diagram to instruction list conversion device is provided, comprising: an acquisition unit for acquiring a single-output ladder diagram, the single-output ladder diagram including a multi-input function instruction or a single-input function instruction; a partitioning unit for partitioning the single-output ladder diagram into at least one input region and an output region, one input region corresponding to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponding to the input of the multi-input function instruction or the single-input function instruction; a first conversion unit for converting the input region and the output region into directed graphs respectively to obtain multiple target directed graphs; a second conversion unit for converting the multiple target directed graphs into binary trees to obtain multiple target binary trees; and a generation unit for generating an instruction list based on the multiple target binary trees.

[0012] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform any of the methods described.

[0013] According to another aspect of this application, a computer program product is provided, comprising a computer program that, when executed by a processor, implements any of the methods described.

[0014] According to another aspect of this application, a host computer for a programmable logic controller is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for performing any one of the methods described.

[0015] Applying the technical solution of this application, the above-mentioned ladder diagram to instruction list method divides the single-output ladder diagram into at least one input region and one output region. Then, the input region and the output region are converted into directed graphs, and then into binary trees, finally generating an instruction list. Since the input region corresponds to one input and the output region corresponds to one output, it overcomes the problem that when processing multi-input function instructions, the inability to effectively distinguish the input signals of each branch often leads to incorrect conversion results or conversion process failure. It also solves the problem that existing ladder diagram to instruction list methods do not support the parsing of multi-input function instructions. Attached Figure Description

[0016] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0017] Figure 1 A hardware structure block diagram of a mobile terminal performing a ladder diagram to instruction list method according to an embodiment of this application is shown.

[0018] Figure 2 A flowchart illustrating a ladder diagram to instruction list method according to an embodiment of this application is shown.

[0019] Figure 3 A schematic diagram of a ladder diagram including multiple rungs is shown according to an embodiment of this application;

[0020] Figure 4 A ladder diagram including multiple input function instructions is shown according to an embodiment of this application;

[0021] Figure 5 A schematic diagram of a trapezoidal region division according to an embodiment of this application is shown;

[0022] Figure 6 The result of a five-region directed graph corresponding to a trapezoidal graph provided according to an embodiment of this application is shown;

[0023] Figure 7 A flowchart illustrating the conversion of a directed graph corresponding to region 1 into a binary tree according to an embodiment of this application is shown;

[0024] Figure 8 The diagram illustrates the result of converting a directed graph corresponding to five regions into a binary tree according to an embodiment of this application;

[0025] Figure 9 The illustration shows a result of setting up an instruction table in a binary tree according to an embodiment of this application;

[0026] Figure 10 The result of generating an instruction table for a subsequent traversal of five binary trees according to an embodiment of this application is shown;

[0027] Figure 11 A structural block diagram of a ladder diagram to instruction list device according to an embodiment of this application is shown.

[0028] The above figures include the following reference numerals:

[0029] 102. Processor; 104. Memory; 106. Transmission device; 108. Input / output device. Detailed Implementation

[0030] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0031] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0033] As described in the background section, existing ladder diagram to instruction list conversion methods do not support the parsing of multi-input function instructions. To solve this problem, embodiments of this application provide a ladder diagram to instruction list conversion method, apparatus, computer-readable storage medium, computer program product, and host computer for a programmable logic controller.

[0034] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention.

[0035] The methods and embodiments provided in this application can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, Figure 1 This is a hardware structure block diagram of a mobile terminal using a ladder diagram to instruction list method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. The mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0036] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the ladder diagram to instruction list method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the aforementioned networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the aforementioned networks may include wireless networks provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0037] This embodiment provides a ladder diagram to instruction list conversion method running on a mobile terminal, computer terminal or similar computing device. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Also, although the logical order is shown in the flowchart, in some cases the steps shown or described can be executed in a different order than that shown here.

[0038] Figure 2 This is a flowchart of a ladder diagram to instruction list conversion method according to an embodiment of this application. Figure 2 As shown, the method includes the following steps:

[0039] Step S201: Obtain a single-output ladder diagram, which includes multi-input function instructions or single-input function instructions.

[0040] Specifically, the ladder diagram to instruction list conversion method supports not only single-input function instruction parsing but also multi-input function instructions.

[0041] Step S202: Divide the single-output ladder diagram into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0042] Specifically, the ladder diagram is scanned, and the inputs and outputs of multi-input or single-input function instructions in the ladder diagram are divided into different areas.

[0043] Step S203: Convert the above input region and the above output region into directed graphs respectively to obtain multiple target directed graphs;

[0044] Specifically, each region is independently converted into a directed graph, with one input region corresponding to one target directed graph and one output region corresponding to one target directed graph.

[0045] Step S204: Convert the multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0046] Specifically, the directed graph is traversed and converted into a binary tree, with one target directed graph corresponding to one target binary tree.

[0047] Step S205: Generate an instruction table based on the multiple target binary trees mentioned above.

[0048] Specifically, traverse all binary trees to generate an instruction table.

[0049] In this embodiment, the ladder diagram to instruction list conversion method divides the single-output ladder diagram into at least one input region and one output region. Then, the input region and the output region are converted into directed graphs, then into binary trees, and finally an instruction list is generated. Since the input region corresponds to one input and the output region corresponds to one output, the problem of incorrect conversion results or conversion failure often occurs when processing multi-input function instructions due to the inability to effectively distinguish the input signals of each branch. This solves the problem that existing ladder diagram to instruction list conversion methods do not support the parsing of multi-input function instructions.

[0050] To simplify the conversion method, in an optional implementation, step S201 includes:

[0051] Step S2011: Obtain the initial ladder diagram;

[0052] Step S2012: The initial ladder diagram is split according to the ladder level to obtain at least one single-output ladder diagram, and the single-output ladder diagram corresponds one-to-one with the output of the initial ladder diagram.

[0053] In the above embodiments, such as Figure 3 As shown, the initial ladder diagram includes multiple rungs. Since each rung is relatively independent, the initial ladder diagram is split according to the rungs to obtain at least one single-output ladder diagram. This ensures that the output of the single-output ladder diagram corresponds one-to-one with the output of the initial ladder diagram. The single-output ladder diagram of each rung is converted to the instruction table independently, simplifying the conversion.

[0054] To avoid the inability to effectively distinguish the input signals of each branch, in an optional implementation, step S202 above includes:

[0055] Step S2021: When the ladder diagram includes the multi-input function instruction, the region that generates each input of the multi-input function instruction is divided into an independent region to obtain multiple input regions, and the region that generates the output of the multi-input function instruction is divided into an independent region to obtain one output region.

[0056] Step S2022: In the case that the ladder diagram includes the single-input function instruction, the region that generates the input of the single-input function instruction is divided into an independent region to obtain an input region, and the region that generates the output of the single-input function instruction is divided into an independent region to obtain an output region.

[0057] In the above implementation, the ladder diagram is scanned to check its syntax validity, ensuring that components are not open-circuited or short-circuited, that each ladder rung contains only one function instruction block, and that parameter inputs are complete. If the check fails, a compilation error is thrown. Based on the input / output port characteristics of the function instruction, the ladder rung network is divided into several independent regions. Specifically, with the function instruction block as the center, the left-side control logic network corresponding to each Boolean input pin is divided into an independent "input region," and the right-side logic network corresponding to each Boolean output pin is divided into an independent "output region." For example... Figure 4 As shown, the CTR instruction contains four Boolean inputs (ACT, CNO, UPDOWN, RST) and one Boolean output. The algorithm divides the ladder diagram into five independent regions based on these regions: regions 1-4 are the input ladder diagram, and region 5 is the output ladder diagram, as shown below. Figure 5 As shown.

[0058] In an optional implementation, to transform a directed graph, step S203 above includes:

[0059] Step S2031: Map the logic elements of the input region and the output region to physical nodes, and map the intersection points of the routes between the logic elements of the input region and the output region to virtual nodes.

[0060] Step S2032: A cross-linked list is used to store the directed graph. The cross-linked list includes vertex nodes and arc nodes. Each vertex node records element information and in-degree, out-degree, the first in-arc and out-arc pointers. Each arc node records the arc head and arc tail numbers and the same-head or same-tail arc pointers.

[0061] Step S2033: Determine the energy flow direction of the signal according to the above cross-linked list, and establish directed edges on the above physical nodes and the above virtual nodes according to the energy flow direction of the signal to generate multiple above-mentioned directed target graphs.

[0062] In the above implementation, for each divided region, a unique "physical node" is created for its logic elements (normally open / normally closed contacts, coils, etc.); and "virtual nodes" are created for the intersection points of lines between elements. A cross-linked list data structure is used to store the directed graph. Each vertex node records element information and its in-degree, out-degree, first in-arc, and out-arc pointers; each arc node records the arc head, arc tail number, and same-head / same-tail arc pointers. This structure can greatly optimize the efficiency of querying in-degree and out-degree in subsequent steps. Based on the energy flow direction of the signals in the ladder diagram (from left to right, from top to bottom), directed edges are established between nodes to complete the construction of the directed graph for each region, such as... Figure 6 The diagram shows the generation of 5 directed graphs.

[0063] To simplify the graph structure, in an optional implementation, step S204 above includes:

[0064] Step S2041: Remove the virtual nodes in the directed graph whose out-degree and in-degree are both 1.

[0065] Step S2042, the first merging step, merges the two first nodes connected in series into one serial node, with the out-degree of one of the first nodes being 1 and the in-degree of the other first node being 1.

[0066] Step S2043, the second merging step, merges the two parallel-connected second nodes into one parallel node, where the out-degree and in-degree of one of the second nodes are both 1, and the out-degree and in-degree of the other second node are both 1.

[0067] Step S2044: Repeat the first merging step and the second merging step at least once until there is only one root node in the directed graph, and obtain the target binary tree corresponding to the target directed graph.

[0068] In the above implementation, redundant virtual nodes are first identified and removed. Redundant virtual nodes typically refer to virtual nodes with both in-degree and out-degree of 1. During removal, their unique incoming edge predecessor node is directly connected to their unique outgoing edge successor node. Serial merging: Identify serial structures in the graph. A serial structure is characterized by two nodes (which can be entity nodes or merged subtree nodes) connected sequentially, with the out-degree of the previous node and the in-degree of the next node both being 1. These two serial nodes are merged into a new node of type "serial," with the original node (or subtree root node) serving as its left and right subtrees. Parallel merging: Identify parallel structures in the graph. A parallel structure is characterized by two nodes with both out-degree and in-degree of 1 and sharing a common predecessor and successor. These two nodes are merged into a new node of type "parallel," with the original node (or subtree root node) serving as its left and right subtrees. Repeat the above steps, continuously merging the identified serial and parallel structures into corresponding binary tree nodes, until the entire directed graph is reduced to a single root node, which represents the binary tree structure of the current region's ladder diagram logic. During this process, if an iteration fails to reduce the number of nodes in the graph, an error message indicating a logical topology anomaly will be displayed. Figure 5 The merging process of region 1 in the trapezoidal diagram is as follows: Figure 7 As shown, the above steps were executed four times in this example, and finally the directed graph had only one real node left and the corresponding binary tree was generated. Figure 8 This trapezoid is shown Figure 5 The result of converting a directed graph into a binary tree.

[0069] In an optional implementation, to generate the instruction table, step S205 above includes:

[0070] Step S2051: Generate corresponding instructions based on the node types and relationships of all the above-mentioned target directed graphs to obtain the above-mentioned instruction table. The above-mentioned instructions include instructions for leaf nodes, instructions for the above-mentioned serial nodes, and instructions for the above-mentioned parallel nodes. The above-mentioned leaf nodes are nodes other than the above-mentioned serial nodes and the above-mentioned parallel nodes.

[0071] In the above implementation, corresponding instructions are generated based on node type and relationship: Leaf nodes: Represent basic logic elements in the ladder diagram (such as contacts, coils, and function blocks). Basic instructions are generated based on element type and state, such as LD, LDI, OUT, OUTI, CTR, etc. Series nodes: For the left child node, its corresponding basic instructions are generated, such as LD and LDI. For the right child node, its basic instructions are converted into series connection instructions. For example, LD is converted to AND, LDI to ANI, and series-parallel child nodes are converted to ANB. Parallel nodes: For the left child node, its corresponding basic instructions are generated, such as LD and LDI. For the right child node, its basic instructions are converted into parallel connection instructions. For example, LD is converted to OR, LDI to ORI, and series-parallel child nodes are converted to ORB. Then, each node of the binary tree is accessed recursively. When a node is accessed, the node information is set according to the rules shown in 1. Example binary tree generated according to rule 1 is as follows: Figure 9 As shown. The post-order traversal method is used to traverse all binary trees, and the result of the post-order traversal is the order in which the instruction list statements are generated. Figure 10 exhibit Figure 9 The instruction list generated by the post-order traversal of the binary tree in the example is exactly the instruction list program corresponding to the example ladder diagram.

[0072] This application also provides a ladder diagram to instruction list conversion device. It should be noted that the ladder diagram to instruction list conversion device of this application can be used to execute the ladder diagram to instruction list conversion method provided in this application. This device is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0073] The ladder diagram to instruction list device provided in the embodiments of this application will be described below.

[0074] Figure 11 This is a schematic diagram of a ladder diagram to instruction list device according to an embodiment of this application. Figure 11 As shown, the device includes:

[0075] Acquisition unit 10 is used to acquire a single-output ladder diagram, wherein the single-output ladder diagram includes multi-input function instructions or single-input function instructions;

[0076] Specifically, the ladder diagram to instruction list conversion method supports not only single-input function instruction parsing but also multi-input function instructions.

[0077] The partitioning unit 20 is used to divide the single-output ladder diagram into at least one input region and one output region. One of the input regions corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0078] Specifically, the ladder diagram is scanned, and the inputs and outputs of multi-input or single-input function instructions in the ladder diagram are divided into different areas.

[0079] The first conversion unit 30 is used to convert the above-mentioned input region and the above-mentioned output region into directed graphs respectively, to obtain multiple target directed graphs;

[0080] Specifically, each region is independently converted into a directed graph, with one input region corresponding to one target directed graph and one output region corresponding to one target directed graph.

[0081] The second conversion unit 40 is used to convert multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0082] Specifically, the directed graph is traversed and converted into a binary tree, with one target directed graph corresponding to one target binary tree.

[0083] The generation unit 50 is used to generate an instruction table based on multiple target binary trees mentioned above.

[0084] Specifically, traverse all binary trees to generate an instruction table.

[0085] In this embodiment, the ladder diagram to instruction table conversion device divides a single-output ladder diagram into at least one input region and one output region. Then, the input region and the output region are converted into directed graphs, then into binary trees, and finally an instruction table is generated. Since each input region corresponds to one input and each output region corresponds to one output, the problem of incorrect conversion results or conversion failure often occurs when processing multi-input function instructions due to the inability to effectively distinguish the input signals of each branch. This solves the problem that existing ladder diagram to instruction table conversion methods do not support the parsing of multi-input function instructions.

[0086] To simplify the conversion method, in one optional implementation, the acquisition unit includes:

[0087] The acquisition module is used to obtain the initial ladder diagram;

[0088] The splitting module is used to split the initial ladder diagram according to the ladder level to obtain at least one of the single-output ladder diagrams, and the single-output ladder diagrams correspond one-to-one with the outputs of the initial ladder diagram.

[0089] In the above embodiments, such as Figure 3As shown, the initial ladder diagram includes multiple rungs. Since each rung is relatively independent, the initial ladder diagram is split according to the rungs to obtain at least one single-output ladder diagram. This ensures that the output of the single-output ladder diagram corresponds one-to-one with the output of the initial ladder diagram. The single-output ladder diagram of each rung is converted to the instruction table independently, simplifying the conversion.

[0090] To avoid the inability to effectively distinguish the input signals of each branch, in one optional implementation, the above-mentioned division unit includes:

[0091] The first partitioning module is used to partition the region of each input that generates the multi-input function instruction into an independent region when the ladder diagram includes the multi-input function instruction, to obtain multiple input regions, and to partition the region of the output that generates the multi-input function instruction into an independent region, to obtain one output region.

[0092] The second partitioning module is used to partition the region that generates the input of the single-input function instruction into an independent region to obtain an input region, and to partition the region that generates the output of the single-input function instruction into an independent region to obtain an output region, when the ladder diagram includes the single-input function instruction.

[0093] In the above implementation, the ladder diagram is scanned to check its syntax validity, ensuring that components are not open-circuited or short-circuited, that each ladder rung contains only one function instruction block, and that parameter inputs are complete. If the check fails, a compilation error is thrown. Based on the input / output port characteristics of the function instruction, the ladder rung network is divided into several independent regions. Specifically, with the function instruction block as the center, the left-side control logic network corresponding to each Boolean input pin is divided into an independent "input region," and the right-side logic network corresponding to each Boolean output pin is divided into an independent "output region." For example... Figure 4 As shown, the CTR instruction contains four Boolean inputs (ACT, CNO, UPDOWN, RST) and one Boolean output. The algorithm divides the ladder diagram into five independent regions based on these regions: regions 1-4 are the input ladder diagram, and region 5 is the output ladder diagram, as shown below. Figure 5 As shown.

[0094] In one optional implementation, for transforming a directed graph, the first transformation unit includes:

[0095] The mapping module is used to map the logical elements of the above-mentioned input area and the above-mentioned output area as physical nodes, and to map the intersection points of the routes between the logical elements of the above-mentioned input area and the above-mentioned output area as virtual nodes.

[0096] The storage module is used to store a directed graph using a cross-linked list. The cross-linked list includes vertex nodes and arc nodes. Each vertex node records element information and in-degree, out-degree, the first in-arc and out-arc pointers. Each arc node records the arc head and arc tail numbers and the same-head or same-tail arc pointers.

[0097] The first generation module is used to determine the energy flow direction of the signal based on the cross-linked list, establish directed edges on the physical nodes and the virtual nodes according to the energy flow direction of the signal, and generate multiple directed graphs of the target.

[0098] In the above implementation, for each divided region, a unique "physical node" is created for its logic elements (normally open / normally closed contacts, coils, etc.); and "virtual nodes" are created for the intersection points of lines between elements. A cross-linked list data structure is used to store the directed graph. Each vertex node records element information and its in-degree, out-degree, first in-arc, and out-arc pointers; each arc node records the arc head, arc tail number, and same-head / same-tail arc pointers. This structure can greatly optimize the efficiency of querying in-degree and out-degree in subsequent steps. Based on the energy flow direction of the signals in the ladder diagram (from left to right, from top to bottom), directed edges are established between nodes to complete the construction of the directed graph for each region, such as... Figure 6 The diagram shows the generation of 5 directed graphs.

[0099] To simplify the graph structure, in one optional implementation, the second conversion unit includes:

[0100] The removal module is used to remove the virtual nodes in the directed graph where both the out-degree and in-degree are 1.

[0101] The first merging module is used to perform the first merging step, merging two serially connected first nodes into one serial node, where the out-degree of one of the first nodes is 1 and the in-degree of the other first node is 1.

[0102] The second merging module is used to perform the second merging step, merging two parallel-connected second nodes into one parallel node, wherein the out-degree and in-degree of one of the aforementioned second nodes are both 1, and the out-degree and in-degree of the other aforementioned second node are both 1.

[0103] The repeat module is used to perform the first merging step and the second merging step described above at least once, until there is only one root node in the directed graph, thus obtaining the target binary tree corresponding to the target directed graph.

[0104] In the above implementation, redundant virtual nodes are first identified and removed. Redundant virtual nodes typically refer to virtual nodes with both in-degree and out-degree of 1. During removal, their unique incoming edge predecessor node is directly connected to their unique outgoing edge successor node. Serial merging: Identify serial structures in the graph. A serial structure is characterized by two nodes (which can be entity nodes or merged subtree nodes) connected sequentially, with the out-degree of the previous node and the in-degree of the next node both being 1. These two serial nodes are merged into a new node of type "serial," with the original node (or subtree root node) serving as its left and right subtrees. Parallel merging: Identify parallel structures in the graph. A parallel structure is characterized by two nodes with both out-degree and in-degree of 1 and sharing a common predecessor and successor. These two nodes are merged into a new node of type "parallel," with the original node (or subtree root node) serving as its left and right subtrees. Repeat the above steps, continuously merging the identified serial and parallel structures into corresponding binary tree nodes, until the entire directed graph is reduced to a single root node, which represents the binary tree structure of the current region's ladder diagram logic. During this process, if an iteration fails to reduce the number of nodes in the graph, an error message indicating a logical topology anomaly will be displayed. Figure 5 The merging process of region 1 in the trapezoidal diagram is as follows: Figure 7 As shown, the above steps were executed four times in this example, and finally the directed graph had only one real node left and the corresponding binary tree was generated. Figure 8 This trapezoid is shown Figure 5 The result of converting a directed graph into a binary tree.

[0105] In one optional implementation, the generation unit for generating the instruction list includes:

[0106] The second generation module is used to generate corresponding instructions based on the node types and relationships of all the above-mentioned target directed graphs, and obtain the above-mentioned instruction table. The above-mentioned instructions include instructions for leaf nodes, instructions for the above-mentioned serial nodes, and instructions for the above-mentioned parallel nodes. The above-mentioned leaf nodes are nodes other than the above-mentioned serial nodes and the above-mentioned parallel nodes.

[0107] In the above implementation, corresponding instructions are generated based on node type and relationship: Leaf nodes: Represent basic logic elements in the ladder diagram (such as contacts, coils, and function blocks). Basic instructions are generated based on element type and state, such as LD, LDI, OUT, OUTI, CTR, etc. Series nodes: For the left child node, its corresponding basic instructions are generated, such as LD and LDI. For the right child node, its basic instructions are converted into series connection instructions. For example, LD is converted to AND, LDI to ANI, and series-parallel child nodes are converted to ANB. Parallel nodes: For the left child node, its corresponding basic instructions are generated, such as LD and LDI. For the right child node, its basic instructions are converted into parallel connection instructions. For example, LD is converted to OR, LDI to ORI, and series-parallel child nodes are converted to ORB. Then, each node of the binary tree is accessed recursively. When a node is accessed, the node information is set according to the rules shown in 1. Example binary tree generated according to rule 1 is as follows: Figure 9 As shown. The post-order traversal method is used to traverse all binary trees, and the result of the post-order traversal is the order in which the instruction list statements are generated. Figure 10 exhibit Figure 9 The instruction list generated by the post-order traversal of the binary tree in the example is exactly the instruction list program corresponding to the example ladder diagram.

[0108] The aforementioned ladder diagram to instruction table conversion device includes a processor and a memory. The aforementioned acquisition unit, partitioning unit, first conversion unit, second conversion unit, and generation unit are all stored as program units in the memory. The processor executes these program units stored in the memory to achieve the corresponding functions. All of the aforementioned modules are located in the same processor; alternatively, the aforementioned modules may be located in different processors in any combination.

[0109] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the issue that existing ladder diagram-to-instruction-tablet methods do not support the parsing of multi-input function instructions.

[0110] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0111] This invention provides a computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the ladder diagram to instruction table method.

[0112] Specifically, the methods for converting ladder diagrams to instruction lists include:

[0113] Step S201: Obtain a single-output ladder diagram, which includes multi-input function instructions or single-input function instructions.

[0114] Step S202: Divide the single-output ladder diagram into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0115] Step S203: Convert the above input region and the above output region into directed graphs respectively to obtain multiple target directed graphs;

[0116] Step S204: Convert the multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0117] Step S205: Generate an instruction table based on the multiple target binary trees mentioned above.

[0118] This invention provides a processor for running a program, wherein the program executes the ladder diagram to instruction table method during runtime.

[0119] Specifically, the methods for converting ladder diagrams to instruction lists include:

[0120] Step S201: Obtain a single-output ladder diagram, which includes multi-input function instructions or single-input function instructions.

[0121] Step S202: Divide the single-output ladder diagram into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0122] Step S203: Convert the above input region and the above output region into directed graphs respectively to obtain multiple target directed graphs;

[0123] Step S204: Convert the multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0124] Step S205: Generate an instruction table based on the multiple target binary trees mentioned above.

[0125] This invention provides a host computer for a programmable logic controller, including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:

[0126] Step S201: Obtain a single-output ladder diagram, which includes multi-input function instructions or single-input function instructions.

[0127] Step S202: Divide the single-output ladder diagram into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0128] Step S203: Convert the above input region and the above output region into directed graphs respectively to obtain multiple target directed graphs;

[0129] Step S204: Convert the multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0130] Step S205: Generate an instruction table based on the multiple target binary trees mentioned above.

[0131] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:

[0132] Step S201: Obtain a single-output ladder diagram, which includes multi-input function instructions or single-input function instructions.

[0133] Step S202: Divide the single-output ladder diagram into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction.

[0134] Step S203: Convert the above input region and the above output region into directed graphs respectively to obtain multiple target directed graphs;

[0135] Step S204: Convert the multiple target directed graphs into binary trees to obtain multiple target binary trees;

[0136] Step S205: Generate an instruction table based on the multiple target binary trees mentioned above.

[0137] It is obvious to those skilled in the art that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. They can be implemented using computer-executable program code, and thus can be stored in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those described herein, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.

[0138] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0139] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0140] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0141] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0142] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0143] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0144] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0145] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0146] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. 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 apparatus that includes that element.

[0147] As can be seen from the above description, the embodiments of this application achieve the following technical effects:

[0148] 1) In the ladder diagram to instruction list method of this application, a single-output ladder diagram is divided into at least one input region and one output region. Then, the input region and the output region are converted into directed graphs, and then into binary trees, and finally an instruction list is generated. Since the input region corresponds to one input and the output region corresponds to one output, the problem of incorrect conversion results or conversion failure often occurs when processing multi-input function instructions due to the inability to effectively distinguish the input signals of each branch. This solves the problem that the existing ladder diagram to instruction list method does not support the parsing of multi-input function instructions.

[0149] 2) In the ladder diagram to instruction table device of this application, the single-output ladder diagram is divided into at least one input region and one output region. Then, the input region and the output region are converted into directed graphs, and then into binary trees, and finally an instruction table is generated. Since the input region corresponds to one input and the output region corresponds to one output, the problem of incorrect conversion results or conversion failure often occurs when processing multi-input function instructions because the input signals of each branch cannot be effectively distinguished. This solves the problem that the existing ladder diagram to instruction table method does not support the parsing of multi-input function instructions.

[0150] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for converting a ladder diagram to an instruction list, characterized in that, include: Obtain a single-output ladder diagram, wherein the single-output ladder diagram includes multiple-input function instructions or single-input function instructions; The single-output ladder diagram is divided into at least one input region and one output region. One input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction. The input region and the output region are converted into directed graphs respectively to obtain multiple target directed graphs; The multiple target directed graphs are converted into binary trees to obtain multiple target binary trees; An instruction table is generated based on multiple target binary trees.

2. The method according to claim 1, characterized in that, Obtain a single-output ladder diagram, including: Obtain the initial ladder diagram; The initial ladder diagram is split according to the ladder level to obtain at least one single-output ladder diagram, and the single-output ladder diagram corresponds one-to-one with the output of the initial ladder diagram.

3. The method according to claim 1, characterized in that, The step of dividing the single-output ladder diagram into at least one input region and one output region includes: When the ladder diagram includes the multi-input function instruction, the region that generates each input of the multi-input function instruction is divided into independent regions to obtain multiple input regions, and the region that generates the output of the multi-input function instruction is divided into independent regions to obtain one output region; When the ladder diagram includes the single-input function instruction, the region that generates the input of the single-input function instruction is divided into an independent region to obtain an input region, and the region that generates the output of the single-input function instruction is divided into an independent region to obtain an output region.

4. The method according to claim 1, characterized in that, The input region and the output region are respectively converted into directed graphs to obtain multiple target directed graphs, including: The logical elements of the input region and the output region are mapped as physical nodes, and the intersection points of the routes between the logical elements of the input region and the output region are mapped as virtual nodes; A cross-linked list is used to store the directed graph. The cross-linked list includes vertex nodes and arc nodes. Each vertex node records element information and in-degree, out-degree, the first in-arc and out-arc pointers. Each arc node records the arc head and arc tail numbers and the same-head or same-tail arc pointers. The energy flow direction of the signal is determined based on the cross-linked list, and directed edges are established on the physical nodes and the virtual nodes according to the energy flow direction of the signal to generate multiple target directed graphs.

5. The method according to claim 4, characterized in that, The multiple directed graphs of the targets are converted into binary trees to obtain multiple target binary trees, including: Remove the virtual node in the directed graph whose out-degree and in-degree are both 1; The first merging step is to merge two first nodes connected in series into one first node, where the out-degree of one first node is 1 and the in-degree of the other first node is 1. The second merging step is to merge two parallel-connected second nodes into one parallel node, where the out-degree and in-degree of one second node are both 1, and the out-degree and in-degree of the other second node are both 1. Repeat the first merging step and the second merging step at least once until there is only one root node in the directed graph, to obtain the target binary tree corresponding to the target directed graph.

6. The method according to claim 5, characterized in that, Generate an instruction table based on multiple target binary trees, including: Based on the node types and relationships of all the target directed graphs, corresponding instructions are generated to obtain the instruction table. The instructions include instructions for leaf nodes, instructions for series nodes, and instructions for parallel nodes. The leaf nodes are nodes other than the series nodes and the parallel nodes.

7. A ladder diagram to instruction list conversion device, characterized in that, include: The acquisition unit is used to acquire a single-output ladder diagram, wherein the single-output ladder diagram includes multiple-input function instructions or single-input function instructions; A partitioning unit is used to divide the single-output ladder diagram into at least one input region and one output region, wherein one input region corresponds to one input of the multi-input function instruction or the single-input function instruction, and the output region corresponds to the input of the multi-input function instruction or the single-input function instruction. The first conversion unit is used to convert the input region and the output region into directed graphs respectively, to obtain multiple target directed graphs; The second conversion unit is used to convert the multiple target directed graphs into binary trees to obtain multiple target binary trees; The generation unit is used to generate an instruction table based on the plurality of target binary trees.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 6.

9. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1 to 6.

10. A host computer for a programmable logic controller, characterized in that, include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising methods for performing any one of claims 1 to 6.