CN118642426B - Remote monitoring and debugging method, system and terminal based on PLC - Google Patents
Remote monitoring and debugging method, system and terminal based on PLC Download PDFInfo
- Publication number
- CN118642426B CN118642426B CN202411123826.7A CN202411123826A CN118642426B CN 118642426 B CN118642426 B CN 118642426B CN 202411123826 A CN202411123826 A CN 202411123826A CN 118642426 B CN118642426 B CN 118642426B
- Authority
- CN
- China
- Prior art keywords
- plc
- program
- virtual
- debugging
- setting
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000000034 method Methods 0.000 title claims abstract description 64
- 238000012544 monitoring process Methods 0.000 title claims abstract description 33
- 238000001514 detection method Methods 0.000 claims abstract description 8
- 230000006870 function Effects 0.000 claims description 29
- 230000008569 process Effects 0.000 claims description 29
- 230000006854 communication Effects 0.000 claims description 13
- 238000004891 communication Methods 0.000 claims description 13
- 238000012545 processing Methods 0.000 claims description 10
- 238000004364 calculation method Methods 0.000 claims description 9
- 238000011161 development Methods 0.000 claims description 9
- 230000007246 mechanism Effects 0.000 claims description 7
- 230000000875 corresponding effect Effects 0.000 description 10
- 238000004458 analytical method Methods 0.000 description 8
- 238000012360 testing method Methods 0.000 description 8
- 238000012986 modification Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 5
- 238000007726 management method Methods 0.000 description 4
- 238000004088 simulation Methods 0.000 description 4
- 238000012795 verification Methods 0.000 description 4
- 230000006399 behavior Effects 0.000 description 3
- 230000005540 biological transmission Effects 0.000 description 3
- 230000003993 interaction Effects 0.000 description 3
- 230000002452 interceptive effect Effects 0.000 description 3
- 238000004519 manufacturing process Methods 0.000 description 3
- 230000004044 response Effects 0.000 description 3
- 230000008859 change Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000009191 jumping Effects 0.000 description 2
- 238000012423 maintenance Methods 0.000 description 2
- 238000013507 mapping Methods 0.000 description 2
- 238000004806 packaging method and process Methods 0.000 description 2
- 238000002360 preparation method Methods 0.000 description 2
- 230000008439 repair process Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000007175 bidirectional communication Effects 0.000 description 1
- 238000006243 chemical reaction Methods 0.000 description 1
- 230000001276 controlling effect Effects 0.000 description 1
- 238000013506 data mapping Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000003745 diagnosis Methods 0.000 description 1
- 238000009826 distribution Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000007613 environmental effect Effects 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000009776 industrial production Methods 0.000 description 1
- 239000003607 modifier Substances 0.000 description 1
- 238000005457 optimization Methods 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 238000003860 storage Methods 0.000 description 1
Abstract
The application provides a remote monitoring and debugging method, a remote monitoring and debugging system and a remote monitoring and debugging terminal based on a PLC (programmable logic controller), and relates to the technical field of remote debugging of PLC programs, wherein the debugging method comprises the steps of carrying a virtual environment, configuring parameters, first judgment, second judgment, detection, output and the like; the debugging system comprises a virtual environment setting up module, a parameter configuration module, a judging module, a program replacing module and an output module. The whole flow of the application comprises a plurality of automatic judging and executing steps, such as breakpoint setting, program replacement, first acquisition and the like, so that the manual intervention is reduced, and the debugging efficiency is improved.
Description
Technical Field
The application relates to the technical field of remote debugging of PLC programs, in particular to a remote monitoring and debugging method, system and terminal based on PLC.
Background
With the rapid development of industrial automation technology, programmable Logic Controllers (PLCs) play a vital role in industrial production. However, the conventional PLC development, debugging and debugging process often depends on the actual hardware device, and the PLC program needs to be debugged in the factory where the hardware device is located, which not only increases the development cost, but also has the limitation of the geographical location.
The invention discloses a method and a system for debugging a configuration program of a PLC (programmable logic controller) by judging whether the current instruction line is an effective stop line or not, controlling the running state of the program and realizing remote debugging of the PLC, wherein the publication date is 12 days of 05 months in 2020 and the publication number is CN 111142469A. In the debugging process of the PLC program, a developer is required to add debugging information one by one in a code line, a first function determines whether a current instruction line is an effective stop line or not based on information sent by debugging equipment, judges whether to continue running the current instruction line, adds the debugging information to each code line, and judges whether to continue running the code line one by one according to the debugging information, wherein the debugging process is time-consuming and error-prone.
Disclosure of Invention
In order to improve debugging efficiency and accuracy, the application provides a remote monitoring debugging method, a remote monitoring debugging system and a remote monitoring debugging terminal based on a PLC.
In a first aspect, the application provides a remote monitoring and debugging method based on a PLC, which adopts the following technical scheme:
A remote monitoring and debugging method based on PLC comprises the following steps:
carrying a virtual environment: establishing a virtual environment, the virtual environment comprising: virtual PLC and debugging equipment;
Configuration parameters: configuring parameters of a virtual environment, and setting input signals of a virtual PLC, wherein the input signals of the virtual PLC comprise: an output signal of the commissioning device;
first judgment: judging whether the virtual PLC operates according to expected logic, if so, executing an output step; if not, executing a second judging step;
And (3) second judgment: judging whether the input signal of the virtual PLC is correct or not, if so, executing a detection step; if not, executing the step of configuring parameters;
and (3) detection: setting a breakpoint, first acquisition and program replacement;
Setting a breakpoint: setting n breakpoints in a PLC program of the virtual PLC;
First acquisition: acquiring a replacement program between an ith breakpoint and an (i+1) th breakpoint, and marking the replacement program as a first program;
Program replacement: replacing a program between an ith breakpoint and an (i+1) th breakpoint of the PLC program with a first program by adopting a Hook mechanism, and executing a first judging step;
and (3) outputting: and generating and outputting an operation report of the virtual PLC.
By adopting the technical scheme, the application uses the Hook mechanism to replace programs, can rapidly verify whether different code segments are correct, can timely find out which code segment is wrong, and reduces the time of manual modification and searching error codes line by line. The application comprises a plurality of automatic judging and executing steps, such as breakpoint setting, program replacement, first acquisition and the like, reduces manual intervention and improves debugging efficiency. By outputting the operation report, each step and each result in the debugging process can be recorded in detail, so that the follow-up analysis and problem positioning are facilitated. The application builds the virtual environment and performs debugging in the virtual environment, thereby reducing the influence on the actual production system and improving the debugging safety. The virtual environment allows for rapid configuration and modification of parameters of the virtual environment, sets input signals of the virtual PLC, and can conveniently debug the performance of the PLC program in different scenarios by simulating the feedback state of the debugging device in the virtual environment.
Optionally, using modular programming to divide the PLC program into a plurality of data blocks according to the function; and debugging the program of each data block in a single-step execution mode.
By adopting the technical scheme, the PLC program is divided into the plurality of data blocks, each data block corresponds to a specific function in the PLC program, the program can be replaced by the form of the data block in the program replacing step, when a certain function needs to be modified or updated, the related data block is only needed to be concerned, the whole PLC program does not need to be modified in a large scale, the same or similar function can be reused in the PLC programs of different projects, and the workload of repeated programming is reduced. The program of each data block is debugged in a single-step execution mode, a developer can accurately control the execution flow of the program, gradually observe the values of variables in the data blocks and the output of the program, compare the values of the variables and the output of the program in the running process, help the developer analyze error reasons, and determine whether the problem is in a specific part of the data blocks or in interaction among the data blocks. The application adopts the modularized programming and the single-step execution mode, can debug and verify the correctness and reliability of the PLC program more efficiently, not only improves the debugging precision and efficiency, but also improves the maintainability and expandability of the PLC program.
Optionally, after the step of setting the breakpoint is performed, before the step of performing the first obtaining, the method further includes:
First backup: backing up each data block in the PLC program independently;
First programming: writing a replacement program according to each data block in the PLC program;
interface matching: assigning input/output interface data in each data block to input/output interface data of the replacement program;
Program storage: the replacement procedure for a block of data is encapsulated in a library of functions.
By adopting the technical scheme, before the PLC program replacement is executed, each data block of the PLC is independently backed up, and in the debugging process, if an unpredictable problem occurs, the PLC program can be quickly restored to the original PLC program. Corresponding replacement programs are written according to the data blocks in the PLC program, and the replacement programs are used for temporarily replacing all codes in the original data blocks in the debugging process so as to verify specific functions or repair potential problems. The application assigns the input/output interface data in each data block to the input/output interface data of the replacement program, thereby ensuring that the replacement program can correctly interact with other parts of the PLC program. The application is convenient to manage and reuse the replacement programs by packaging all the replacement programs of one data block in one function library, wherein the function library comprises a plurality of replacement programs, each program corresponds to a specific data block or function, and the corresponding replacement program can be selected for loading and executing according to the need in the debugging process. The application encapsulates the replacement program in the function library, which is also helpful for keeping the codes clean and orderly, and is convenient for subsequent maintenance and upgrading.
Optionally, in the program replacing step, further includes:
Third judgment: judging whether the first program is replaced successfully, if so, executing a first judging step; if not, executing the calling step;
Calling: and replacing the first program by the data blocks backed up in the first backup step, and executing the first acquisition step.
By adopting the technical scheme, after the program replacement step, the application sets a third judgment step for judging whether the program replacement is successful, and if the replacement operation is successfully completed, the first judgment step is executed, namely: and using the replaced program to perform further debugging or running. If the replacement operation is not successfully completed, such as an error exists in the replacement program, an interrupt or conflict occurs in the replacement process, and the like, a calling step needs to be executed to restore the original state. And after the original state is restored, the first acquisition step is re-executed, the replacement program is re-acquired, and the data block in the PLC program is replaced again. Through the third judging step and the calling step, the application can further ensure the replacement accuracy and improve the flexibility and controllability of the debugging process.
Optionally, the number n of the breakpoints is smaller than the number of lines of codes in the PLC program and is greater than the number of data blocks included in the PLC program.
By adopting the technical scheme, the breakpoint is flexibly set in the debugging process of the PLC program, so that a developer can control the debugging process more accurately, and the potential problem can be positioned and solved quickly. The number n of the breakpoints is smaller than the number of code lines in the PLC program, and the fact that a developer cannot set a breakpoint after each line of codes, the problem that the program runs too slowly or is debugged too slowly due to too many breakpoints is solved, the number n of the breakpoints is larger than the number of data blocks contained in the PLC program, that is, the number n of the breakpoints is set at the beginning and the end of each data block, each PLC data block can be independently debugged, and two data blocks cannot be debugged at the same time.
Optionally, after the program detection step is performed, before the output step is performed, the method further includes:
Fourth judgment: judging whether the virtual PLC needs to communicate with debugging equipment in the virtual environment, if so, executing a first setting step; if not, executing the output step;
a first setting: the method comprises the steps of setting a communication protocol, setting a client library, and second acquisition and data processing;
Setting a communication protocol: setting the virtual PLC and the debugging equipment to communicate through an MQTT protocol;
Setting a client library: setting an MQTT client library on the virtual PLC;
Second acquisition: the debugging equipment forwards the acquired data to a corresponding MQTT client library through an MQTT protocol;
And (3) data processing: after the virtual PLC processes the data, the processed data is displayed through an output step.
By adopting the technical scheme, the application can intelligently determine whether the virtual PLC needs to communicate with the debugging equipment according to the current environment or the requirement by setting the fourth judging step, thereby reducing unnecessary resource consumption or error operation. The application adopts the MQTT protocol for communication, and the MQTT protocol is a lightweight message transmission protocol, has the characteristics of low bandwidth, low power consumption and high reliability, and is suitable for data exchange among devices. And setting an MQTT client library on the virtual PLC so that the virtual PLC can be used as an MQTT client to communicate with the debugging equipment. Data is acquired from the debugging equipment through the MQTT protocol and is processed in the virtual PLC, and the process ensures the accuracy and the instantaneity of the data.
Optionally, after the step of setting the client library is performed, before the step of performing the second obtaining, the method further includes:
And (3) data release: the virtual PLC periodically publishes state information to a specified topic of the MQTT server, the state information comprising: an input signal of the virtual PLC, an output signal of the virtual PLC, and an internal state signal of the virtual PLC;
And (3) receiving an instruction: the virtual PLC receives the control instruction theme issued by the MQTT server and controls the debugging equipment according to the received control instruction theme.
By adopting the technical scheme, the virtual PLC periodically issues the state information to the appointed theme of the MQTT server, so that the state synchronization between the virtual PLC and the debugging equipment or other monitoring systems is realized, and the debugging equipment can acquire the latest state of the virtual PLC by updating the state information in real time, thereby performing corresponding actions. The virtual PLC can receive the control instruction subject issued by the MQTT server and control the debugging equipment according to the instructions, so that the remote control function of the debugging equipment is realized, and the flexibility and the automation degree of the system are improved.
Optionally, after the instruction receiving step is performed, before the second obtaining step is performed, the method further includes:
setting a client application: setting an MQTT client application on the debugging equipment, wherein the MQTT client application is used for connecting an MQTT server and subscribing a theme of virtual PLC state information;
Setting a virtual interface: and developing a virtual interface through the HMI development tool, and displaying the state information of the virtual PLC.
By adopting the technical scheme, the MQTT client application is arranged on the debugging equipment, so that the debugging equipment can be actively connected to the MQTT server and subscribe the subject of the virtual PLC state information, and therefore, the debugging equipment can receive and process the state information issued by the virtual PLC in real time, and the bidirectional communication between the debugging equipment and the virtual PLC is realized. Through the MQTT protocol for communication, each debugging device can be easily integrated with other devices or systems following the MQTT protocol, so that flexibility and expandability are enhanced. The virtual interface is developed through the HMI development tool, the state information of the virtual PLC is displayed to a developer in an intuitive and friendly mode, the developer is helped to quickly know the running condition of the virtual PLC, and corresponding operation or decision is carried out through the virtual interface.
In a second aspect, the application provides a remote monitoring and debugging system based on a PLC, which adopts the following technical scheme:
A PLC-based remote monitoring and debugging system, comprising:
building a virtual environment module for building a virtual environment, the virtual environment comprising: virtual PLC and debugging equipment;
The configuration parameter module is used for configuring parameters of the virtual environment and setting input signals of the virtual PLC, wherein the input signals of the virtual PLC comprise: an output signal of the commissioning device;
The judging module comprises a first judging unit and a second judging unit;
The first judging unit is used for judging whether the virtual PLC operates according to expected logic;
The second judging unit is used for judging whether the input signal of the virtual PLC is correct or not;
The program replacing module is used for setting breakpoints in the PLC program and replacing the PLC program between the breakpoints by adopting the replacing program to obtain a second program;
and the output module is used for generating and outputting an operation report of the virtual PLC.
By adopting the technical scheme, the virtual environment module is constructed to be responsible for creating a virtual environment containing the virtual PLC, configuring hardware and software resources in the virtual environment, ensuring that the hardware and the software resources can simulate the running environment of the actual PLC, and providing a developer interface or an API interface so that a developer can conveniently configure and manage the virtual environment. The configuration parameter module allows a user to configure various parameters of the virtual environment and set input signals of the virtual PLC, and simulates data input of an external sensor or equipment. The judging module comprises a plurality of judging units and is used for carrying out real-time monitoring and judgment in the running process of the program. The program replacement module can automatically or manually set breakpoints in the PLC program, allows a developer to upload or write a replacement program for replacing the PLC program between the breakpoints, performs replacement operation, and generates and stores a second program so as to perform further debugging or verification.
In a third aspect, the present application provides a terminal, which adopts the following technical scheme:
The terminal is provided with the remote monitoring and debugging system based on the PLC, and the terminal is used for realizing the remote monitoring and debugging method based on the PLC when in operation.
In summary, the present application includes at least one of the following beneficial technical effects:
1. The application uses the Hook mechanism to replace the program, can rapidly verify whether different code segments are correct, and can timely find out which code segment has errors, thereby reducing the time of manual modification and searching error codes line by line. The application comprises a plurality of automatic judging and executing steps, such as breakpoint setting, program replacement, first acquisition and the like, reduces manual intervention and improves debugging efficiency. By outputting the operation report, each step and each result in the debugging process can be recorded in detail, so that the follow-up analysis and problem positioning are facilitated. The application builds the virtual environment and performs debugging in the virtual environment, thereby reducing the influence on the actual production system and improving the debugging safety. The virtual environment allows for rapid configuration and modification of parameters of the virtual environment, sets input signals of the virtual PLC, and can conveniently debug the performance of the PLC program in different scenarios by simulating the feedback state of the debugging device in the virtual environment.
2. According to the application, the PLC program is divided into a plurality of data blocks, each data block corresponds to a specific function in the PLC program, the program can be replaced in the program replacing step in a data block mode, when a certain function needs to be modified or updated, only the relevant data block is needed to be concerned, the whole PLC program does not need to be modified in a large scale, the same or similar function can be reused in the PLC programs of different projects, and the workload of repeated programming is reduced. The program of each data block is debugged in a single-step execution mode, a developer can accurately control the execution flow of the program, gradually observe the values of variables in the data blocks and the output of the program, compare the values of the variables and the output of the program in the running process, help the developer analyze error reasons, and determine whether the problem is in a specific part of the data blocks or in interaction among the data blocks. The application adopts the modularized programming and the single-step execution mode, can debug and verify the correctness and reliability of the PLC program more efficiently, not only improves the debugging precision and efficiency, but also improves the maintainability and expandability of the PLC program.
3. According to the application, by setting the fourth judging step, whether the virtual PLC needs to communicate with the debugging equipment or not can be intelligently determined according to the current environment or the requirement, so that unnecessary resource consumption or error operation is reduced. The application adopts the MQTT protocol for communication, and the MQTT protocol is a lightweight message transmission protocol, has the characteristics of low bandwidth, low power consumption and high reliability, and is suitable for data exchange among devices. And setting an MQTT client library on the virtual PLC so that the virtual PLC can be used as an MQTT client to communicate with the debugging equipment. Data is acquired from the debugging equipment through the MQTT protocol and is processed in the virtual PLC, and the process ensures the accuracy and the instantaneity of the data.
4. The set up virtual environment module is responsible for creating a virtual environment containing a virtual PLC, configuring hardware and software resources in the virtual environment, ensuring that they can simulate the running environment of an actual PLC, and providing a developer interface or API interface so that a developer can conveniently configure and manage the virtual environment. The configuration parameter module allows a user to configure various parameters of the virtual environment and set input signals of the virtual PLC, and simulates data input of an external sensor or equipment. The judging module comprises a plurality of judging units and is used for carrying out real-time monitoring and judgment in the running process of the program. The program replacement module can automatically or manually set breakpoints in the PLC program, allows a developer to upload or write a replacement program for replacing the PLC program between the breakpoints, performs replacement operation, and generates and stores a second program so as to perform further debugging or verification.
Drawings
FIG. 1 is a flow chart of a remote monitoring and debugging method based on a PLC of the application;
fig. 2 is a step S3 of the present application: a method flow chart of the detection;
fig. 3 is a step S4 of the present application: a set method flow chart.
Detailed Description
The application is described in further detail below in connection with fig. 1 to 3.
Example 1: the embodiment discloses a remote monitoring and debugging method based on a PLC, and referring to FIG. 1, the debugging method comprises the following steps: step S1: early preparation, step S2: judging and step S3: detecting and S4: setting and step S5: the method comprises the steps of firstly setting a virtual environment, setting parameters of the virtual environment and input signals of a virtual PLC, judging whether the virtual PLC operates according to expected logic, judging whether the input signals of the virtual PLC are correct, replacing a program, judging whether a replaced second program can operate according to the expected, and outputting an operation report if so, otherwise, replacing and debugging a data block after the next breakpoint, and outputting an operation report, wherein the remote monitoring and debugging method comprises the following steps:
The step S1: early preparation, comprising the step S11: carrying a virtual environment and a step S12: and (5) configuring parameters.
Step S11: carrying out virtual environment, and constructing a virtual environment containing a complete industrial control flow by using professional simulation software or a cloud platform, wherein the virtual environment comprises a virtual PLC and debugging equipment. The virtual environment is required to simulate hardware configuration, network topology and communication protocol in the actual production scene, so that the debugging environment is ensured to be close to the actual application.
And installing PLC programming software and necessary debugging tools in the virtual environment to ensure that all components are compatible and stably operate.
Through modularized programming, the PLC program is divided into a plurality of data blocks according to functions.
And loading the written data blocks into the virtual PLC, and performing preliminary running debugging to verify whether the basic functions of the PLC program are realized.
Step S12: and configuring parameters, namely configuring various parameters of the virtual environment in detail, such as equipment parameters, network delay, fault simulation and the like, according to debugging requirements. Simulating external input signals, including sensor data, button signals, etc., to ensure that the virtual PLC is able to receive the correct input information, the input signals of the virtual PLC comprising: an output signal of the commissioning device.
The step S2: the judgment comprises the following step S21: first judgment and step S22: and (5) second judgment.
Step S21: the first judgment is carried out, whether the virtual PLC operates according to expected logic is judged, if yes, step S5 is executed: outputting; if not, step S22 is executed: and (5) second judgment.
Step S22: and judging whether the input signal of the virtual PLC is correct or not. If the input signal is correct, step S3 is executed: detecting; if the input signal is wrong, the process returns to step S13: and configuring parameters and adjusting input signals.
As shown in fig. 2, the step S3: the detection includes step S31: setting a breakpoint, step S32: writing a replacement program, and step S33: first acquisition, step S34: program replacement, step S35: checking, step S36: second operation, step S37: fifth judgment, step S38: first calculation and step S39: and sixth judgment.
Step S31: setting break points, and presetting a plurality of key positions in a PLC program as the break points so as to accurately control the debugging flow, wherein the number n of the break points is smaller than the number of code lines in the PLC program and larger than the number of data blocks contained in the PLC program. The plurality of key positions in the PLC program include: at the start and end of a data block, at the beginning and/or end of a key code line, etc.
The step S32: writing a replacement program, including step S321: first backup, step S322: first programming, step S323: interface matching and step S324: and (5) program storage.
The step S321: a first backup comprising step S3211: data block identification, step S3212: separate backup and step S3213: version control.
Step S3211: and identifying data blocks, namely identifying all the data blocks in the PLC program, including input/output data blocks, internal variable data blocks, configuration parameter data blocks and the like.
Step S3212: and independently backing up each data block, and ensuring the integrity and independence of each data block, wherein the backing up of the data blocks can be stored in a local hard disk, a network server or cloud storage for subsequent recovery or reference.
Step S3213: version control, adding version control information such as time stamps, modifiers, modified content summaries, etc. to the data blocks of each backup for tracking and management.
The step S322: first programming, including step S3221: requirement analysis and step S3222: and (5) writing an alternative program.
Step S3221: requirement analysis, analyzing the role and replacement requirements of each data block in the PLC program based on the functions of the data block and the overall logic of the PLC program, wherein the replacement requirements comprise: program code structure, variable naming form, interface type, etc.
Step S3222: and writing a replacement program, namely writing a corresponding replacement program according to the replacement requirement for each data block. The replacement program can simulate or replace the function of the original data block, and is convenient for debugging and modification.
The step S323: interface matching, including step S3231: explicit interface and step S3232: and (5) data mapping.
Step S3231: and (3) defining an interface, and defining input/output interface data of each data block and the replacement program, wherein the input/output interface data comprises interface numbers, transmission modes and the like.
Step S3232: and (3) mapping data, namely establishing a mapping relation of input/output interface data between the data block and the replacement program, ensuring that the data can be correctly transferred and converted, and giving the input/output interface data of the data block to the input/output interface data of the replacement program.
The step S324: program storage, comprising step S3241: creating a function library, step S3242: packaging and step S3243: version management.
Step S3241: a function library is created, which contains all necessary functions, modules and interface definitions, creating a separate function library for all replacement programs for each data block.
Step S3242: and the replacement program, the library files, the configuration files and the like which are depended on by the replacement program are packaged into an independent package, so that the replacement program is convenient to deploy and distribute.
Step S3243: version management, adding version control information such as version number, release date, modified content, etc. to the function library for management and update.
Step S33: and the first acquisition, namely acquiring a replacement program between the ith breakpoint and the (i+1) th breakpoint, and recording the replacement program as a first program.
Step S34: program replacement, namely dynamically replacing program code fragments between an ith breakpoint and an (i+1) th breakpoint in a PLC program by using a Hook mechanism so as to debug different logic branches or repair potential problems.
Adding a Hook point after the ith breakpoint, namely: and adding a Hook function after the ith breakpoint, jumping to the address of the replacement program, and executing the behavior of the first program after replacing the ith breakpoint in the PLC program.
Positioning an ith breakpoint in the PLC program by an Inline Hook technology, inserting a Hook function after the ith breakpoint, and jumping to a replacement program to realize that the replacement program is injected between the ith breakpoint and the (i+1) th breakpoint, so as to obtain a second program.
The step S35: the collation includes step S351: third judgment and step S352: and (5) calling.
Step S351: third judgment, judgment step S34: in the program replacement, if the first program successfully replaces the data block in the PLC program, step S21 is executed if yes: a first judgment; if not, then step S352 is executed: and (5) calling.
The judging index of whether the first program successfully replaces the data block in the PLC program is as follows: signature of new program, starting log of program, simple debugging case, etc. If all the judging indexes are correct, the replacement is successful; otherwise, the replacement failure is indicated.
Step S352: calling, reviewing step S321: the data blocks backed up in the first backup, the data blocks including the complete state of the first program prior to the replacement operation; replacing a current first program by using the backed-up data block, and relating to operations such as program recovery, memory rollback and the like; after the data block replacement is completed, step S33 is re-executed: and a first acquisition. The purpose of this step is to restore the first program to its original state, in order to avoid more serious problems with the system or the application.
Step S36: and secondly, adopting a single-Step execution mode, adopting commands such as 'single-Step in' (Step Into), 'single-Step skip' (Step Over) or 'single-Step Out' (Step Out), debugging the program of each data block, and obtaining an operation result.
After each step is performed, a careful observation is made as to whether the values of the program variables, the memory state, and the behavior of the program are in line with expectations. The values of the variables of the key steps, the results of the execution and any anomaly information are recorded for subsequent analysis and comparison.
Step S37: fifth, comparing the operation result with the expected result, comparing whether the operation result and the expected result are the same, or whether the output error of the operation result and the expected result is within the allowable range, if yes, executing step S38: a first calculation; if not, executing step S5: and outputting.
Step S38: first calculation, let i=i+1, in step S34: the next data block is replaced in the program replacement, and step S39 is performed: and sixth judgment.
Step S39: sixth judgment, in step S38: in the first calculation, after i is updated, whether i is equal to n or not is judged, namely whether the current breakpoint is the last breakpoint in the PLC program is judged, if yes, step S5 is executed: outputting; if not, step S33 is executed: and the first acquisition is performed to replace the next data block.
As shown in fig. 3, the step S4: the setting includes step S41: fourth judgment and step S42: a first setting.
Step S41: fourth, judging whether the virtual PLC needs to communicate with the debugging device in the virtual environment, if so, executing step S42: a first setting; if not, executing step S5: and outputting.
The step S42: the first setting includes step S421: setting a communication protocol, step S422: setting a client library, step S423: setting a virtual PLC, step S424: setting a client application, step S425: setting a virtual interface, step S426: second acquisition and step S427: and (5) data processing.
Step S421: a communication protocol is set, and MQTT (Message Queuing Telemetry Transport) protocol is used as the communication protocol between the virtual PLC and the debugging device. MQTT is a lightweight messaging protocol particularly suited for use in scenarios requiring low power consumption and reliable communications, such as internet of things (IoT) applications.
Step S422: and setting a client library, and installing and configuring an MQTT client library on the virtual PLC. The MQTT client library is responsible for processing tasks such as connection of the virtual PLC and the MQTT server, sending and receiving of messages and the like.
Step S423: setting the virtual PLC includes step S4231: data distribution and step S4232: and receiving an instruction.
Step S4231: and data is published, and the virtual PLC periodically publishes the state information to the appointed theme of the MQTT server.
The status information includes:
input signal of virtual PLC: these input signals reflect external inputs received by the virtual PLC, such as sensor readings, button status, etc., and are the basis for the virtual PLC to perform logic processing and calculations.
Output signal of virtual PLC: these output signals represent control outputs of the virtual PLC to the external device, such as motor control signals, status of indicator lights, etc., reflecting the response of the virtual PLC to the external environment and the control results.
Internal status signal of virtual PLC: these internal state signals provide detailed information of the internal operating state of the virtual PLC, such as program execution state, error codes, internal variable values, etc., which are the basis for debugging and fault diagnosis.
By publishing the state information of the virtual PLC to the appointed theme of the MQTT server, any client subscribed to the theme can acquire the current state of the virtual PLC in real time, so that the monitoring and analysis of the virtual PLC debugging process are realized.
Step S4232: the virtual PLC is also responsible for receiving control instruction topics issued by the MQTT server, wherein the control instructions are from an external system or a user and used for guiding the behavior of the virtual PLC and the operation of the debugging equipment. When the virtual PLC receives the control instruction theme, the instruction content is analyzed, and corresponding operations, such as changing the output signal state, adjusting parameter settings and the like, are executed according to the instruction requirement.
In this way, an external system or a user can remotely control the virtual PLC, so that automatic debugging is realized. Meanwhile, the MQTT protocol has the advantages of low delay, high reliability, expandability and the like, so that the control mode is very suitable for application scenes needing real-time response and high reliability.
Step S424: and setting a client application, and installing a client application program supporting the MQTT protocol on the debugging equipment, wherein the application program is responsible for connecting to the MQTT server and subscribing a state information theme published by the virtual PLC. Necessary connection parameters such as the address, port number, user name and password of the MQTT server are configured in the MQTT client application. The MQTT client application is configured to subscribe to the theme of the virtual PLC for releasing state information, and when the virtual PLC releases new state information, the MQTT server pushes the information to the MQTT client application on the debugging equipment.
Step S425: a virtual interface is set up, and a layout of the virtual interface is designed in the HMI development tool, where the layout of the virtual interface includes determining which state information (e.g., input signals, output signals, internal state signals, etc.) to display, and a display manner (e.g., chart, indicator light, digital display, etc.) of the state information.
The virtual interface is connected with the MQTT client application and the virtual PLC (HMI development tool support) so as to acquire real-time state information from a data source (namely the MQTT server or the virtual PLC).
According to the requirement, writing interactive logic, enabling a user to interact with the virtual PLC through the virtual interface (such as sending control instructions, adjusting parameters and the like), and fully debugging after interface design and programming are completed, so that the virtual interface can be ensured to correctly display state information of the virtual PLC, and responding to operation of the user.
The writing of the interaction logic according to the requirement comprises the following steps:
Defining requirements of a virtual interface, the requirements comprising: the user needs to be able to start and stop a certain program or process of the virtual PLC, the user needs to be able to adjust a certain parameter in the virtual PLC, such as a speed, a temperature set point, etc., the user needs to be able to monitor certain critical states of the virtual PLC, such as the state of input/output signals, internal error codes, etc., in real time.
Designing a virtual interface, comprising: and the control parts such as buttons, switches and the like are arranged and used for triggering control instructions, setting text boxes, sliding blocks and the like, inputting or adjusting parameter values, using indicator lamps, charts and the like and displaying state information.
Interactive logic is written, and in the HMI development tool, interactive logic code is written using a corresponding programming language or scripting language. For example:
And (3) sending a control instruction: when a user clicks a button, the virtual interface captures the click event and triggers a function or method to send control commands to the virtual PLC. This instruction is a message sent to the MQTT server via the MQTT protocol, and the virtual PLC subscribes to the corresponding topic and receives this instruction.
Adjusting parameters: when the user adjusts the parameters through the slider or text box, the virtual interface captures the change and sends the new parameter value to the virtual PLC, which can be implemented through MQTT messages or can directly call the API of the virtual PLC if the HMI tool supports direct connection to the virtual PLC.
Monitoring a state change: for state information to be monitored in real time, the virtual interface subscribes to the corresponding theme on the MQTT server and updates the display on the interface when a new message is received.
Step S426: the second acquisition, the debugging device sends the acquired data to the designated MQTT theme (Topic) via the MQTT protocol, which the MQTT client library on the virtual PLC subscribes to in order to receive and process the data.
Step S427: and (3) data processing, namely, after the virtual PLC receives the data, carrying out necessary processing (such as analysis, calculation, conversion and the like). After the data processing is completed, the operation result is in the form of an operation report, and the step S5 is performed: the output is displayed.
Step S5: output, comprising step S51: generating a report and step S52: and (5) analyzing results.
Step S51: generating reports, automatically generating detailed virtual PLC operation reports, wherein the operation reports comprise debugging/operation summaries, debugging steps, input signals, operation results, problem records, solution suggestions and the like.
Debug/run overview: the purpose, scope, environment configuration, and time period of execution of debugging or execution will be briefly described.
Debugging: the execution process of each step of debugging or running is detailed, including 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.
Input signal: the input signals provided to the virtual PLC in each debugging step or run phase are recorded, including the name, type, value and time of provision of the signals.
Operation results: the actual output or response results of the virtual PLC after each debugging step or run phase are recorded, including the name, value, time stamp of the output signal and any anomaly or error information.
Problem recording: any problems encountered during debugging or operation should be well documented, including description of the problem, time of occurrence, scope of impact, and preliminary judgment or speculation. For the problems that have been solved, solutions and solutions times should also be recorded.
Solution proposal: specific solutions or improvements are proposed for the recorded problem based on expert experience, which may be based on the root cause of the problem.
Step S52: and analyzing the result, namely analyzing the performance and the stability of the PLC program according to the report content, and providing a basis for subsequent optimization and maintenance.
The embodiment provides a remote monitoring and debugging method based on a PLC, which comprises the steps of constructing a virtual environment containing a virtual PLC and configuring environment parameters and input signals of the virtual PLC. Subsequently, a double judgment is adopted: firstly, verifying whether the logic of a PLC program accords with expectations or not, if not, checking the correctness of an input signal, if the input is correct, entering a detection step, replacing a PLC program segment by using a breakpoint and Hook mechanism to test a specific section, and performing operation and result verification through multiple iterations until all breakpoint areas are traversed or a problem is found. The method effectively improves the debugging efficiency and accuracy of the PLC program, and finally outputs detailed operation reports, thereby providing powerful support for remote debugging.
Example 2: the embodiment discloses remote monitoring debugging system based on PLC, the debugging system include:
And constructing a virtual environment module, wherein the module is responsible for constructing a virtual environment comprising a virtual PLC and debugging equipment. The virtual environment needs to simulate a real PLC operating environment, including the necessary hardware interface simulation, communication protocol support, and operating system level simulation. Through the virtual environment, a developer can test and debug the PLC program without actual hardware.
The configuration parameter module is used for configuring parameters of the virtual environment and setting input signals of the virtual PLC; parameters of the virtual environment include, for example, device parameters, network delay, fault simulation, etc., to ensure that the virtual environment is as close to a real operating environment as possible; the input signals include sensor data, button signals, etc., ensuring that the virtual PLC can receive the correct input information, the input signals of the virtual PLC include: an output signal of the commissioning device.
The judging module comprises a first judging unit and a second judging unit.
And the first judging unit is used for judging whether the virtual PLC operates according to expected logic.
And the second judging unit is used for judging whether the input signal of the virtual PLC is correct or not.
And the program replacing module is used for setting breakpoints in the PLC program and replacing the PLC program between the breakpoints by adopting the replacing program to obtain a second program.
And the output module is used for sorting all data and information collected in the test process into an operation report and outputting the operation report. The export module also supports exporting reports into a variety of formats (e.g., PDF, excel, etc.) for viewing and analysis.
The embodiment provides a remote monitoring and debugging system based on a PLC, which simulates a real running environment to test by building a virtual environment containing a virtual PLC. The configuration parameter module flexibly configures environmental parameters and input signals, and ensures accurate and controllable testing conditions. The judging module comprises two judging units which are respectively responsible for original program logic verification, input signal correctness checking, replacement program running result evaluation and breakpoint traversal control. When the running of the original program is not expected, the system automatically enters a test flow of a replacement program, a breakpoint is set in the PLC program through a program replacement module, the replacement program is jumped, a special area is accurately replaced and tested by using a Hook mechanism, and all the breakpoint tests are completed or the problem is found. According to the embodiment, the debugging efficiency of the PLC program is remarkably improved, manual intervention is reduced, and the error rate is reduced through an automatic testing and judging process.
Example 3: the application also provides a terminal which is provided with the remote monitoring and debugging system based on the PLC, and the terminal is used for realizing the remote monitoring and debugging method based on the PLC when in operation.
The above embodiments are not intended to limit the scope of the present application, so: all equivalent changes in structure, shape and principle of the application should be covered in the scope of protection of the application.
Claims (6)
1. The remote monitoring and debugging method based on the PLC is characterized by comprising the following steps of:
carrying a virtual environment: establishing a virtual environment, the virtual environment comprising: virtual PLC and debugging equipment;
Adopting modularized programming, dividing a PLC program into a plurality of data blocks according to functions;
Configuration parameters: configuring parameters of a virtual environment, and setting input signals of a virtual PLC, wherein the input signals of the virtual PLC comprise: an output signal of the commissioning device;
first judgment: judging whether the virtual PLC operates according to expected logic, if so, executing an output step; if not, executing a second judging step;
And (3) second judgment: judging whether the input signal of the virtual PLC is correct or not, if so, executing a detection step; if not, executing the step of configuring parameters;
and (3) detection: setting a breakpoint, first acquisition, program replacement, second operation, fifth judgment, first calculation and sixth judgment;
Setting a breakpoint: setting n breakpoints in a PLC program of the virtual PLC;
First acquisition: acquiring a replacement program between an ith breakpoint and an (i+1) th breakpoint, and marking the replacement program as a first program;
Program replacement: replacing a program between an ith breakpoint and an (i+1) th breakpoint of the PLC program with a first program by adopting a Hook mechanism;
second operation: debugging the program of each data block in a single-step execution mode to obtain an operation result;
Fifth judgment: comparing the operation result with the expected result, and comparing whether the operation result and the expected result are the same or whether the output error of the operation result and the expected result is within an allowable range, if so, executing a first calculation step; if not, executing the output step;
first calculation: let i=i+1, and execute the sixth judgment step;
sixth judgment: judging whether i is equal to n, if so, executing an output step; if not, executing a first acquisition step;
After the detecting step is performed, before the outputting step is performed, further comprising:
Fourth judgment: judging whether the virtual PLC needs to communicate with debugging equipment in the virtual environment, if so, executing a first setting step; if not, executing the output step;
a first setting: the method comprises the steps of setting a communication protocol, setting a client library, and second acquisition and data processing;
Setting a communication protocol: setting the virtual PLC and the debugging equipment to communicate through an MQTT protocol;
Setting a client library: setting an MQTT client library on the virtual PLC;
And (3) data release: the virtual PLC periodically publishes state information to a specified topic of the MQTT server, the state information comprising: an input signal of the virtual PLC, an output signal of the virtual PLC, and an internal state signal of the virtual PLC;
and (3) receiving an instruction: the virtual PLC receives a control instruction theme issued by the MQTT server and controls the debugging equipment according to the received control instruction theme;
setting a client application: setting an MQTT client application on the debugging equipment, wherein the MQTT client application is used for connecting an MQTT server and subscribing a theme of virtual PLC state information;
Setting a virtual interface: developing a virtual interface through an HMI development tool, and displaying state information of the virtual PLC;
Second acquisition: the debugging equipment forwards the acquired data to a corresponding MQTT client library through an MQTT protocol;
and (3) data processing: after the virtual PLC processes the data, the processed data is displayed through an output step;
and (3) outputting: and generating and outputting an operation report of the virtual PLC.
2. The PLC-based remote monitoring and debugging method of claim 1, further comprising, after performing the step of setting the breakpoint, before performing the first obtaining step:
First backup: backing up each data block in the PLC program independently;
First programming: writing a replacement program according to each data block in the PLC program;
interface matching: assigning input/output interface data in each data block to input/output interface data of the replacement program;
Program storage: the replacement procedure for a block of data is encapsulated in a library of functions.
3. The PLC-based remote monitoring and debugging method of claim 2, further comprising, in the program replacing step:
Third judgment: judging whether the first program is replaced successfully, if so, executing a first judging step; if not, executing the calling step;
Calling: and replacing the first program by 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 of claim 3, wherein the number n of breakpoints is smaller than the number of lines of codes in the PLC program and larger than the number of data blocks included in the PLC program.
5. A PLC-based remote monitoring and debugging system adapted for use in the debugging method of any of claims 1-4, comprising:
building a virtual environment module for building a virtual environment, the virtual environment comprising: virtual PLC and debugging equipment;
The configuration parameter module is used for configuring parameters of the virtual environment and setting input signals of the virtual PLC, wherein the input signals of the virtual PLC comprise: an output signal of the commissioning device;
The judging module comprises a first judging unit and a second judging unit;
The first judging unit is used for judging whether the virtual PLC operates according to expected logic;
The second judging unit is used for judging whether the input signal of the virtual PLC is correct or not;
The program replacing module is used for setting breakpoints in the PLC program and replacing the PLC program between the breakpoints by adopting the replacing program to obtain a second program;
and the output module is used for generating and outputting an operation report of the virtual PLC.
6. A terminal carrying a commissioning system according to claim 5, wherein the terminal is operable to implement the commissioning method of any one of claims 1-4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411123826.7A CN118642426B (en) | 2024-08-16 | Remote monitoring and debugging method, system and terminal based on PLC |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202411123826.7A CN118642426B (en) | 2024-08-16 | Remote monitoring and debugging method, system and terminal based on PLC |
Publications (2)
Publication Number | Publication Date |
---|---|
CN118642426A CN118642426A (en) | 2024-09-13 |
CN118642426B true CN118642426B (en) | 2024-11-12 |
Family
ID=
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102063366A (en) * | 2009-11-18 | 2011-05-18 | 中兴通讯股份有限公司 | Method and system for debugging process |
CN109884978A (en) * | 2019-04-02 | 2019-06-14 | 浙江捷诺电器股份有限公司 | A kind of remote system and its method for PLC device debugging |
CN117370214A (en) * | 2023-12-01 | 2024-01-09 | 珠海格力电器股份有限公司 | Program debugging method and device of controller and storage medium |
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102063366A (en) * | 2009-11-18 | 2011-05-18 | 中兴通讯股份有限公司 | Method and system for debugging process |
CN109884978A (en) * | 2019-04-02 | 2019-06-14 | 浙江捷诺电器股份有限公司 | A kind of remote system and its method for PLC device debugging |
CN117370214A (en) * | 2023-12-01 | 2024-01-09 | 珠海格力电器股份有限公司 | Program debugging method and device of controller and storage medium |
Non-Patent Citations (1)
Title |
---|
S7 - PLCSIM 仿真软件在选煤厂PLC 程序调试中的应用;董;《选煤技术》;20150430(第2期);第74-76页 * |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN110888414B (en) | Test method for upgrading vehicle controller | |
JP2008170998A (en) | System and method for turbine control simulation | |
US11194550B2 (en) | System and method for migrating legacy software to a system common architecture | |
CN108009081B (en) | Engineering design tool cooperation device and engineering design tool cooperation method | |
US11958511B2 (en) | Train signal system and linkage method therefor | |
US20080127061A1 (en) | Method and system for editing code | |
CN105179156A (en) | Offline control program testing system and method of pump storage group | |
CN112925705B (en) | Unmanned-duty-based carrier rocket flight software acceptance method and system | |
CN118642426B (en) | Remote monitoring and debugging method, system and terminal based on PLC | |
CN118642426A (en) | Remote monitoring and debugging method, system and terminal based on PLC | |
JP2003330756A (en) | Configuration management method for supervisory control software | |
CN113535560A (en) | Test execution method and device, storage medium and computing equipment | |
Schofield et al. | Continuous Integration for PLC-based Control System Development | |
CN112836220A (en) | Cloud center environment inspection method | |
Scott | Learning RSLogix 5000 Programming: Build robust PLC solutions with ControlLogix, CompactLogix, and Studio 5000/RSLogix 5000 | |
US20240264829A1 (en) | Method and system for generating engineering programs which are compatible with a specific engineering environment | |
US20240094694A1 (en) | Virtual Deployment of Distributed Control Systems for Control Logic Testing | |
Buit | PC104 stack mechatronic control platform | |
CN115755781A (en) | Method, apparatus, device, and medium for configuring control logic of distributed control system | |
CN117370171A (en) | Remote control POS batch automatic test method | |
Juurinen | Test Automation for Control Applications on Distributed Control System | |
Marttila | Automating Protective Relay Software Updates | |
WO2023062209A1 (en) | Method and system for generating and optimizing engineering programs for a technical installation | |
CN117472742A (en) | Test tool deployment method, device, equipment and storage medium | |
Barana et al. | Recent developments of the RFX control and data acquisition system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant |