A remote monitoring and debugging method, system and terminal based on PLC

By using virtual PLC and debugging equipment in a virtual environment, combining Hook mechanism and modular programming, the problem of time-consuming and error-prone debugging of traditional PLC programs is solved, and efficient and accurate PLC program debugging is achieved, reducing the actual system Influence.

CN118642426BActive Publication Date: 2024-11-12YANTAI OUNENG ELECTRONIC TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411123826.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2024-11-12
Estimated Expiration
2044-08-16

AI Technical Summary

Technical Problem

Traditional PLC program debugging relies on hardware devices, resulting in geographic location limitations and high development costs, and the debugging process is time-consuming and error-prone.

Method used

The virtual environment is equipped with virtual PLC and debugging equipment, and program replacement and breakpoint setting are performed through the Hook mechanism, combining modular programming and single-step execution to realize automated judgment and execution, and generate operation reports.

Benefits of technology

It improves the efficiency and accuracy of PLC program debugging, reduces the impact on the actual production system, reduces manual intervention, and improves the safety and maintainability of debugging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118642426B_ABST
    Figure CN118642426B_ABST
Patent Text Reader

Abstract

The present application provides a remote monitoring and debugging method, system and terminal based on PLC, which relates to the technical field of remote debugging of PLC programs, wherein the debugging method includes steps such as installing a virtual environment, configuring parameters, first judgment, second judgment, detection, and output; the debugging system includes building a virtual environment module, configuring parameter module, judgment module, program replacement module and output module. The entire process of the present application includes multiple automated judgment and execution steps, such as breakpoint setting, program replacement, first acquisition, etc., which reduces manual intervention and improves debugging efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of remote debugging of PLC programs, and in particular to a remote monitoring and debugging method, system and terminal based on PLC. Background Art

[0002] With the rapid development of industrial automation technology, programmable logic controllers (PLCs) play a vital role in industrial production. However, the traditional PLC development, debugging and commissioning process often relies on actual hardware equipment, and the PLC program needs to be debugged in the factory where the hardware equipment is located, which not only increases the development cost, but also has geographical restrictions.

[0003] The Chinese invention patent with publication date of May 12, 2020 and publication number of CN111142469A provides a debugging method and debugging system for the configuration program of a PLC. By judging whether the current instruction line is a valid stop line, the state of program operation is controlled to realize remote debugging of the PLC program. During the debugging process of the PLC program, the developer needs to add debugging information to the code lines one by one. The first function determines whether the current instruction line is a valid stop line based on the information sent by the debugging device, and determines whether to continue running the current instruction line. Debugging information is added to each code line, and whether to continue running the code line is determined one by one based on the debugging information. The debugging process is time-consuming and error-prone. Summary of the invention

[0004] In order to improve debugging efficiency and accuracy, the present application provides a PLC-based remote monitoring and debugging method, system and terminal.

[0005] In the first aspect, the present application provides a remote monitoring and debugging method based on PLC, which adopts the following technical solution:

[0006] A remote monitoring and debugging method based on PLC, comprising the following steps:

[0007] Carrying out a virtual environment: establishing a virtual environment, wherein the virtual environment includes: a virtual PLC and a debugging device;

[0008] Configuration parameters: configure the parameters of the virtual environment and set the input signal of the virtual PLC, the input signal of the virtual PLC includes: the output signal of the debugging device;

[0009] First judgment: judging whether the virtual PLC runs according to the expected logic, if yes, executing the output step; if no, executing the second judgment step;

[0010] Second judgment: judge whether the input signal of the virtual PLC is correct, if so, execute the detection step; if not, execute the parameter configuration step;

[0011] Detection: including setting breakpoints, first acquisition and program replacement;

[0012] Set breakpoints: Set n breakpoints in the PLC program of the virtual PLC;

[0013] First acquisition: obtain the replacement program between the i-th breakpoint and the i+1-th breakpoint, recorded as the first program;

[0014] Program replacement: Using the Hook mechanism, the program between the i-th breakpoint and the i+1-th breakpoint of the PLC program is replaced with the first program, and the first judgment step is executed;

[0015] Output: Generate and output the operation report of the virtual PLC.

[0016] By adopting the above technical solution, the present application uses the Hook mechanism for program replacement, which can quickly verify whether different code segments are correct, and can promptly find out which code segment has an error, reducing the time for manual modification and line-by-line search for error codes. The present application includes multiple automated judgment and execution steps, such as breakpoint setting, program replacement, first acquisition, etc., which reduces manual intervention and improves debugging efficiency. By outputting a run report, the present application can record each step and result of the debugging process in detail, which is convenient for subsequent analysis and problem location. The present application builds a virtual environment and performs debugging in the virtual environment, which can reduce the impact on the actual production system and improve the safety of debugging. The virtual environment allows for rapid configuration and modification of the parameters of the virtual environment, setting the input signal of the virtual PLC, and simulating the feedback status of the debugging device in the virtual environment, thereby conveniently debugging the performance of the PLC program in different scenarios.

[0017] Optionally, modular programming is used to divide the PLC program into multiple data blocks according to functions; the program of each data block is debugged using a single-step execution method.

[0018] By adopting the above technical solution, the present application divides the PLC program into multiple data blocks, each data block corresponds to a specific function in the PLC program, and the program can be replaced in the form of data blocks in the program replacement step. When a function needs to be modified or updated, only the relevant data blocks need to be concerned, without the need to make large-scale modifications to the entire PLC program, and the same or similar functions can be reused in the PLC programs of different projects, reducing the workload of repeated programming. By debugging the program of each data block in a single-step execution mode, the developer can accurately control the execution flow of the program, gradually observe the values ​​of the variables in the data blocks and the output of the program, and compare the values ​​of the variables and the output of the program at runtime to help the developer analyze the cause of the error and determine whether the problem is in a specific part of the data block or in the interaction between the data blocks. The present application adopts modular programming and a single-step execution mode, which can more efficiently debug and verify the correctness and reliability of the PLC program, not only improving the accuracy and efficiency of debugging, but also improving the maintainability and scalability of the PLC program.

[0019] Optionally, after executing the breakpoint setting step and before executing the first acquisition step, the method further includes:

[0020] First backup: back up each data block in the PLC program separately;

[0021] First programming: write replacement programs according to each data block in the PLC program;

[0022] Interface matching: assigning the input / output interface data in each data block to the input / output interface data of the replacement program;

[0023] Program storage: Encapsulate the replacement program of a data block in a function library.

[0024] By adopting the above technical solution, the present application performs a separate backup of each data block of the PLC before executing the PLC program replacement. During the debugging process, if an unforeseen problem occurs, the original PLC program can be quickly restored. According to each data block in the PLC program, a corresponding replacement program is written. These replacement programs are used to temporarily replace all the codes in the original data block during the debugging process in order to verify specific functions or repair potential problems. The present application assigns the input / output interface data in each data block to the input / output interface data of the replacement program, ensuring that the replacement program can correctly interact with other parts of the PLC program. The present application encapsulates all the replacement programs of a data block in a function library, which facilitates the management and reuse of the replacement program. The function library contains multiple replacement programs, each of which corresponds to a specific data block or function. During the debugging process, the corresponding replacement program can be selected for loading and execution as needed. The present application encapsulates the replacement program in the function library, which also helps to keep the code neat and orderly, and facilitates subsequent maintenance and upgrades.

[0025] Optionally, in the program replacement step, it also includes:

[0026] Third judgment: judging whether the first program is replaced successfully, if so, executing the first judgment step; if not, executing the calling step;

[0027] Calling: replacing the first program with the data blocks backed up in the first backup step, and executing the first acquisition step.

[0028] By adopting the above technical solution, the present application sets a third judgment step after the program replacement step to determine whether the program replacement is successful. If the replacement operation has been successfully completed, the first judgment step is executed, that is, the replaced program is used for further debugging or operation. If the replacement operation is not successfully completed, such as there is an error in the replacement program, an interruption or conflict occurs during the replacement process, etc., it is necessary to execute the calling step to restore the original state. After restoring the original state, the first acquisition step is re-executed to re-acquire the replacement program and re-replace the data block in the PLC program. Through the third judgment step and the calling step, the present application can further ensure the accuracy of the replacement and improve the flexibility and controllability of the debugging process.

[0029] Optionally, the number n of breakpoints is smaller than the number of lines of code in the PLC program and larger than the number of data blocks included in the PLC program.

[0030] By adopting the above technical solution, the present application flexibly sets breakpoints during the debugging process of the PLC program, which helps developers to control the debugging process more accurately and quickly locate and solve potential problems. The number of breakpoints n is less than the number of code lines in the PLC program, indicating that the developer will not set a breakpoint after each line of code, reducing the problem of too many breakpoints causing the program to run too slowly or debug too slowly. The number of breakpoints n is greater than the number of data blocks contained in the PLC program, that is, breakpoints are set at the beginning and end of each data block, which can ensure that each PLC data block can be debugged separately, and two data blocks will not be debugged at the same time.

[0031] Optionally, after executing the program detection step and before executing the output step, the method further includes:

[0032] Fourth judgment: judging whether the virtual PLC needs to communicate with the debugging device in the virtual environment, if yes, executing the first setting step; if no, executing the output step;

[0033] First setting: including setting the communication protocol, setting the client library, and the second acquisition and data processing steps;

[0034] Set the communication protocol: Set the virtual PLC to communicate with the debugging device via the MQTT protocol;

[0035] Set up client library: Set up the MQTT client library on the virtual PLC;

[0036] Second acquisition: The debugging device forwards the collected data to the corresponding MQTT client library through the MQTT protocol;

[0037] Data processing: After the virtual PLC processes the data, it displays the processed data through the output step.

[0038] By adopting the above technical solution, the present application can intelligently determine whether the virtual PLC needs to communicate with the debugging device according to the current environment or demand by setting the fourth judgment step, thereby reducing unnecessary resource consumption or erroneous operations. The present application adopts the MQTT protocol for communication. The MQTT protocol is a lightweight message transmission protocol with the characteristics of low bandwidth, low power consumption, and high reliability, and is suitable for data exchange between devices. An MQTT client library is set on the virtual PLC so that the virtual PLC can communicate with the debugging device as an MQTT client. Data is obtained from the debugging device through the MQTT protocol and processed in the virtual PLC. This process ensures the accuracy and real-time nature of the data.

[0039] Optionally, after executing the step of setting the client library and before executing the second obtaining step, the method further includes:

[0040] Data publishing: The virtual PLC periodically publishes status information to the specified topic of the MQTT server, and the status information includes: the input signal of the virtual PLC, the output signal of the virtual PLC, and the internal status signal of the virtual PLC;

[0041] Instruction reception: The virtual PLC receives the control instruction topic published by the MQTT server, and controls the debugging device according to the received control instruction topic.

[0042] By adopting the above technical solution, the virtual PLC regularly publishes status information to the specified topic of the MQTT server, which helps to achieve status synchronization between the virtual PLC and the debugging device or other monitoring systems. By updating the status information in real time, the debugging device can obtain the latest status of the virtual PLC and perform corresponding actions. The virtual PLC can receive the control instruction topic published by the MQTT server and control the debugging device according to these instructions, realizing the remote control function of the debugging device and improving the flexibility and automation of the system.

[0043] Optionally, after executing the instruction receiving step and before executing the second acquiring step, the method further includes:

[0044] Set up the client application: Set up the MQTT client application on the debugging device to connect to the MQTT server and subscribe to the topic of the virtual PLC status information;

[0045] Set up virtual interface: Develop virtual interface through HMI development tools to display the status information of virtual PLC.

[0046] By adopting the above technical solution, an MQTT client application is set on the debugging device, so that the debugging device can actively connect to the MQTT server and subscribe to the topic of the virtual PLC status information. In this way, the debugging device can receive and process the status information published by the virtual PLC in real time, and realize two-way communication with the virtual PLC. Through the MQTT protocol for communication, each debugging device can be easily integrated with other devices or systems that follow the MQTT protocol, which enhances flexibility and scalability. By developing a virtual interface through the HMI development tool, the status information of the virtual PLC is displayed to the developer in an intuitive and friendly way, which helps the developer quickly understand the operating status of the virtual PLC and perform corresponding operations or decisions through the virtual interface.

[0047] In the second aspect, the present application provides a remote monitoring and debugging system based on PLC, which adopts the following technical solution:

[0048] A remote monitoring and debugging system based on PLC, comprising:

[0049] Building a virtual environment module for establishing a virtual environment, wherein the virtual environment includes: a virtual PLC and a debugging device;

[0050] A configuration parameter module is used to configure the parameters of the virtual environment and set the input signal of the virtual PLC, wherein the input signal of the virtual PLC includes: an output signal of the debugging device;

[0051] A judgment module, comprising a first judgment unit and a second judgment unit;

[0052] A first judging unit, used to judge whether the virtual PLC operates according to the expected logic;

[0053] A second judging unit is used to judge whether the input signal of the virtual PLC is correct;

[0054] A program replacement module, used for setting breakpoints in the PLC program and replacing the PLC program between the breakpoints with a replacement program to obtain a second program;

[0055] Output module, generates and outputs the operation report of the virtual PLC.

[0056] By adopting the above technical solution, the virtual environment building module is responsible for creating a virtual environment including a virtual PLC, configuring the hardware and software resources in the virtual environment, ensuring that they can simulate the operating environment of the actual PLC, and providing a developer interface or API interface so that developers can easily configure and manage the virtual environment. The configuration parameter module allows the user to configure the various parameters of the virtual environment and set the input signal of the virtual PLC to simulate the data input of external sensors or devices. The judgment module includes multiple judgment units for real-time monitoring and judgment during program operation. The program replacement module can automatically or manually set breakpoints in the PLC program, allowing developers to upload or write replacement programs to replace the PLC program between breakpoints, perform replacement operations, and generate and save the second program for further debugging or verification.

[0057] In a third aspect, the present application provides a terminal, which adopts the following technical solution:

[0058] A terminal is provided, wherein the terminal is equipped with the PLC-based remote monitoring and debugging system, and when the terminal is in operation, the terminal is used to implement the PLC-based remote monitoring and debugging method.

[0059] In summary, the present application includes at least one of the following beneficial technical effects:

[0060] 1. This application uses the Hook mechanism for program replacement, which can quickly verify whether different code segments are correct, and can promptly find out which code segment has an error, reducing the time for manual modification and line-by-line search for error codes. This application includes multiple automated judgment and execution steps, such as breakpoint setting, program replacement, first acquisition, etc., which reduces manual intervention and improves debugging efficiency. This application can record each step and result of the debugging process in detail by outputting a run report, which is convenient for subsequent analysis and problem location. This application builds a virtual environment and performs debugging in the virtual environment, which can reduce the impact on the actual production system and improve the safety of debugging. The virtual environment allows for rapid configuration and modification of the parameters of the virtual environment, setting the input signals of the virtual PLC, and simulating the feedback status of the debugging device in the virtual environment, thereby conveniently debugging the performance of the PLC program in different scenarios.

[0061] 2. This application divides the PLC program into multiple data blocks, each data block corresponds to a specific function in the PLC program. In the program replacement step, the program can be replaced in the form of data blocks. When a function needs to be modified or updated, only the relevant data blocks need to be concerned, without large-scale modification of the entire PLC program. The same or similar functions can be reused in the PLC programs of different projects, reducing the workload of repeated programming. By debugging the program of each data block in a single-step execution mode, the developer can accurately control the execution process of the program, gradually observe the values ​​of the variables in the data blocks and the output of the program, and compare the values ​​of the variables and the output of the program at runtime to help the developer analyze the cause of the error and determine whether the problem is in a specific part of the data block or in the interaction between the data blocks. This application adopts modular programming and single-step execution, which can more efficiently debug and verify the correctness and reliability of the PLC program, not only improving the accuracy and efficiency of debugging, but also improving the maintainability and scalability of the PLC program.

[0062] 3. By setting the fourth judgment step, the present application can intelligently determine whether the virtual PLC needs to communicate with the debugging device according to the current environment or demand, thereby reducing unnecessary resource consumption or erroneous operations. The present application adopts the MQTT protocol for communication. The MQTT protocol is a lightweight message transmission protocol with the characteristics of low bandwidth, low power consumption, and high reliability, and is suitable for data exchange between devices. An MQTT client library is set on the virtual PLC so that the virtual PLC can communicate with the debugging device as an MQTT client. Data is obtained from the debugging device through the MQTT protocol and processed in the virtual PLC. This process ensures the accuracy and real-time nature of the data.

[0063] 4. The virtual environment module is responsible for creating a virtual environment containing a virtual PLC, configuring the hardware and software resources in the virtual environment to ensure that they can simulate the operating environment of the actual PLC, and providing a developer interface or API interface so that developers can easily configure and manage the virtual environment. The configuration parameter module allows the user to configure the various parameters of the virtual environment and set the input signal of the virtual PLC to simulate the data input of external sensors or devices. The judgment module contains multiple judgment units for real-time monitoring and judgment during program operation. The program replacement module can automatically or manually set breakpoints in the PLC program, allowing developers to upload or write replacement programs to replace the PLC program between breakpoints, perform replacement operations, and generate and save the second program for further debugging or verification. BRIEF DESCRIPTION OF THE DRAWINGS

[0064] Figure 1 It is a flow chart of a remote monitoring and debugging method based on PLC in the present application;

[0065] Figure 2 This is a flow chart of the method of step S3: detection of this application;

[0066] Figure 3 This is a flow chart of the method of setting in step S4 of this application. DETAILED DESCRIPTION

[0067] The following combination Figures 1 to 3 This application is described in further detail.

[0068] Embodiment 1: This embodiment discloses a remote monitoring and debugging method based on PLC, referring to Figure 1 The debugging method includes: step S1: preliminary preparation, step S2: judgment, step S3: detection, step S4: setting and step S5: output. In this embodiment, the virtual environment is first set, and then the parameters of the virtual environment and the input signal of the virtual PLC are set. Then, it is judged whether the virtual PLC runs according to the expected logic, and then it is judged whether the input signal of the virtual PLC is correct, and then the program is replaced, and then it is judged whether the replaced second program can run as expected. If it can, an operation report is output. Otherwise, the data block after the next breakpoint is replaced and debugged, and then an operation report is output. The remote monitoring debugging method is as follows:

[0069] The step S1: preliminary preparation includes step S11: installing a virtual environment and step S12: configuring parameters.

[0070] Step S11: Use a virtual environment to build a virtual environment that includes a complete industrial control process using professional simulation software or a cloud platform. The virtual environment includes a virtual PLC and debugging equipment. The virtual environment needs to simulate the hardware configuration, network topology, and communication protocol in the actual production scenario to ensure that the debugging environment is close to the actual application.

[0071] Install PLC programming software and necessary debugging tools in the virtual environment to ensure that all components are compatible and run stably.

[0072] Through modular programming, the PLC program is divided into multiple data blocks according to its functions.

[0073] Load the programmed data blocks into the virtual PLC and perform preliminary operation and debugging to verify whether the basic functions of the PLC program are realized.

[0074] Step S12: Configure parameters. According to the debugging requirements, configure various parameters of the virtual environment in detail, such as device parameters, network delay, fault simulation, etc. Simulate external input signals, including sensor data, button signals, etc., to ensure that the virtual PLC can receive correct input information. The input signals of the virtual PLC include: the output signals of the debugging device.

[0075] The step S2: judging includes step S21: first judging and step S22: second judging.

[0076] Step S21: first judgment, judging whether the virtual PLC runs according to the expected logic, if so, executing step S5: output; if not, executing step S22: second judgment.

[0077] Step S22: second judgment, judging whether the input signal of the virtual PLC is correct. If the input signal is correct, then executing step S3: detection; if the input signal is wrong, then returning to step S13: configuring parameters and adjusting the input signal.

[0078] like Figure 2 As shown, the step S3: detection includes step S31: setting breakpoints, step S32: writing a replacement program, step S33: first acquisition, step S34: program replacement, step S35: verification, step S36: second operation, step S37: fifth judgment, step S38: first calculation and step S39: sixth judgment.

[0079] Step S31: setting breakpoints, presetting multiple key positions in the PLC program as breakpoints, so as to accurately control the debugging process, the number n of the breakpoints is less than the number of code lines in the PLC program, and greater than the number of data blocks included in the PLC program. The multiple key positions in the PLC program include: the start and end points of the data block, the beginning and / or end of the key code line, etc.

[0080] The step S32: writing a replacement program includes step S321: first backup, step S322: first programming, step S323: interface matching and step S324: program storage.

[0081] The step S321: first backup includes step S3211: data block identification, step S3212: separate backup and step S3213: version control.

[0082] Step S3211: Data block identification, identifying all data blocks in the PLC program, including input / output data blocks, internal variable data blocks, configuration parameter data blocks, etc.

[0083] Step S3212: Perform separate backup for each data block to ensure the integrity and independence of each data block. The backup of the data block can be stored in a local hard disk, a network server or a cloud storage for subsequent recovery or reference.

[0084] Step S3213: Version control, adding version control information to each backed up data block, such as timestamp, modifier, modification content summary, etc., for tracking and management.

[0085] The step S322: first programming, includes step S3221: requirement analysis and step S3222: replacement program writing.

[0086] Step S3221: Requirements analysis, based on the functions of the data blocks and the overall logic of the PLC program, analyze the role and replacement requirements of each data block in the PLC program, the replacement requirements include: program coding structure, variable naming format, interface type, etc.

[0087] Step S3222: Write a replacement program. For each data block, write a corresponding replacement program according to the replacement requirements. The replacement program can simulate or replace the function of the original data block and is easy to debug and modify.

[0088] The step S323: interface matching includes step S3231: defining the interface and step S3232: data mapping.

[0089] Step S3231: clarify the interface, clarify the input / output interface data of each data block and replacement program, and the input / output interface data includes the interface number, transmission mode, etc.

[0090] Step S3232: Data mapping, establishing a mapping relationship between the input / output interface data of the data block and the replacement program to ensure that the data can be correctly transmitted and converted, and assigning the input / output interface data of the data block to the input / output interface data of the replacement program.

[0091] The step S324: program storage includes step S3241: creating a function library, step S3242: encapsulation and packaging, and step S3243: version management.

[0092] Step S3241: Create a function library. Create an independent function library for all replacement programs of each data block. The function library should contain all necessary functions, modules and interface definitions.

[0093] Step S3242: Encapsulation and packaging: encapsulating the replacement program and its dependent library files, configuration files, etc. into an independent package for easy deployment and distribution.

[0094] Step S3243: Version management, adding version control information to the function library, such as version number, release date, modification content, etc., for easy management and updating.

[0095] Step S33: first acquisition, acquiring a replacement program between the ith breakpoint and the (i+1)th breakpoint, and recording the replacement program as a first program.

[0096] Step S34: Program replacement, using the Hook mechanism, dynamically replace the program code fragment between the i-th breakpoint and the i+1-th breakpoint in the PLC program to debug different logic branches or fix potential problems.

[0097] A Hook point is added after the i-th breakpoint, that is, a Hook function is added after the i-th breakpoint, jumps to the address of the replacement program, and executes the first program to replace the behavior after the i-th breakpoint in the PLC program.

[0098] Through the Inline Hook technology, the i-th breakpoint in the PLC program is located, and a Hook function is inserted after the i-th breakpoint to jump to the replacement program, so that the replacement program is injected between the i-th breakpoint and the i+1-th breakpoint to obtain the second program.

[0099] The step S35: checking includes step S351: third judgment and step S352: calling.

[0100] Step S351: the third judgment, judging step S34: whether the first program successfully replaces the data block in the PLC program during program replacement, if so, executing step S21: the first judgment; if not, executing step S352: calling.

[0101] The first program successfully replaces the data block in the PLC program. The judgment indicators are: the signature of the new program, the startup log of the program, running a simple debugging case, etc. If all the judgment indicators are correct, it means the replacement is successful; otherwise, it means the replacement fails.

[0102] Step S352: call, review step S321: the data blocks backed up in the first backup, these data blocks contain the complete state of the first program before the replacement operation; use the backed up data blocks to replace the current first program, involving program recovery, memory rollback and other operations; after the data block replacement is completed, re-execute step S33: first acquisition. The purpose of this step is to restore the first program to its original state to avoid more serious problems in the system or application.

[0103] Step S36: The second operation adopts a single-step execution mode, using commands such as "Step Into", "Step Over" or "Step Out" to debug the program of each data block and obtain the operation results.

[0104] After each step is executed, carefully observe the values ​​of program variables, memory status, and whether the program behavior is as expected. Record the variable values, execution results, and any abnormal information of key steps for subsequent analysis and comparison.

[0105] Step S37: The fifth judgment, compare the operation result with the expected result to see whether they are the same or whether the output error between the two is within the allowable range. If so, execute step S38: the first calculation; if not, execute step S5: output.

[0106] Step S38: First calculation, let i=i+1, replace the next data block in step S34: program replacement, and execute step S39: sixth judgment.

[0107] Step S39: The sixth judgment, in step S38: the first calculation, after updating i, judge whether i is equal to n, that is, judge whether the current breakpoint is the last breakpoint in the PLC program. If so, execute step S5: output; if not, execute step S33: first acquisition, and replace the next data block.

[0108] like Figure 3 As shown, the step S4: setting includes step S41: fourth judgment and step S42: first setting.

[0109] Step S41: the fourth judgment, judging whether the virtual PLC needs to communicate with the debugging device in the virtual environment, if so, executing step S42: the first setting; if not, executing step S5: output.

[0110] The step S42: first setting includes step S421: setting the communication protocol, step S422: setting the client library, step S423: setting the virtual PLC, step S424: setting the client application, step S425: setting the virtual interface, step S426: second acquisition and step S427: data processing.

[0111] Step S421: Set the communication protocol and use the MQTT (Message Queuing Telemetry Transport) protocol as the communication protocol between the virtual PLC and the debugging device. MQTT is a lightweight message transmission protocol, which is particularly suitable for scenarios that require low power consumption and reliable communication, such as Internet of Things (IoT) applications.

[0112] Step S422: Set the client library, install and configure the MQTT client library on the virtual PLC. The MQTT client library will be responsible for processing the connection between the virtual PLC and the MQTT server, the sending and receiving of messages, and other tasks.

[0113] Step S423: Setting the virtual PLC, including step S4231: data publishing and step S4232: command receiving.

[0114] Step S4231: Data publishing, the virtual PLC periodically publishes status information to the specified topic of the MQTT server.

[0115] The status information includes:

[0116] Input signals of the virtual PLC: These input signals reflect the external inputs received by the virtual PLC, such as sensor readings, button status, etc., and are the basis for the virtual PLC to perform logical processing and calculations.

[0117] Output signals of the virtual PLC: These output signals represent the control output of the virtual PLC to external devices, such as motor control signals, indicator light status, etc., reflecting the response and control results of the virtual PLC to the external environment.

[0118] Internal status signals of the virtual PLC: These internal status signals provide detailed information about the internal operating status of the virtual PLC, such as program execution status, error codes, internal variable values, etc. The internal status signals are the basis for debugging and fault diagnosis.

[0119] By publishing the status information of the virtual PLC to the specified topic of the MQTT server, any client that has subscribed to the topic can obtain the current status of the virtual PLC in real time, thereby realizing the monitoring and analysis of the virtual PLC debugging process.

[0120] Step S4232: Instruction reception, the virtual PLC is also responsible for receiving the control instruction topic published by the MQTT server. These control instructions come from external systems or users and are used to guide the behavior of the virtual PLC and the operation of the debugging device. When the virtual PLC receives the control instruction topic, it will parse the instruction content and perform corresponding operations according to the requirements of the instruction, such as changing the output signal state, adjusting parameter settings, etc.

[0121] In this way, external systems or users can remotely control the virtual PLC and realize automatic debugging. At the same time, due to the advantages of MQTT protocol such as low latency, high reliability and scalability, this control method is very suitable for application scenarios that require real-time response and high reliability.

[0122] Step S424: Set up the client application. Install a client application that supports the MQTT protocol on the debugging device. The application is responsible for connecting to the MQTT server and subscribing to the status information topic published by the virtual PLC. Configure the necessary connection parameters in the MQTT client application, such as the address, port number, user name, and password of the MQTT server. Configure the MQTT client application to subscribe to the topic of the virtual PLC publishing status information. When the virtual PLC publishes new status information, the MQTT server will push this information to the MQTT client application on the debugging device.

[0123] Step S425: Setting a virtual interface, and designing a layout of the virtual interface in the HMI development tool. The layout of the virtual interface includes determining which status information to display (such as input signals, output signals, internal status signals, etc.), and how to display the status information (such as charts, indicator lights, digital displays, etc.).

[0124] Connect the virtual interface with the MQTT client application and the virtual PLC (HMI development tools support direct connection between the three) to obtain real-time status information from the data source (i.e., MQTT server or virtual PLC).

[0125] Write the interactive logic as needed, and users can interact with the virtual PLC through the virtual interface (such as sending control instructions, adjusting parameters, etc.). After completing the interface design and programming, perform sufficient debugging to ensure that the virtual interface can correctly display the status information of the virtual PLC and respond to user operations.

[0126] The interactive logic is written as required, including:

[0127] Clarify the requirements of the virtual interface, which include: the user needs to be able to start and stop a program or process of the virtual PLC, the user needs to be able to adjust a parameter in the virtual PLC, such as speed, temperature setting value, etc., the user needs to be able to monitor certain key states of the virtual PLC in real time, such as the state of input / output signals, internal error codes, etc.

[0128] Design virtual interfaces, including: placing controls such as buttons and switches to trigger control instructions, setting controls such as text boxes and sliders to enter or adjust parameter values, and using controls such as indicator lights and charts to display status information.

[0129] Write the interaction logic. In the HMI development tool, use the corresponding programming language or scripting language to write the interaction logic code. For example:

[0130] Send control instructions: When the user clicks a button, the virtual interface captures the click event and triggers a function or method to send a control instruction to the virtual PLC. This instruction is a message sent to the MQTT server via the MQTT protocol. The virtual PLC subscribes to the corresponding topic and receives the instruction.

[0131] Adjust parameters: When the user adjusts a parameter via a slider or text box, the virtual interface captures the change and sends the new parameter value to the virtual PLC, either via MQTT messages or by calling the virtual PLC’s API if the HMI tool supports direct connection to the virtual PLC.

[0132] Monitor status changes: For status information that needs to be monitored in real time, the virtual interface will subscribe to the corresponding topic on the MQTT server and update the display on the interface when new messages are received.

[0133] Step S426: Second acquisition, the debugging device sends the collected data to a specified MQTT topic (Topic) through the MQTT protocol, and the MQTT client library on the virtual PLC subscribes to the topic to receive and process the data.

[0134] Step S427: Data processing, after receiving the data, the virtual PLC performs necessary processing (such as analysis, calculation, conversion, etc.). After the data processing is completed, the operation results are displayed in the form of an operation report through step S5: output.

[0135] Step S5: output, including step S51: generating a report and step S52: result analysis.

[0136] Step S51: Generate a report, automatically generate a detailed virtual PLC operation report, the operation report includes debugging / operation overview, debugging steps, input signals, operation results, problem records and solution suggestions, etc.

[0137] Debug / Run Overview: Briefly describe the purpose, scope, environment configuration, and execution time period of the debug or run.

[0138] Debugging steps: List the execution process of each step of debugging or running in detail, including the debugging / running number, name, execution time, preconditions, operation steps, etc. These steps should be detailed enough so that others can reproduce the debugging or running process.

[0139] Input signal: records the input signal provided to the virtual PLC in each debugging step or operation stage, including the signal name, type, value and provision time.

[0140] Operation results: record the actual output or response results of the virtual PLC after each debugging step or operation stage, and the actual output or response results of the virtual PLC include the name, value, timestamp and any abnormal or error information of the output signal.

[0141] Problem record: Any problems encountered during debugging or operation should be recorded in detail, including the description of the problem, the time of occurrence, the scope of impact, and the initial judgment or speculation. For problems that have been solved, the solution and the time of solution should also be recorded.

[0142] Solution suggestions: Based on the recorded problems, specific solution suggestions or improvement plans are proposed based on expert experience. The solution suggestions or improvement plans can be based on the root cause of the problem.

[0143] Step S52: Result analysis: Analyze the performance and stability of the PLC program according to the report content to provide a basis for subsequent optimization and maintenance.

[0144] This embodiment provides a remote monitoring and debugging method based on PLC, by building a virtual environment including a virtual PLC, and configuring the environment parameters and the input signal of the virtual PLC. Subsequently, a double judgment is adopted: first, verify whether the PLC program logic meets expectations. If not, check the correctness of the input signal. If the input is correct, enter the detection step, use the breakpoint and Hook mechanism to replace the PLC program fragment to test a specific section, and run and verify the results through multiple iterations until all breakpoint areas are traversed or the problem is found. This method effectively improves the efficiency and accuracy of PLC program debugging, and finally outputs a detailed operation report, providing strong support for remote debugging.

[0145] Embodiment 2: This embodiment discloses a remote monitoring and debugging system based on PLC, and the debugging system comprises:

[0146] Build a virtual environment module. This module is responsible for building a virtual environment that includes a virtual PLC and debugging equipment. The virtual environment needs to simulate the real PLC operating environment, including necessary hardware interface simulation, communication protocol support, and operating system level simulation. Through the virtual environment, developers can test and debug PLC programs without actual hardware.

[0147] The configuration parameter module is used to configure the parameters of the virtual environment and set the input signal of the virtual PLC; the parameters of the virtual environment include device parameters, network delay, fault simulation, etc., to ensure that the virtual environment can be as close to the real operating environment as possible; the input signal includes sensor data, button signals, etc., to ensure that the virtual PLC can receive correct input information, and the input signal of the virtual PLC includes: the output signal of the debugging device.

[0148] The judgment module includes a first judgment unit and a second judgment unit.

[0149] The first judging unit is used to judge whether the virtual PLC runs according to the expected logic.

[0150] The second judging unit is used to judge whether the input signal of the virtual PLC is correct.

[0151] The program replacement module is used to set breakpoints in the PLC program and replace the PLC program between the breakpoints with a replacement program to obtain a second program.

[0152] The output module is used to organize all the data and information collected during the test into a running report and output the running report. The output module also supports exporting the report into multiple formats (such as PDF, Excel, etc.) for viewing and analysis.

[0153] The present embodiment provides a remote monitoring and debugging system based on PLC, which simulates the real operating environment for testing by building a virtual environment including a virtual PLC. The configuration parameter module flexibly configures the environmental parameters and input signals to ensure that the test conditions are accurate and controllable. The judgment module includes two judgment units, which are responsible for the original program logic verification, input signal correctness check, replacement program operation result evaluation and breakpoint traversal control. When the original program does not run as expected, the system automatically enters the replacement program test process, sets breakpoints in the PLC program through the program replacement module and jumps to run the replacement program, and uses the Hook mechanism to accurately replace and test specific areas until the problem is found or all breakpoint tests are completed. The present embodiment significantly improves the debugging efficiency of the PLC program, reduces manual intervention and reduces the error rate through automated testing and judgment processes.

[0154] Embodiment 3: The present application also provides a terminal, which is equipped with the PLC-based remote monitoring and debugging system. When the terminal is running, it is used to implement the PLC-based remote monitoring and debugging method.

[0155] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, any equivalent changes made according to the structure, shape, and principle of the present application should be included in the protection scope of the present application.

Claims

1. A remote monitoring and debugging method based on PLC, characterized in that: include: Carrying out a virtual environment: establishing a virtual environment, wherein the virtual environment includes: a virtual PLC and a debugging device; Adopt modular programming to divide the PLC program into multiple data blocks according to the functions; Configuration parameters: configure the parameters of the virtual environment and set the input signal of the virtual PLC, the input signal of the virtual PLC includes: the output signal of the debugging device; First judgment: judging whether the virtual PLC runs according to the expected logic, if yes, executing the output step; if no, executing the second judgment step; Second judgment: judging whether the input signal of the virtual PLC is correct, if so, executing the detection step; if not, executing the parameter configuration step; Detection: including setting breakpoints, first acquisition, program replacement, second operation, fifth judgment, first calculation and sixth judgment; Set breakpoints: Set n breakpoints in the PLC program of the virtual PLC; First acquisition: obtain the replacement program between the i-th breakpoint and the i+1-th breakpoint, recorded as the first program; Program replacement: Using the Hook mechanism, the program between the i-th breakpoint and the i+1-th breakpoint of the PLC program is replaced with the first program; Second run: Use single-step execution to debug the program of each data block and obtain the running results; Fifth judgment: compare the running result with the expected result to see whether they are the same or whether the output error between the two is within the allowable range. If yes, execute the first calculation step; if no, execute the output step; First calculation: let i=i+1, and execute the sixth judgment step; Sixth judgment: judge whether i is equal to n, if yes, execute the output step; if no, execute the first acquisition step; After the detection step and before the output step, it also includes: Fourth judgment: judging whether the virtual PLC needs to communicate with the debugging device in the virtual environment, if yes, executing the first setting step; if no, executing the output step; First setting: including setting the communication protocol, setting the client library, and the second acquisition and data processing steps; Set the communication protocol: Set the virtual PLC to communicate with the debugging device via the MQTT protocol; Set up client library: Set up the MQTT client library on the virtual PLC; Data publishing: The virtual PLC periodically publishes status information to the specified topic of the MQTT server, and the status information includes: the input signal of the virtual PLC, the output signal of the virtual PLC, and the internal status signal of the virtual PLC; Instruction reception: The virtual PLC receives the control instruction topic published by the MQTT server, and controls the debugging device according to the received control instruction topic; Set up client application: Set up the MQTT client application on the debugging device to connect to the MQTT server and subscribe to the topic of virtual PLC status information; Set up virtual interface: Develop virtual interface through HMI development tool to display the status information of virtual PLC; Second acquisition: The debugging device forwards the collected data to the corresponding MQTT client library through the MQTT protocol; Data processing: After the virtual PLC processes the data, it displays the processed data through the output step; Output: Generate and output the operation report of the virtual PLC.

2. The PLC-based remote monitoring and debugging method according to claim 1, characterized in that: After executing the breakpoint setting step and before executing the first acquisition step, the method further includes: First backup: back up each data block in the PLC program separately; First programming: write replacement programs according to each data block in the PLC program; Interface matching: assigning the input / output interface data in each data block to the input / output interface data of the replacement program; Program storage: Encapsulate the replacement program of a data block in a function library.

3. The PLC-based remote monitoring and debugging method according to claim 2 is characterized in that: The program replacement step also includes: Third judgment: judging whether the first program is replaced successfully, if so, executing the first judgment step; if not, executing the calling step; Calling: replacing the first program with the data blocks backed up in the first backup step, and executing the first acquisition step.

4. The PLC-based remote monitoring and debugging method according to claim 3 is characterized in that: The number n of the breakpoints is smaller than the number of lines of code in the PLC program, and larger than the number of data blocks included in the PLC program.

5. A remote monitoring and debugging system based on PLC, the debugging system is applicable to the debugging method according to any one of claims 1 to 4, characterized in that: include: Building a virtual environment module for establishing a virtual environment, wherein the virtual environment includes: a virtual PLC and a debugging device; A configuration parameter module is used to configure the parameters of the virtual environment and set the input signal of the virtual PLC, wherein the input signal of the virtual PLC includes: an output signal of the debugging device; A judgment module, comprising a first judgment unit and a second judgment unit; A first judging unit, used to judge whether the virtual PLC operates according to the expected logic; A second judging unit is used to judge whether the input signal of the virtual PLC is correct; A program replacement module, used for setting breakpoints in the PLC program and replacing the PLC program between the breakpoints with a replacement program to obtain a second program; Output module, generates and outputs the operation report of the virtual PLC.

6. A terminal equipped with the debugging system according to claim 5, characterized in that: When running, the terminal is used to implement the debugging method according to any one of claims 1 to 4.