State machine-based plc program online debugging method, system and electronic equipment

By storing debugging information in the configuration software and using a breakpoint linked list state machine during PLC program debugging, the problem of low debugging efficiency in PLC programs is solved, and a more efficient debugging process is achieved.

CN115599673BActive Publication Date: 2026-07-10NANJING SCIYON AUTOMATION GRP +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING SCIYON AUTOMATION GRP
Filing Date
2022-10-18
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

In the current PLC program debugging process, the debugging efficiency is low, mainly because the debugging information occupies a large amount of storage space in the PLC device and all breakpoint information needs to be traversed before each virtual instruction is executed, which leads to a decrease in instruction execution speed.

Method used

The debugging information is stored in the configuration software, and a state machine mechanism with a breakpoint list is used. Before each virtual instruction is executed, the breakpoint list is checked only to see if it is updated. The state is only updated when it is updated, reducing the frequency of traversal and update.

Benefits of technology

By independently storing debugging information and optimizing breakpoint state machine detection, storage consumption and traversal counts are reduced, thereby improving the efficiency of PLC program debugging and instruction execution speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115599673B_ABST
    Figure CN115599673B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of PLC debugging, and discloses a PLC program online debugging method and system based on a state machine and electronic equipment. The method comprises the following steps: obtaining a PLC program to be debugged and corresponding debugging information, and storing the PLC program in a PLC device and storing the debugging information in configuration software; wherein the PLC program comprises a plurality of virtual instructions. The configuration software generates a debugging instruction in combination with the debugging information and a user's debugging command, and sends the debugging instruction to the PLC device to determine a virtual instruction queue to be executed. Each virtual instruction is executed in turn based on the virtual instruction queue, and whether a breakpoint link list is updated is confirmed before each virtual instruction is executed, and when the breakpoint link list is updated, the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue is synchronously updated based on the breakpoint link list. The application has the advantage of high debugging efficiency in the PLC program debugging process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of PLC debugging technology, and specifically to a method, system, and electronic equipment for online debugging of PLC programs based on state machines. Background Technology

[0002] A PLC controller is a digital computing operating system used in industrial environments to execute various user-oriented instructions and automate the control processes of various equipment operations or industrial production. For large-scale industrial systems, the corresponding PLC control logic is more complex, and effective debugging of the PLC program is crucial to ensuring the stable operation of the PLC control logic and the industrial system.

[0003] During PLC program debugging, firstly, executable program data and relevant debugging information need to be generated. Then, based on debugging instructions, the virtual machine is controlled to sequentially execute the corresponding virtual instructions, and the specific execution status of each virtual instruction is obtained before execution. However, since the executable program data and debugging information are stored in the PLC device, not only does it occupy a large amount of local storage, but it also significantly impacts debugging efficiency when the control logic is complex. Furthermore, when obtaining the execution status of the corresponding virtual instructions, a method of scanning breakpoint information before the execution of each virtual instruction is adopted, thus requiring traversal of all breakpoint information. This traversal process also significantly reduces the instruction execution speed, thereby greatly affecting debugging efficiency. Summary of the Invention

[0004] The purpose of this invention is to provide a PLC program online debugging method, system, and electronic device based on a state machine, so as to solve the technical problem of low debugging efficiency in the existing PLC program online debugging process.

[0005] To achieve the above objectives, the present invention proposes the following technical solution:

[0006] The online debugging method for PLC programs based on state machines includes:

[0007] The PLC program to be debugged and its corresponding debugging information are obtained, and the PLC program is stored in the PLC device, while the debugging information is stored in the configuration software; wherein, the PLC program includes several virtual instructions, and the debugging information includes several debugging instructions generated based on user instructions;

[0008] The configuration software combines the debugging information and the user's debugging commands to generate debugging instructions, and sends the debugging instructions to the PLC device to determine the virtual instruction queue to be executed;

[0009] Based on the virtual instruction queue, each virtual instruction is executed sequentially. Before each virtual instruction is executed, it is confirmed whether the breakpoint list is updated. When the breakpoint list is updated, the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue is updated synchronously based on it.

[0010] The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine. The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state. The deletion state means deleting the breakpoint instruction to restore the corresponding virtual instruction. The addition state means replacing the virtual instruction with the corresponding breakpoint instruction. The hit-delete state means executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle. The hit-hold state means executing the breakpoint instruction according to the breakpoint instruction in any execution cycle.

[0011] Furthermore, the update of the breakpoint list includes:

[0012] Switching between the delete state and the hit delete state;

[0013] Switching between the deleted state and the hit-and-hold state;

[0014] The hit switches between the maintained state and the newly added state;

[0015] Switch from add status to delete status;

[0016] The hit delete state is switched to the hit hold state.

[0017] Furthermore, the virtual instructions and breakpoint instructions to be executed are stored in the instruction code area of ​​the PLC device;

[0018] The step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue during the update of the breakpoint linked list includes:

[0019] If the state of the breakpoint state machine is the deletion state, then the corresponding virtual instruction will be restored to the corresponding position in the instruction code area;

[0020] If the state of the breakpoint state machine is a newly added state, then the original virtual instruction is replaced by a breakpoint instruction at the corresponding position in the instruction code area;

[0021] If the state of the breakpoint state machine is the hit-delete state, then after the breakpoint instruction is executed, the corresponding virtual instruction will be restored to the corresponding position in the instruction code area;

[0022] If the breakpoint state machine is in a hit-and-hold state, then the breakpoint instruction will always be stored at the corresponding position in the instruction code area.

[0023] Furthermore, the step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue based on the breakpoint linked list during update includes:

[0024] If the state of the breakpoint state machine is the deletion state, then the corresponding virtual instruction in the virtual instruction queue will be executed within the current execution cycle.

[0025] If the state machine at the breakpoint is in the state of adding, holding, or deleting, the PLC program will be suspended by the breakpoint instruction when the corresponding process is reached in the current execution cycle, and feedback information will be sent to the configuration software.

[0026] Furthermore, after sending the feedback information to the configuration software, the process includes:

[0027] Based on the feedback information, the configuration software displays the execution process of the PLC program for this execution cycle.

[0028] A state machine-based online PLC program debugging system includes:

[0029] The program acquisition module is used to acquire the PLC program to be debugged and its corresponding debugging information, and to store the PLC program in the PLC device and the debugging information in the configuration software; wherein, the PLC program includes several virtual instructions, and the debugging information includes several debugging instructions generated based on user instructions;

[0030] The debugging planning module is used to enable the configuration software to generate debugging instructions by combining the debugging information and the user's debugging commands, and to send the debugging instructions to the PLC device to determine the virtual instruction queue to be executed;

[0031] The debugging execution module is used to execute each virtual instruction sequentially based on the virtual instruction queue, and to confirm whether the breakpoint list is updated before each virtual instruction is executed, and to synchronously update the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue when the breakpoint list is updated.

[0032] The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine. The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state. The deletion state means deleting the breakpoint instruction to restore the corresponding virtual instruction. The addition state means replacing the virtual instruction with the corresponding breakpoint instruction. The hit-delete state means executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle. The hit-hold state means executing the breakpoint instruction according to the breakpoint instruction in any execution cycle.

[0033] Furthermore, including:

[0034] The first update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area when the state of the breakpoint state machine is the deletion state;

[0035] The second update module is used to replace the original virtual instruction with a breakpoint instruction at the corresponding position in the instruction code area when the state of the breakpoint state machine is a new state.

[0036] The third update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area after the breakpoint instruction is executed when the state of the breakpoint state machine is the hit delete state.

[0037] The fourth update module is used to store the breakpoint instruction at the corresponding position in the instruction code area when the breakpoint state machine is in the hit-and-hold state.

[0038] Furthermore, including:

[0039] The first execution module is used to execute the corresponding virtual instruction in the virtual instruction queue during the current execution cycle when the state of the breakpoint state machine is in the deletion state.

[0040] The second execution module is used to suspend the PLC program according to the breakpoint instruction when the breakpoint state machine is in the add state, hold state, or delete state, and send feedback information to the configuration software when the corresponding process is executed in the current execution cycle.

[0041] Furthermore, including:

[0042] The display module is used to enable the configuration software to display the execution process of the PLC program in the current execution cycle based on the feedback information.

[0043] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, it implements the state machine-based PLC program online debugging method.

[0044] Beneficial effects:

[0045] As can be seen from the above technical solutions, the technical solution of the present invention provides a PLC program online debugging method based on a state machine to improve the technical defects of low debugging efficiency in existing PLC program debugging.

[0046] The debugging method mainly includes two stages: acquiring the PLC program to be debugged and the corresponding debugging information, and debugging the PLC program according to the debugging information. First, in the program acquisition stage, the inventors discovered that debugging information is program logic only involved in the PLC program debugging stage. However, existing PLC program debugging processes store both the debugging information and the PLC program within the PLC device, resulting in large storage requirements and reduced debugging efficiency. Therefore, this technical solution, based on this consideration, stores the debugging information within the configuration software, thereby reducing the consumption of PLC device storage space and improving the debugging efficiency.

[0047] Secondly, during the debugging phase, the inventors discovered that debugging often requires real-time debugging using breakpoint instructions based on user needs, in addition to the virtual instruction queue. Therefore, to ensure the debugging process follows actual debugging commands, it's necessary to check for corresponding breakpoint instructions before executing each virtual instruction in the virtual instruction queue. Existing methods typically involve traversing all breakpoint information before each virtual instruction, which is time-consuming and reduces the execution speed of virtual instructions or corresponding breakpoint instructions, thus affecting debugging efficiency. Therefore, this technical solution introduces the state machine from the PLC hardware debugging process into the PLC software debugging (i.e., PLC program debugging). This only requires checking the breakpoint list for updates before each virtual instruction, and only performs state checks on the specific breakpoint state machine when the breakpoint list is updated. Since updating the breakpoint list can be achieved using appropriate markers, the update check is extremely fast, and all state machine updates can be obtained and updated once when the breakpoint list is updated. Compared to existing technologies that require a traversal operation before each execution, updating the breakpoint instructions corresponding to the virtual instructions one by one greatly reduces the frequency of traversal searches and breakpoint instruction updates, thereby improving instruction execution speed and debugging efficiency.

[0048] It should be understood that all combinations of the foregoing concepts and the additional concepts described in more detail below can be considered part of the inventive subject matter of this disclosure, provided that such concepts do not contradict each other.

[0049] The foregoing and other aspects, embodiments, and features of the teachings of the present invention will be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the invention, such as features and / or beneficial effects of exemplary embodiments, will become apparent from the following description or may be learned through practice of specific embodiments according to the teachings of the present invention. Attached Figure Description

[0050] The accompanying drawings are not intended to be drawn to scale. In the drawings, each identical or nearly identical component shown in the various figures may be denoted by the same reference numeral. For clarity, not every component is labeled in each figure. Embodiments of various aspects of the invention will now be described by way of example and with reference to the accompanying drawings, wherein:

[0051] Figure 1 This is a flowchart of the online debugging method for PLC programs based on state machines as described in Example 1;

[0052] Figure 2 for Figure 1 The update logic diagram of the breakpoint linked list described in the document;

[0053] Figure 3 for Figure 1 A detailed flowchart of PLC debugging based on the state update of the breakpoint state machine;

[0054] Figure 4 To Figure 1 A diagram showing how the debugging results are displayed. Detailed Implementation

[0055] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention without creative effort are within the scope of protection of the present invention. Unless otherwise defined, the technical or scientific terms used herein should have the ordinary meaning understood by those skilled in the art.

[0056] The terms "first," "second," and similar words used in the specification and claims of this patent application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular forms of "an," "a," or "the," etc., do not indicate a quantity limitation, but rather indicate the presence of at least one. Terms such as "comprising" or "including" mean that the element or object preceding "comprising" encompasses the features, wholes, steps, operations, elements, and / or components listed following "comprising" or "including," and do not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components, and / or collections thereof. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0057] In existing PLC program debugging processes, the storage space occupied by debugging information on the PLC device is affected. In particular, the traversal operation to check for breakpoint information updates before each virtual instruction execution and the step-by-step comparison and updating of breakpoint information reduce instruction execution speed, thereby reducing the overall debugging efficiency of PLC programs. Based on this, this embodiment aims to provide a state machine-based online PLC program debugging method to improve this deficiency in existing PLC program debugging.

[0058] Example 1

[0059] Combination Figure 1 As shown, the online debugging method for PLC programs based on state machines proposed in this embodiment will be described in detail.

[0060] The method includes the following steps in sequence:

[0061] Step S102: Obtain the PLC program to be debugged and its corresponding debugging information, store the PLC program in the PLC device, and store the debugging information in the configuration software.

[0062] In this embodiment, the PLC program includes several virtual instructions. The PLC program and the debugging information are written by an editor and compiled by a compiler so that the PLC device and configuration software can recognize and execute them. Specifically, the debugging instructions record the mapping relationship between virtual instruction lines and text lines, so that when the configuration software issues debugging instructions, the corresponding virtual instruction offset can be obtained from the text line based on the mapping relationship.

[0063] Since the debugging information is stored in the configuration software in this step, and the configuration software is independent of the PLC device, the memory consumption of the PLC device caused by the debugging information is avoided, thereby improving the debugging efficiency during the debugging process.

[0064] Step S104: The configuration software combines the debugging information and the user's debugging commands to generate debugging instructions, and sends the debugging instructions to the PLC device to determine the virtual instruction queue to be executed.

[0065] Step S106: Execute each virtual instruction sequentially based on the virtual instruction queue, and confirm whether the breakpoint list has been updated before executing each virtual instruction. When the breakpoint list is updated, update the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue synchronously.

[0066] The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine.

[0067] The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state; the deletion state refers to deleting the breakpoint instruction to restore the corresponding virtual instruction, the addition state refers to replacing the virtual instruction with the corresponding breakpoint instruction, the hit-delete state refers to executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle, and the hit-hold state refers to executing the breakpoint instruction according to the breakpoint instruction in any execution cycle.

[0068] In this approach, before each virtual instruction execution, it is only necessary to check if the breakpoint list has been updated. Only when the breakpoint list is updated is the specific state of each breakpoint state machine searched for and updated; and the state machines of breakpoints with updated states are then updated once. Compared to existing technologies that traverse all breakpoint information before each virtual instruction execution and update breakpoint information one by one, this significantly reduces the computational load during breakpoint information confirmation, thereby improving instruction execution speed.

[0069] Specifically, such as Figure 2 As shown, the update logic of the breakpoint linked list includes:

[0070] Switching between delete state and hit-and-delete state; switching between delete state and hit-and-hold state; switching between hit-and-hold state and add state; switching from add state to delete state; switching from hit-and-delete state to hit-and-hold state.

[0071] For example, when switching from the delete state to the hit delete state, a breakpoint instruction is inserted at the corresponding virtual instruction, and deleted to restore it as a virtual instruction after the breakpoint instruction is hit in the current execution cycle. As another example, when switching from the delete state to the hit hold state, a breakpoint instruction is inserted at the corresponding virtual instruction, and remains unchanged after the breakpoint instruction is hit in the current execution cycle. As yet another example, when switching from the hit hold state to the add state, the breakpoint instruction is deleted and a new breakpoint instruction is added when the breakpoint instruction is hit in the current execution cycle. As yet another example, when switching from the add state to the delete state, the newly added breakpoint instruction is deleted.

[0072] To improve the debugging logic during PLC debugging, both the virtual instructions to be executed and the breakpoint instructions are stored in the instruction code area of ​​the PLC device. In step S106, when the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue is updated synchronously based on the breakpoint linked list, the specific process is as follows:

[0073] If the state of the breakpoint state machine is in the deletion state, the corresponding virtual instruction will be restored to the corresponding position in the instruction code area.

[0074] If the state of the breakpoint state machine is a newly added state, then the original virtual instruction is replaced by a breakpoint instruction at the corresponding position in the instruction code area.

[0075] If the state of the breakpoint state machine is in the hit-delete state, then after the breakpoint instruction is executed, the corresponding virtual instruction will be restored to the corresponding position in the instruction code area.

[0076] If the breakpoint state machine is in a hit-and-hold state, then the breakpoint instruction will always be stored at the corresponding position in the instruction code area.

[0077] As a specific implementation method, such as Figure 3 As shown, when debugging a PLC based on the state update of a breakpoint state machine, the specific steps include:

[0078] Step S106.2: If the state of the breakpoint state machine is the deletion state, then the corresponding virtual instruction in the virtual instruction queue will be executed within the current execution cycle.

[0079] Step S106.4: If the state of the breakpoint state machine is in the add state, hold state, or delete state, then when the corresponding process is executed in the current execution cycle, the PLC program is suspended according to the breakpoint instruction, and feedback information is sent to the configuration software.

[0080] To enable users to obtain debugging results, as a specific implementation method, such as Figure 4 As shown, after steps S106.2 to S106.4, the method further includes:

[0081] Step S108: The configuration software displays the execution process of the PLC program for this execution cycle based on the feedback information.

[0082] At this point, the debugging results for this period can be obtained through the displayed results for further debugging and optimization.

[0083] Based on this embodiment, independent storage of debugging information avoids the corresponding storage space occupation, and the introduction of a breakpoint state machine during PLC hardware debugging avoids the need for traversing all breakpoint information and updating each breakpoint information one by one before each execution during PLC software debugging, thus improving execution speed. This, in turn, improves the final PLC program debugging efficiency.

[0084] The aforementioned program can run in a processor or be stored in memory (or a computer-readable storage medium). Computer-readable media includes both permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, program modules, 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, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media, such as modulated data signals and carrier waves.

[0085] These computer programs 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 for the functions specified in one or more boxes can be implemented using different modules, and different steps can be implemented using different modules.

[0086] Example 2

[0087] In step S106 of Embodiment 1, the breakpoint state machine can also be an instruction-level single-step state machine. The states of the instruction-level single-step state machine sequentially include: an initial state, a first-level state, and a second-level state. In step S106, when a breakpoint instruction is triggered, the execution of the corresponding virtual instruction is stopped, and the instruction-level single-step state machine undergoes a state transition. If it is currently in the initial state, it transitions to the first-level state; if it is currently in the first-level state, it transitions to the second-level state; and if it is currently in the second-level state, it transitions to the initial state.

[0088] During implementation, the specific logic is as follows; where origin is the initial state, state0 is the first-level state, state1 is the second-level state, ilss represents the instruction-level single-step state machine, and the REAL_NORMAL state represents the instruction to delete the breakpoint.

[0089] First, under normal circumstances:

[0090] 1. With the virtual machine stopped, the client sends instruction-level single-step commands;

[0091] 2. The resolver switches ILSS from state origin to state 0 and starts the virtual machine;

[0092] 3. The virtual machine detects that the ilss state is state0, switches it to state1, and parses a virtual instruction;

[0093] 4. The virtual machine detects that the ilss state is state1, switches it to origin, and enters the debug stub;

[0094] 5. The debug stub sends the current instruction offset to the client and waits for the client to send instructions;

[0095] Secondly, in the case of hitting the breakpoint instruction:

[0096] 1. The virtual machine entered a debug stub due to a breakpoint being hit and is in a stopped state. The client sends the ilss command.

[0097] 2. The resolver switches ILSS from state origin to state 0 and starts the virtual machine;

[0098] 3. The virtual machine changes the breakpoint to the REAL_NORMAL state and resumes virtual instructions;

[0099] 4. The virtual machine detects that the ilss state is state0, switches it to state1, and parses a virtual instruction;

[0100] 5. The virtual machine detects a change in the breakpoint list and restores the breakpoint instructions;

[0101] 6. The virtual machine detects that the ilss state is state1, switches it to origin, and enters the debug stub;

[0102] 7. The debug stub sends the current instruction offset to the client and waits for the client to send instructions.

[0103] Furthermore, when a breakpoint instruction is encountered during the ILSS process:

[0104] 1. With the virtual machine stopped, the client sends instruction-level single-step commands;

[0105] 2. The resolver switches ILSS from state origin to state 0 and starts the virtual machine;

[0106] 3. The virtual machine detects that the ilss state is state0, switches it to state1, and parses a virtual instruction;

[0107] 4. The parsed virtual instruction is a breakpoint instruction. When the breakpoint is hit, the debug stub is entered, and the breakpoint is marked as a resumed state. The ilss state is checked and it is state1, indicating that the breakpoint was hit during the ilss process. At this time, the program does not stop, but switches the ilss state to state0 and continues to run.

[0108] 5. The virtual machine changes the breakpoint to the REAL_NORMAL state and resumes the virtual instruction. It checks that the ilss state is state0, switches the ilss state to state1, and parses a virtual instruction.

[0109] 6. The virtual machine detects a change in the breakpoint list and restores the breakpoint instructions;

[0110] 7. The virtual machine detects that the ilss state is state1, switches it to origin, and enters the debug stub;

[0111] 8. The debug stub sends the current instruction offset to the client and waits for the client to send instructions.

[0112] Since instruction-level step-by-step exit is achieved through the instruction-level single-step state machine, it is not necessary to traverse all breakpoint information before executing virtual instructions, which also has the advantage of improving instruction execution speed.

[0113] Example 3

[0114] This embodiment provides a PLC program online debugging system based on a state machine. The system includes:

[0115] The program acquisition module is used to acquire the PLC program to be debugged and its corresponding debugging information, and to store the PLC program in the PLC device and the debugging information in the configuration software; wherein, the PLC program includes several virtual instructions, and the debugging information includes several debugging instructions generated based on user instructions.

[0116] The debugging planning module, in which the configuration software combines the debugging information and the user's debugging commands to generate debugging instructions, and sends the debugging instructions to the PLC device to determine the virtual instruction queue to be executed.

[0117] The debugging execution module is used to execute each virtual instruction sequentially based on the virtual instruction queue, and to confirm whether the breakpoint list has been updated before each virtual instruction is executed, and to update the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue synchronously when the breakpoint list is updated.

[0118] The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine. The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state. The deletion state means deleting the breakpoint instruction to restore the corresponding virtual instruction. The addition state means replacing the virtual instruction with the corresponding breakpoint instruction. The hit-delete state means executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle. The hit-hold state means executing the breakpoint instruction according to the breakpoint instruction in any execution cycle.

[0119] The steps of the system used to implement the above method have already been explained and will not be repeated here.

[0120] For example, the system also includes:

[0121] The first update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area when the state of the breakpoint state machine is in the deletion state.

[0122] The second update module is used to replace the original virtual instruction with a breakpoint instruction at the corresponding position in the instruction code area when the state of the breakpoint state machine is a new state.

[0123] The third update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area after the breakpoint instruction is executed when the state of the breakpoint state machine is the hit delete state.

[0124] The fourth update module is used to store the breakpoint instruction at the corresponding position in the instruction code area when the breakpoint state machine is in the hit-and-hold state.

[0125] For example, the system also includes:

[0126] The first execution module is used to execute the corresponding virtual instruction in the virtual instruction queue during the current execution cycle when the state of the breakpoint state machine is in the deletion state.

[0127] The second execution module is used to suspend the PLC program according to the breakpoint instruction when the breakpoint state machine is in the add state, hold state, or delete state, and send feedback information to the configuration software when the corresponding process is executed in the current execution cycle.

[0128] For example, the system also includes:

[0129] The display module is used to enable the configuration software to display the execution process of the PLC program in the current execution cycle based on the feedback information.

[0130] Since the electronic devices are all built based on the method, they also have the advantage of high debugging efficiency when debugging PLC programs.

[0131] Example 4

[0132] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, it implements the state machine-based PLC program online debugging method.

[0133] Since the electronic devices are all built based on the method, they also have the advantage of high debugging efficiency when debugging PLC programs.

[0134] While the present invention has been disclosed above with reference to preferred embodiments, it is not intended to limit the invention. Those skilled in the art can make various modifications and refinements without departing from the spirit and scope of the invention. Therefore, the scope of protection of the present invention shall be determined by the claims.

Claims

1. A method for online debugging of PLC programs based on state machines, characterized in that, include: The PLC program to be debugged and its corresponding debugging information are acquired, and the PLC program is stored in the PLC device, while the debugging information is stored in the configuration software. The configuration software and the PLC device are independent of each other. The PLC program includes several virtual instructions. The debugging information includes several first debugging instructions generated based on user instructions. The first debugging instructions record the mapping relationship between virtual instruction lines and text lines, so that when a second debugging instruction is issued in the configuration software, the corresponding virtual instruction offset can be obtained from the text line based on the mapping relationship. The configuration software combines the debugging information and the user's debugging commands to generate a second debugging instruction, and sends the second debugging instruction to the PLC device to determine the virtual instruction queue to be executed; Based on the virtual instruction queue, each virtual instruction is executed sequentially. Before executing each virtual instruction, it is confirmed whether the breakpoint list has been updated. If the breakpoint list has not been updated, the specific state update of each breakpoint state machine is not searched. If the breakpoint list is updated, the specific state update of each breakpoint state machine is searched, and the breakpoint state machines with updated states are updated once, so that the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue is updated synchronously based on the breakpoint list when it is updated. The virtual instructions to be executed and the breakpoint instructions are stored in the instruction code area of ​​the PLC device. The step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue when the breakpoint list is updated includes: if the state of the breakpoint state machine is the hit delete state, then after the breakpoint instruction is executed, the corresponding virtual instruction is restored to the corresponding position in the instruction code area. The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine. The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state. The deletion state refers to deleting the breakpoint instruction to restore the corresponding virtual instruction. The addition state refers to replacing the virtual instruction with the corresponding breakpoint instruction. The hit-delete state refers to executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle. The hit-hold state refers to executing the breakpoint instruction according to the breakpoint instruction in any execution cycle. The update of the breakpoint list includes: switching between the delete state and the hit-delete state; switching between the delete state and the hit-hold state; switching between the hit-hold state and the add state; switching from the add state to the delete state; and switching from the hit-delete state to the hit-hold state.

2. The online debugging method for PLC programs based on state machines according to claim 1, characterized in that, The step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue during the update of the breakpoint linked list includes: If the state of the breakpoint state machine is a newly added state, then the original virtual instruction is replaced by a breakpoint instruction at the corresponding position in the instruction code area; If the breakpoint state machine is in a hit-and-hold state, then the breakpoint instruction will always be stored at the corresponding position in the instruction code area.

3. The online debugging method for PLC programs based on state machines according to claim 1, characterized in that, The step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue during the update of the breakpoint linked list includes: If the state of the breakpoint state machine is the deletion state, then the corresponding virtual instruction in the virtual instruction queue will be executed within the current execution cycle. If the state machine at the breakpoint is in the state of adding, holding, or deleting, the PLC program will be suspended by the breakpoint instruction when the corresponding process is reached in the current execution cycle, and feedback information will be sent to the configuration software.

4. The online debugging method for PLC programs based on state machines according to claim 3, characterized in that, After sending feedback information to the configuration software, the process includes: Based on the feedback information, the configuration software displays the execution process of the PLC program for this execution cycle.

5. A PLC program online debugging system based on a state machine, characterized in that, include: The program acquisition module acquires the PLC program to be debugged and its corresponding debugging information, stores the PLC program in the PLC device, and stores the debugging information in the configuration software, which is independent of the PLC device. The PLC program includes several virtual instructions; the debugging information includes several first debugging instructions generated based on user instructions. Each first debugging instruction records a mapping relationship between virtual instruction lines and text lines, so that when a second debugging instruction is issued in the configuration software, the corresponding virtual instruction offset can be obtained from the text lines based on the mapping relationship. The debugging planning module, in which the configuration software combines the debugging information and the user's debugging commands to generate a second debugging instruction, and sends the second debugging instruction to the PLC device to determine the virtual instruction queue to be executed; The debugging execution module executes each virtual instruction sequentially based on the virtual instruction queue. Before executing each virtual instruction, it checks whether the breakpoint list has been updated. If the breakpoint list has not been updated, it does not search for the specific state update of each breakpoint state machine. If the breakpoint list has been updated, it searches for the specific state update of each breakpoint state machine and updates the breakpoint state machines with updated states once, so that the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue is updated synchronously based on the breakpoint list update. The virtual instructions to be executed and the breakpoint instructions are stored in the instruction code area of ​​the PLC device. The step of synchronously updating the state of each breakpoint state machine corresponding to each virtual instruction in the virtual instruction queue based on the breakpoint list update includes: if the state of the breakpoint state machine is a hit-delete state, then after the breakpoint instruction is executed, the corresponding virtual instruction is restored to the corresponding position in the instruction code area. The breakpoint list stores all breakpoint instructions corresponding to the virtual instruction queue, and each breakpoint instruction corresponds to a breakpoint state machine. The states of the breakpoint state machine include: deletion state, addition state, hit-delete state, and hit-hold state. The deletion state refers to deleting the breakpoint instruction to restore the corresponding virtual instruction. The addition state refers to replacing the virtual instruction with the corresponding breakpoint instruction. The hit-delete state refers to executing the breakpoint instruction according to the breakpoint instruction in the current execution cycle and restoring the breakpoint instruction to the corresponding virtual instruction in the next execution cycle. The hit-hold state refers to executing the breakpoint instruction according to the breakpoint instruction in any execution cycle. The update of the breakpoint list includes: switching between the delete state and the hit-delete state; switching between the delete state and the hit-hold state; switching between the hit-hold state and the add state; switching from the add state to the delete state; and switching from the hit-delete state to the hit-hold state.

6. The PLC program online debugging system based on a state machine according to claim 5, characterized in that, include: The first update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area when the state of the breakpoint state machine is the deletion state; The second update module is used to replace the original virtual instruction with a breakpoint instruction at the corresponding position in the instruction code area when the state of the breakpoint state machine is a new state. The third update module is used to restore the corresponding virtual instruction to the corresponding position in the instruction code area after the breakpoint instruction is executed when the state of the breakpoint state machine is the hit delete state. The fourth update module is used to store the breakpoint instruction at the corresponding position in the instruction code area when the breakpoint state machine is in the hit-and-hold state.

7. The PLC program online debugging system based on a state machine according to claim 5, characterized in that, include: The first execution module is used to execute the corresponding virtual instruction in the virtual instruction queue during the current execution cycle when the state of the breakpoint state machine is in the deletion state. The second execution module is used to suspend the PLC program according to the breakpoint instruction when the breakpoint state machine is in the add state, hold state, or delete state during the current execution cycle, and send feedback information to the configuration software.

8. The PLC program online debugging system based on a state machine according to claim 7, characterized in that, include: The display module is used to enable the configuration software to display the execution process of the PLC program in the current execution cycle based on the feedback information.

9. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor runs the computer program, it implements the online debugging method for a PLC program based on a state machine as described in any one of claims 1-4.