A PLC online monitoring and debugging system and its implementation method

By using instant communication protocols and multiple monitoring modes in the PLC online monitoring and debugging system, combined with breakpoints and step control, the problems of CPU resource waste and single debugging function in PLC online monitoring and debugging are solved, and efficient monitoring and The debugging function improves the real-time performance and development efficiency of the system.

CN116149253BActive Publication Date: 2024-09-17SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310218772.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-02
Publication Date
2024-09-17
Estimated Expiration
2043-03-02

AI Technical Summary

Technical Problem

The existing PLC online monitoring and debugging system cannot effectively solve the problems of CPU resource waste and single debugging function with low efficiency. It cannot monitor PLC internal data in real time and provide accurate debugging functions.

Method used

A PLC online monitoring and debugging system is used to package and analyze data through the instant communication protocol and data acquisition and analysis modules between the host computer and the slave computer. It supports global monitoring, I/O monitoring and custom monitoring, combined with polling. And manual monitoring mode, realizes multiple monitoring modes, and provides breakpoints, ladder control and virtual debugging system to enhance debugging functions.

Benefits of technology

It reduces waste of CPU resources, improves debugging efficiency, supports flexible monitoring modes and debugging functions, improves program development efficiency, and improves communication real-time and data transmission efficiency through priority and data packetization technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116149253B
    Figure CN116149253B
Patent Text Reader

Abstract

The present invention belongs to the technical field of industrial control, and discloses a PLC online monitoring and debugging system and its implementation method, including S1, a host computer sends a request message to a lower computer through a communication module; the communication module includes an instant communication protocol and a data acquisition and analysis module, and the instant communication protocol specifies the format, transmission and analysis of data; the data acquisition and analysis module packages and analyzes the received data and transmits it to the lower computer; S2, the lower computer responds to the identification code and command code in the request message and runs and returns a response request, which is packaged and analyzed by the data acquisition and analysis module and transmitted to the host computer; S3, the host computer receives the response request to realize online monitoring and debugging of the lower computer. The present invention solves the problems in the prior art that the CPU resource occupancy rate is high, the debugging function is imperfect, and the monitoring mode cannot be flexibly adjusted to meet the needs of different users.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of industrial control, and more specifically, relates to a PLC online monitoring and debugging system and an implementation method thereof. Background Art

[0002] The development of PLC is closely related to computer technology, semiconductor technology, control technology, digital technology, communication network technology, etc. These technologies have jointly promoted the development of PLC (Programmable Logic Controller) technology. Although the above technologies are used as development support, due to the inherent problems of PLC itself such as insufficient data processing and management capabilities and poor human-computer interaction, it cannot meet higher interactive control requirements. Therefore, it is the preferred practice in the field of industrial control to communicate data between personal computers and PLCs and improve control methods. The organic combination of computers as debugging and monitoring host computers and PLC control systems can effectively realize the debugging and monitoring of PLCs. At the same time, computers can also record or display various control data or charts, which greatly facilitates the operation of control personnel. However, real-time monitoring of PLC internal data during debugging or program running will occupy more CPU resources, and the single debugging function will also reduce the development efficiency of the program.

[0003] Although a variety of PLC online monitoring and debugging solutions have been made public, they still cannot substantially solve the technical problems of CPU resource waste and single debugging function with low efficiency:

[0004] Chinese patent document CN111142469A discloses a method for debugging a configuration program of a PLC, which adds debugging information to each code line, compiles the edited target code into a configuration program that can be run by the PLC, and sends the configuration program to the PLC; in debugging mode, before running each instruction line of the configuration program, the PLC calls a first function based on the debugging information, and the first function determines whether the current instruction line is a valid stop line based on breakpoint information and / or single-step debugging information sent by a debugging device. If the current instruction line is not a valid stop line, the current instruction line is run. If the current instruction line is a valid stop line, a second function is called based on the debugging information, and the second function controls the task of running the configuration program to enter a sleep state to stop running the configuration program until a continue running instruction is received; the debugging device obtains the running data of the PLC running the configuration program and displays it.

[0005] Chinese patent CN103218293A discloses a PLC online debugging system and method, which realizes real-time online debugging of user programs by means of communication between a PLC background control module and a PLC, and includes a PLC background control module and a PLC that communicate with each other; wherein the PLC background control module is used to write and compile user programs, send the compiled user programs to the PLC, enable the PLC to enter the PLC online debugging state, debug and monitor the running data of the user programs in the PLC; the PLC is used to receive the user programs compiled by the PLC background control module, download them to the user program storage area, and parse and execute the downloaded user programs according to the breakpoint information generated during the debugging of the PLC background control module, and feed back the monitored running data of the user programs to the PLC background control module.

[0006] Chinese patent CN104898546A discloses a PLC online debugging system and method based on SOC. The program compilation module in the host computer system converts the code of the program to be tested into the code of the user program and outputs it to the memory in the SOC system. The user program consists of a preset binary code. The first debugging module of the host computer system responds to external input and sends debugging instructions or configuration instructions to the embedded microprocessor IP core in the SOC system. The embedded microprocessor IP core responds to the configuration instruction to configure the PLC controller IP core in the SOC system, or responds to the debugging instruction to control the PLC controller IP core to read and execute the binary code of the user program from the memory in the debugging mode. After encountering a breakpoint during execution or completing the debugging instruction, the PLC controller IP core suspends execution and sends feedback to the first debugging module.

[0007] The above method enables the tester to monitor the details of debugging, but the debugging function is relatively single, and it is impossible to debug the program accurately, and it is impossible to monitor the internal data of the PLC during the debugging process. Although the difficulty and workload of system development are relatively small, monitoring the user program during the debugging process causes a large CPU resource occupation. Therefore, the technical problem proposed by the present invention is still unable to be achieved. Summary of the invention

[0008] The present invention aims to overcome at least one defect of the above-mentioned prior art and provides a PLC online monitoring and debugging system and an implementation method thereof.

[0009] The detailed technical scheme of the present invention is as follows:

[0010] In order to solve the above technical problems, the present invention provides a PLC online monitoring and debugging system and an implementation method thereof, so as to solve the problems that the prior art cannot substantially solve, such as waste of CPU resources and single debugging function and low efficiency:

[0011] A method for implementing a PLC online monitoring and debugging system, characterized by comprising:

[0012] S1, the upper computer sends a request message to the lower computer through the communication module; the communication module includes an instant communication protocol and a data acquisition and analysis module, the instant communication protocol specifies the format, transmission and analysis of the data; the data acquisition and analysis module packages and analyzes the received data and transmits it to the lower computer;

[0013] S2, the lower computer responds to the identification code and command code in the request message and returns the response request, which is packaged and analyzed by the data acquisition and analysis module and transmitted to the upper computer;

[0014] S3. The upper computer receives the response request to realize online monitoring and debugging of the lower computer.

[0015] The data acquisition and analysis module performs packaging processing on the received data, specifically including: the host computer sends request data, the data acquisition and analysis module packages the request data into a data packet, and determines whether the data packet needs to be split, and then converts the byteArray type data packet into a binary data stream for outflow through data conversion;

[0016] The determination of whether data packet splitting is required specifically includes: firstly determining whether the size of the encapsulated data packet is greater than the maximum length of the data sent per frame (the default maximum length of the data sent per frame is 256 bytes); if so, the packet splitting process is performed, and a sequence number is added after each small data packet; if the data packet fails to be sent, the lost packet is confirmed by the sequence number, and the host computer resends the data packet (lost packet); if the sending is successful, the process ends;

[0017] If it is not greater, no packet subdivision is performed and the data packet is sent directly; if the data packet fails to be sent, the entire data packet is resent through the host computer.

[0018] Furthermore, the S2 specifically includes: the lower computer parses the received data, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified:

[0019] If verification is not required, the lower computer directly executes the request message; if verification is unsuccessful, the data packet reception error occurs and the lower computer returns an abnormal response; if verification is successful, the data packet reception is complete and correct, and the lower computer performs the corresponding operation according to the identification code and command code in the data packet, and returns the corresponding request response;

[0020] After the lower computer returns the corresponding request response, it packages the PLC's request response data to determine whether the data packet needs to be split. The data packet is then converted into a binary data stream after data conversion. The upper computer parses the received data packet, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified:

[0021] If verification is not required, the host computer directly executes the request response; if the verification is unsuccessful, the data packet is received incorrectly and the host computer prompts a reception error; if the verification is successful, the data packet is received correctly and correctly, and according to the command code in the data packet, the host computer executes the end response, receives data and stores the returned data in the RECVDATA array, responds to exceptions or ends debugging, and other operations.

[0022] Furthermore, the online monitoring of S3 specifically includes polling monitoring mode and manual monitoring mode. The polling monitoring mode: the lower computer returns a response request to the upper computer according to the set polling cycle, and the upper computer receives and performs real-time data refresh on the monitoring chart interface. The polling cycle can be set under polling monitoring; the manual monitoring mode: the upper computer sends a monitoring request message through a serial port interrupt, and after the monitoring request message is sent, the upper computer is restored to a receiving state to prepare to receive a response message from the lower computer: the serial port interrupt is manually selected.

[0023] Specifically, the method of serial port interrupt is as follows: when a serial port interrupt enters, it is determined whether the lower computer has received the serial port interrupt; if the lower computer has received the serial port interrupt, the timer is started, and the SENDING flag is set to 1, which means that the upper computer receives and assembles the data frame returned by the lower computer. If the data is not received, the timer is reset to wait for the reception and assembly of the data frame; if the reception is completed, the SENDING flag is set to 0, which means that the upper computer has completed the reception and the serial port interrupt returns; if the lower computer has not received the serial port interrupt, the timer is started, and the upper computer resends the serial port interrupt request; if the upper computer does not receive the data frame request returned by the lower computer, it is displayed that the serial port interrupt reception is abnormal.

[0024] Furthermore, the online monitoring also includes a global monitoring function, an I / O monitoring function and a custom monitoring function. The global monitoring: monitors all variables, addresses and instructions in use within the program;

[0025] The I / O monitoring: monitors the status of all I points and Q points in use. The monitoring chart displays the I points and Q points used by the program and determines the connection status of the I points and Q points by 0 or 1, 1 for connection and 0 for disconnection.

[0026] The custom monitoring includes: ① monitoring a single data address: obtaining the value of a specified data address (such as a bit, a byte or a double byte) and displaying it in real time on a host computer monitoring chart; ② monitoring continuous data addresses: obtaining the value of a continuous data address, which stores data of the same type; ③ monitoring data blocks: obtaining the value of a specified data block, which stores data of the same type;

[0027] The global monitoring function, I / O monitoring function and custom monitoring function can be combined with the polling monitoring mode and manual monitoring mode to form six monitoring modes:

[0028] Monitoring mode 1: When using polling monitoring, the global monitoring function is turned on, and the value or status of the globally monitored variables, registers, addresses, and instructions will be returned according to the polling cycle;

[0029] Monitoring mode 2: When using polling monitoring, the I / O monitoring function is turned on and the status of the monitored I and O points will be returned according to the polling cycle;

[0030] Monitoring mode 3: When using polling monitoring, the custom monitoring function is divided into three sub-modes;

[0031] Submode 1 returns the value of a specified single data address according to the polling cycle; submode 2 returns the value of a continuous data address according to the polling cycle; submode 3 returns the value of a data block address according to the polling cycle;

[0032] Monitoring mode 4: In manual monitoring mode, global monitoring is turned on. When the lower computer receives the command of global monitoring, it returns the value or status of the variables, registers, addresses and instructions of global monitoring.

[0033] Monitoring mode 5: In manual monitoring mode, the I / O monitoring function is turned on. The lower computer receives the I / O monitoring command and returns the status of the I and O points monitored once.

[0034] Monitoring mode 6: In manual monitoring mode, the custom monitoring function is divided into three sub-modes: Sub-mode 1, the lower computer receives a single data address monitoring command and returns the value of a specified single data address once; Sub-mode 2, the lower computer receives a continuous data address monitoring command and returns the value of a continuous data address once; Sub-mode 3, the lower computer receives a data block address monitoring command and returns the value of a data block address once.

[0035] The debugging of S3 includes: the realization of breakpoints and breakpoint vector tables, the control of ladders and the realization of ladder vector tables, the construction and debugging of virtual debugging systems, and the realization of various debugging functions; the breakpoints need to pause the program at a certain ladder diagram position in the graphical design interface of the debugging function; the breakpoint vector table is a structure array composed of serial numbers, program numbers and line numbers; the serial number is the order of the breakpoints in the breakpoint vector table, and the program number and line number refer to the serial number, program number and line number of the program where the breakpoint is located.

[0036] The implementation of the breakpoint and the breakpoint vector table is specifically as follows: click Add Breakpoint, first traverse the breakpoint vector table to determine whether it is added repeatedly, if it is added repeatedly, it will be displayed that the breakpoint already exists, if it is not added repeatedly, the program number and line number of the ladder diagram program line will be added to the breakpoint vector table; click Delete Breakpoint, traverse the breakpoint vector table, if there is a breakpoint, delete the breakpoint information, if not, it will be displayed that the deletion fails;

[0037] The control of the ladder and the implementation of the ladder vector table are specifically as follows: entering the ladder instruction will locate the next location of the function or subroutine in the program according to the ladder vector table, first add the ladder information of the ladder diagram program in the next line of the calling function or subroutine to the ladder vector table, and then enter the function or subroutine, and increase the ladder number by 1; when jumping out of the ladder, the function execution is completed or the subroutine execution is completed, when the program returns to the previous ladder, it only needs to reduce the ladder number by 1, query the ladder vector table according to the ladder number at this time, find the ladder information corresponding to the ladder number at this time, jump to the specified position according to the program number and line number in the ladder information, and then delete this ladder information in the ladder vector table, so as to realize the ladder control of the program during debugging; the ladder number is equivalent to the index in the ladder vector table (when querying the ladder vector table, the ladder number in the ladder vector table will be queried first, and the corresponding ladder number will be found, so that the program number and line number corresponding to the ladder number can be known to determine the position where the program runs to). Among them, the ladder vector table is a structure array composed of program number, row number and ladder number; the ladder information includes program number and row number, and the program number, row number and ladder number of the ladder vector table refer to the program number, row number and ladder number of the ladder diagram program.

[0038] The construction and debugging of the virtual debugging system: after backing up the original program in the lower computer in the flash, the original system is used as the virtual debugging system for debugging. After the debugging is completed, all debugging information including the debugging program is cleared, the backed-up original program is written into the original system, the program resumes normal operation, and the virtual debugging system is restored to the original system;

[0039] The realization of the multiple debugging functions includes: program control and ladder control; the program control includes: single-step execution, continuous execution, pause, end debugging, add breakpoints, clear breakpoints; the ladder control includes: enter ladder, next ladder, jump out of ladder;

[0040] The present invention also discloses a PLC online monitoring and debugging system, which is characterized by comprising: an upper computer and a lower computer communicating through a communication module; the upper computer sends a request message to the communication module, which is processed by the communication module and sent to the lower computer for operation; after the lower computer completes the operation, it sends a response request to the communication module, which is then processed by the communication module and sent to the upper computer;

[0041] The communication module includes an instant communication protocol and a data collection and analysis module. The instant communication protocol specifies the format, transmission and analysis of data; the data collection and analysis module packages and analyzes the received data;

[0042] The upper computer includes a monitoring module and a debugging module. The monitoring module implements monitoring of the lower computer in a method for implementing a PLC online monitoring and debugging system, and the debugging module implements debugging of the lower computer in a method for implementing a PLC online monitoring and debugging system.

[0043] The data acquisition and analysis module includes a data processing unit, a data conversion unit and a data analysis unit;

[0044] The data processing unit is responsible for splitting the data packets and packaging the data into a whole data packet;

[0045] The data conversion unit is responsible for converting the bytearray type data packet into a binary data stream;

[0046] The data parsing unit is responsible for parsing the received data packets, first determining whether CRC verification is required, and if verification is required, parsing and transmitting the data packets to the upper computer or the lower computer; if verification is not required, parsing and transmitting the data packets directly.

[0047] Compared with the prior art, the present invention has the following beneficial effects:

[0048] (1) The present invention provides a PLC online monitoring and debugging system and an implementation method thereof, which has three monitoring functions: global monitoring, I / O monitoring, and custom monitoring. It supports two monitoring modes: polling monitoring and manual monitoring. It can be freely combined into six monitoring modes to reduce the waste of CPU resources. In addition, the polling cycle can be flexibly adjusted according to different debugging and monitoring scenarios to reduce the CPU load while meeting user needs.

[0049] (2) The present invention provides a PLC online monitoring and debugging system and its implementation method. The system has complete debugging functions including single-step execution, continuous execution, pause, end debugging, add breakpoints, clear breakpoints, enter the ladder, next ladder and jump out of the ladder. During the debugging process, the monitoring chart can be called to view the real-time status of the running instructions, the values ​​of each contact used or the value of the specified data address during the debugging process, so as to accurately locate the program problem and improve the efficiency of program development.

[0050] (3) The present invention provides a PLC online monitoring and debugging system and its implementation method, which can configure the priority of communication events. When the communication load in the system is heavy due to faults or other reasons, different priorities can be assigned to different information that needs to be transmitted. Emergency events can be assigned a higher priority so that they can be exempted from queuing and completed with priority when multiple tasks are executed concurrently, thereby improving the real-time monitoring capability.

[0051] (4) The present invention provides a PLC online monitoring and debugging system and an implementation method thereof. For larger data packets, data packetization technology is adopted. According to the size of the program, the maximum length of each frame of data can be dynamically changed to improve the data packet transmission efficiency. In most cases, the system sends shorter messages. To address the data congestion problem, if a receiving buffer is used to store data that is not received in time, memory resources will be wasted. Therefore, the system solves the data congestion problem by dynamically changing the delay time of data packet sending according to the maximum length of each frame of data.

[0052] (5) The present invention provides a PLC online monitoring and debugging system and an implementation method thereof. After backing up the original program in FLASH, the original system is used as a virtual debugging system for debugging operations. After the debugging is completed, the virtual debugging system is restored to the original system with normal program operation. Compared with directly debugging the program in the original system, the reliability is higher. Compared with setting up an additional virtual debugging system for debugging the program, the development cost is lower.

[0053] (6) The present invention provides a PLC online monitoring and debugging system and its implementation method. The system controls functions or subroutines in a unified way as step control, and step control is achieved by querying a step vector table. Each time a step is entered, the step number in the step vector table is increased by 1, and each time a step is exited, the step number is decreased by 1. The program can be directly jumped through the step information. The method is simple and efficient. BRIEF DESCRIPTION OF THE DRAWINGS

[0054] Figure 1 It is a system framework diagram of the present invention.

[0055] Figure 2 This is a framework diagram of the instant messaging protocol in Example 1 of the present invention.

[0056] Figure 3 This is a flow chart of data packet transmission in Embodiment 1 of the present invention.

[0057] Figure 4 This is a framework diagram of the monitoring module in Example 2 of the present invention.

[0058] Figure 5 This is the monitoring flow chart in Example 2 of the present invention.

[0059] Figure 6 This is the interruption flow chart in Embodiment 2 of the present invention.

[0060] Figure 7 This is the debugging information diagram in Example 3 of the present invention.

[0061] Figure 8 This is a structural diagram of the interruption point vector table of embodiment 3 of the present invention.

[0062] Fig. 9 This is a diagram of the ladder vector table structure in Embodiment 3 of the present invention.

[0063] Fig.10 This is the ladder control flow chart in Example 3 of the present invention.

[0064] Fig.11 This is a debugging flow chart in Example 3 of the present invention.

[0065] Fig.12 It is a flow chart of the operation of the virtual debugging system in Example 3 of the present invention.

[0066] Fig.13 This is a debugging function diagram in Example 3 of the present invention. DETAILED DESCRIPTION

[0067] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0068] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0069] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0070] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0071] Example 1

[0072] This embodiment provides a method for implementing a PLC online monitoring and debugging system to solve the problem that real-time monitoring of PLC internal data during debugging or program running will occupy more CPU resources, and the single debugging function will also reduce the development efficiency of the program. Figure 1 As shown:

[0073] A method for implementing a PLC online monitoring and debugging system, characterized by comprising:

[0074] S1. The host computer (computer) sends a request message to the slave computer (PLC) through a communication module; the communication module includes an instant communication protocol and a data acquisition and analysis module, and the instant communication protocol specifies the format, transmission and analysis of data; the data acquisition and analysis module splits, packages and analyzes the received data and transmits it to the slave computer;

[0075] The instant messaging protocol defines the message structure that this system can recognize and use, regardless of which network they communicate through. The instant messaging protocol corresponds to the request message, data structure, command and response mode. The data communication adopts the master-slave mode. The host computer sends a request message. After the lower computer receives the correct message, it can return a message to the host computer to respond to the request; the host computer can also directly send a message to modify the data of the lower computer to achieve two-way reading and writing. The instant messaging protocol needs to use a 16-bit CRC (cyclic redundancy check code) to verify the transmitted data. In addition, the instant messaging communication protocol adopts timed data transmission and reception. In actual use, if a lower computer is disconnected, the host computer can diagnose it, and when the fault is repaired, the communication can be automatically connected again.

[0076] When a communication command is sent from the sending device (host computer) to the receiving device (slave computer), the slave computer that meets the corresponding terminal address receives the communication command and performs the corresponding operation according to the command code. If the CRC check is correct, the corresponding task is executed and the execution result (data) is returned to the host computer. The transmission and judgment splitting process of the packaged data packet is as follows Figure 3 As shown, it includes: firstly judging whether the size of the encapsulated data packet is greater than the maximum length of the data sent per frame (the default maximum length of the data sent per frame is 256 bytes); if it is greater, it is processed by subpacketization, and a sequence number is added after each small data packet; if the data packet fails to be sent, the lost packet is confirmed by the sequence number, and the upper computer resends the data packet (lost packet), and ends if the sending is successful; if it is not greater, it does not perform subpacketization and directly sends the data packet; if the data packet fails to be sent, the entire data packet is resent through the upper computer.

[0077] The instant messaging protocol specifically includes: 8-bit identification code, 8-bit terminal address, 8-bit command code, 16-bit data address (low bit first), 16-bit data length (low bit first), 16-bit frame number (low bit first), n-bit data bit and 16-bit CRC check bit (low bit first). The instant messaging protocol specifies the format of all communication messages in this system. The transmission and analysis of data need to be carried out in accordance with the instant messaging protocol format, such as Figure 2 The specific message information for each byte is as follows:

[0078] Identification code: used to indicate the instruction to be sent, and to define the format of the message, so that the protocol retains only necessary information and shortens the length of the message as much as possible. This includes debug instructions, read instructions, and write instructions. The length of this position is 8 bytes.

[0079] Terminal address: When a computer is connected to multiple PLCs, the request sent by the computer to the PLC is sent to the corresponding PLC according to the terminal address. The length of this position is 8 bytes.

[0080] Command code: Different command codes correspond to different operations, including but not limited to: inspection, read data, write data, online debugging, response end, receive data, abnormal response and debugging end command. The length of this position is 8 bytes. Different hexadecimal numbers represent different commands. The specific values ​​of the command codes are not listed in detail in this invention.

[0081] Data address: records the starting address of the data to be written and read. The length is 16 bytes. In order to standardize the parsing of data, the little-endian mode is adopted, with the lower 8 bits in front and the higher 8 bits in the back.

[0082] Data length: When data needs to be written or read from the lower computer, the length of the written or read data will be recorded. The length of this position is 16 bytes. To ensure data parsing specifications, the little-endian mode is adopted, with the lower 8 bits in front and the higher 8 bits in the back;

[0083] Frame number: After the data packing function encapsulates the data into a data packet, if the data packet is large, it will divide the data packet into small packets according to the maximum length of data sent per frame and send it to the lower computer. This position records how many small data packets are divided in total. The length of this position is 16 bytes, using the little end mode, with the lower 8 bits in front and the higher 8 bits in the back;

[0084] Data bit: When data needs to be written or returned, this position stores the data to be written or returned, and the length of this position is the length of the data to be written or returned;

[0085] CRC check: Before the lower or upper computer sends a data packet, it will perform a CRC check on the data and store the check result in this position. Only 8 data bits are used in the CRC calculation, and the start bit, stop bit, and parity bit are not involved in the CRC calculation. The length of this position is 16 bytes, using the little end mode, with the lower 8 bits in front and the higher 8 bits in the back.

[0086] The format of the instant messaging protocol when sending different commands is as follows:

[0087] When sending debugging instructions, the message format is composed of 8-bit identification code, 8-bit terminal address, and 8-bit command code, without 16-bit data address, 16-bit data length, 16-bit frame number, n-bit data bit and CRC check. Command codes include but are not limited to single-step execution, continuous execution, pause, end debugging, add breakpoint, clear breakpoint, enter ladder, next ladder and jump ladder commands.

[0088] When sending a read command, the message format is 8-bit identification code, 8-bit terminal address, 8-bit command code, 16-bit data address and 16-bit data length, without 16-bit frame number, n-bit data bit and 16-bit CRC check bit. The command code includes but is not limited to reading a single data address, reading a continuous data address or reading a certain data block address.

[0089] When sending a write instruction, the message format is 8-bit identification code, 8-bit terminal address, 8-bit command code, 16-bit data address, 16-bit data length, 16-bit frame number, n-bit data bit and 16-bit CRC check bit. The command code includes but is not limited to writing a single address data, writing a continuous data address or writing the value of a register.

[0090] When the lower computer returns a read instruction request, the returned message format is an 8-bit identification code, an 8-bit command code, a 16-bit data address, a 16-bit data length, a 16-bit frame number, n data bits and a 16-bit CRC check bit. An 8-bit terminal address is not required, and the returned command code is the same as the received command code.

[0091] When the lower computer returns a write command request, the returned message format is an 8-bit identification code and an 8-bit command code. There is no need for an 8-bit terminal address, a 16-bit data address, a 16-bit data length, a 16-bit frame number, n data bits, and a 16-bit CRC check bit. The returned command code is the same as the received command code.

[0092] When the lower computer returns a debugging command request, the returned command code is the same as the received command code, and different command codes result in different message formats.

[0093] Furthermore, the specific process of the data acquisition and analysis module is as follows: the computer sends the request data, the data packaging function packages the identification code, terminal address, command code, data address, data length, number of frames, data or CRC check code into a data packet, determines whether the data packet needs to be split, and then converts the byteArray type data packet into a binary data stream through data conversion and sends it out. The PLC parses the received data, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified:

[0094] If verification is not required, the PLC directly executes the request message; if verification is unsuccessful, the data packet reception is incorrect and the PLC returns an abnormal response; if verification is successful, the data packet reception is complete and correct, and the PLC performs the corresponding operation according to the identification code and command code in the data packet, and returns the corresponding request response;

[0095] After the PLC returns the corresponding request response, the PLC's request response data is packaged to determine whether the data packet needs to be split. The data packet is then converted into a binary data stream after data conversion. The computer parses the received data packet, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified:

[0096] If verification is not required, the computer directly executes the request response; if the verification is unsuccessful, the data packet is received incorrectly and the computer prompts a reception error; if the verification is successful, the data packet reception is complete and correct, and according to the command code in the data packet, the computer executes the end response, receives data and stores the returned data in the RECVDATA array, responds to an exception or ends debugging, and other operations.

[0097] Specifically, the verification method is CRC verification, which is a conventional verification method for those skilled in the art and will not be described in detail.

[0098] The data acquisition and analysis module instructions and commands include:

[0099] Inspection command: Before the system starts running, the upper computer sends an inspection command to the lower computer. If the upper computer receives a return message, it means that the upper computer and the lower computer can communicate normally, and the identification code is 01.

[0100] Read data command: The upper computer sends a read data command to the lower computer. This command can read the data of the corresponding address or the status of the register. The lower computer returns the corresponding message after receiving it successfully. The identification code is 02, and the command codes include: global read command, I / O read command, single data address read command, continuous data address read command, and data block read command.

[0101] Write data instruction: The upper computer sends a write data command to the lower computer. This command can write data to the corresponding address or force the value of a register to be written. The lower computer receives and verifies the data. After the verification is successful, the write operation is performed and the corresponding message is returned. The identification code is 03, and the command code includes but is not limited to: single data address write command, continuous data address write command or register write command.

[0102] Online debugging command: The upper computer sends online debugging command to the lower computer, opens the virtual debugging system, and can perform various debugging operations. The identification code is 04, and the command code includes but is not limited to: single-step execution command, continuous execution command, debugging end command, add breakpoint command, pause command, clear breakpoint command, soft reset command, enter ladder command, next ladder command, and jump out ladder command.

[0103] End response command: The lower computer returns the end response command to the upper computer, indicating that the communication has ended. The identification code is the same as the identification code of the received message.

[0104] Receive data command: The lower computer returns the data of the corresponding address to the upper computer. The upper computer receives and verifies whether the data is correct. If the verification is successful, the upper computer stores the returned data in the RECVDATA array temporarily and calls the corresponding processing program to perform subsequent operations. The identification code is 05.

[0105] Abnormal response command: If the lower computer fails to verify the received data or fails to return the message, the lower computer returns an abnormal response command to the upper computer, and the identification code is the same as the identification code of the received message.

[0106] Debug end command: The upper computer sends a debug end command to the lower computer. After the lower computer receives the message, it shuts down the virtual debugging system. After the program resumes normal operation, it returns a debug end command, indicating that the debugging is complete. The identification code is 04.

[0107] The identification code of the received message is: the value of the identification code is returned according to the received identification code (eg, if the received identification code is 02, the returned identification code is 02), that is, the identification code of the step where the problem occurs is returned.

[0108] The data collection and analysis module includes the following functions:

[0109] The data collection and analysis module has a data packet splitting function, such as Figure 4As shown in the figure, the specific data packet splitting process is as follows: first determine whether the size of the encapsulated data packet is greater than the maximum length of the data sent per frame (the default maximum length of the data sent per frame is 256 bytes). If it is greater, then split the data packet and add a sequence number after each small data packet. If the data packet fails to be sent, the lost packet is confirmed by the sequence number, and the host computer resends the data packet (lost packet); if it is not greater, then no packet splitting is performed and the data packet is sent directly; if the data packet fails to be sent, the entire data packet is resent through the host computer. If m represents the total length of the data packet, n represents the maximum length of the data sent per frame, and s represents the total number of data packets, then the packet splitting formula is:

[0110]

[0111] Among them, m%n represents the total length of the data packet modulo the maximum length of each frame of data. If the result is 0, it means it is divisible, and if it is greater than 0, it is not divisible. n-1 means that the maximum length of each frame of data minus 1 byte is used to obtain the actual data length stored in each data packet. m / (n-1) means that the maximum length of each frame of data minus 1 byte of the sequence number is rounded up;

[0112] The data acquisition and analysis module has a function of customizing the maximum length of data sent per frame. After the data is packaged, the data packet will be converted into a data stream according to the default maximum length of data sent per frame (the default maximum length of data sent per frame is 256 bytes). If the data packet is too large, the maximum length of data sent per frame can be increased to appropriately improve the transmission efficiency. When the data is small, the maximum length of data sent per frame can be appropriately reduced to improve the accuracy of data transmission, thereby improving the data transmission efficiency. Therefore, according to the interference existing in the actual application and the size of the data packet, the maximum length of data sent per frame is dynamically set to ensure the integrity of data transmission and optimize the data packet transmission efficiency.

[0113] The data acquisition and analysis module has a function of dynamically changing the sending delay (default 50ms). The sending, receiving, data packet parsing and writing data to the corresponding address of the data frame all require time. If the sending delay is small, the data reception will be incomplete, which will cause the program to crash. If the sending delay is too large, there will be a long waiting interval, which will lead to a slow sending speed. Therefore, according to different types of PLCs, the sending delay time is dynamically changed to improve the data packet transmission efficiency;

[0114] The data acquisition and analysis module has a breakpoint retransmission function. If there is interference during the data packet transmission, resulting in data transmission interruption, the lower computer returns the sequence number of the received data packet, and the upper computer locates which frame of the data packet is lost according to the returned sequence number, and the upper computer resends the packet data;

[0115] The communication module has the function of configuring the priority of communication events: the priority of communication events can be configured when the upper computer communicates with the lower computer. The data acquisition and analysis module first processes and analyzes the data. If there is a priority, different priorities are assigned according to the priority defined by the instant communication protocol; if there is no priority, the data is transmitted in order. If the lower computer has a heavy communication load, a higher priority is assigned to more urgent events (such as changes in the state of a register, output of a specific value), so that the communication event is exempted from queuing and the transmission is completed first when multiple tasks are concurrent. For some events whose delayed transmission will not have a great impact on the operation of the PLC, a lower priority can be assigned.

[0116] S2, the lower computer responds to the identification code and command code in the request message and returns the response request, which is packaged and analyzed by the data acquisition and analysis module and transmitted to the upper computer;

[0117] The lower computer parses the received data, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified. If the data packet is received incorrectly, the lower computer returns an abnormal response; if the data packet is received correctly, the lower computer performs operations according to the identification code and command code in the data packet, and returns the corresponding request response.

[0118] S3. The upper computer receives the response request to realize online monitoring and debugging of the lower computer.

[0119] This embodiment also discloses a PLC online monitoring and debugging system, including: an upper computer and a lower computer communicating through a communication module; the upper computer sends a request message to the communication module, which is processed by the communication module and sent to the lower computer for operation; after the lower computer completes the operation, it sends a response request to the communication module, which is then processed by the communication module and sent to the upper computer;

[0120] The communication module includes an instant communication protocol and a data collection and analysis module. The instant communication protocol specifies the format, transmission and analysis of data; the data collection and analysis module packages and analyzes the received data;

[0121] The upper computer includes a monitoring module and a debugging module. The monitoring module realizes monitoring of the lower computer, and the debugging module realizes debugging of the lower computer.

[0122] The data acquisition and analysis module includes a data processing unit, a data conversion unit and a data analysis unit;

[0123] The data processing unit is responsible for splitting the data packets and packaging the data into a whole data packet;

[0124] The data conversion unit is responsible for converting the bytearray type data packet into a binary data stream;

[0125] The data parsing unit is responsible for parsing the received data packets, first determining whether CRC verification is required, and if verification is required, parsing and transmitting the data packets to the upper computer or the lower computer; if verification is not required, parsing and transmitting the data packets directly.

[0126] Example 2

[0127] This embodiment is basically the same as Embodiment 1, except that the method for online monitoring in step S3 is:

[0128] The monitoring module is as follows Figure 5 As shown in the figure, the three monitoring functions all read the current value information of the address through communication, save the corresponding address information, and can modify the value of the corresponding address in real time to achieve the purpose of monitoring the entire PLC. In this system, the upper computer monitors the lower computer through communication. The two use the instant communication protocol described above to exchange data information in the form of data frames. There are two situations for exchanging data information: one is that the computer reads the data of the PLC memory unit as the upper computer, and the other is that the computer writes data into the PLC as the upper computer.

[0129] The monitoring module describes an efficient, fast and low CPU load PLC status viewing method, which can reflect the PLC operation status in real time according to different user needs. The monitoring module has three monitoring functions: global monitoring, I / O monitoring and custom monitoring, and has two monitoring methods: polling monitoring and manual monitoring, which can be combined into six monitoring modes.

[0130] The global monitoring function: monitors all variables, addresses and instructions in use within the program;

[0131] The I / O monitoring function: monitors the status of all I points and Q points in use, the monitoring chart displays the I points and Q points used by the program and determines the connection status of the I points and Q points by 0 or 1, 1 for connection and 0 for disconnection.

[0132] The custom monitoring function includes: ① monitoring a single data address: obtaining the value of a specified data address (such as a bit, a byte or a double byte) and displaying it in real time on a host computer monitoring chart; ② monitoring continuous data addresses: obtaining the value of a segment of continuous data addresses, and the type of data stored in this segment of continuous data addresses is the same; ③ monitoring data blocks: the value of a specified data block can be obtained, and the type of data stored in this data block is the same.

[0133] Polling monitoring mode: The lower computer returns a response request to the upper computer according to the set polling cycle, and the upper computer receives and refreshes the real-time data in the monitoring chart interface. The polling cycle can be manually configured under polling monitoring, and the default is 500ms;

[0134] The manual monitoring method is as follows: the host computer sends a monitoring request message through the serial port interrupt. After the monitoring request message is sent, the host computer is restored to the receiving state to prepare to receive the response message of the lower computer: a timer is used in the receiving process to determine whether the message is received. After receiving a certain frame of data, if no new data frame arrives within the specified time (that is, the communication idle time ends), it is determined that the data packet reception is completed. When the interrupt ends, the monitoring is in a suspended state, and the host computer needs to restart polling monitoring or manual monitoring to monitor the lower computer data again.

[0135] The specific interruption process is as follows Figure 6 As shown: the serial port interrupt enters, and it is determined whether the lower computer receives the interrupt. If the interrupt is received, the timer is started, and the SENDING flag is set to 1. The upper computer receives and assembles the data frame, and determines whether the reception is completed by judging whether the reception end flag is 1. If the data is not received, the timer is reset, and the reception and assembly of the data frame are waiting; if the reception is completed, the SENDING flag is set to 0, and the reception is completed and the serial port interrupt returns;

[0136] If the lower computer does not receive the interrupt, the timer is started and the upper computer resends the interrupt request. If the interrupt request is received within the specified time, the timer is reset and the data is sent; if the interrupt request is not received, the interrupt reception exception is displayed.

[0137] The six monitoring modes of the combination are as follows:

[0138] Monitoring mode 1: When using polling monitoring, the global monitoring function is turned on and the value or status of the globally monitored variables, registers, addresses, and instructions will be returned according to the polling cycle.

[0139] Monitoring mode 2: When using polling monitoring, turn on the I / O monitoring function and the status of the monitored I and O points will be returned according to the polling cycle.

[0140] Monitoring mode 3: When using polling monitoring, enabling the custom monitoring function is divided into three sub-modes.

[0141] Sub-mode 1 returns the value of a specified single data address according to the polling cycle; sub-mode 2 returns the value of a continuous data address according to the polling cycle; sub-mode 3 returns the value of a data block address according to the polling cycle.

[0142] Monitoring mode 4: In manual monitoring mode, global monitoring is turned on. When the lower computer receives the command of global monitoring, it returns the value or status of the variables, registers, addresses and instructions of global monitoring.

[0143] Monitoring mode 5: In manual monitoring mode, turn on the I / O monitoring function. The lower computer receives the I / O monitoring command and returns the status of the monitored I and O points.

[0144] Monitoring mode 6: In manual monitoring mode, the custom monitoring function is divided into three sub-modes. Sub-mode 1, the lower computer receives a single data address monitoring command and returns the value of a specified single data address once; sub-mode 2, the lower computer receives a continuous data address monitoring command and returns the value of a continuous data address once; sub-mode 3, the lower computer receives a data block address monitoring command and returns the value of a data block address once.

[0145] The command code field includes but is not limited to the following commands: inspection command, global monitoring command, I / O monitoring command, read or write single data address command, read or write a continuous data address command, read or write a data block address command, and the lower computer returns the same command code.

[0146] Monitoring process such as Figure 5 As shown in the figure, after the program starts running, the upper computer sends the corresponding monitoring message. If the lower computer receives the message, it will parse the monitoring identification code to determine whether it is a read instruction. If it is a read instruction, it will parse the command code and execute the corresponding operation of reading data from the PLC. If it is not a read instruction, it will determine whether it is a write instruction. If it is a write instruction, it will parse the command code and execute the corresponding operation of writing data to the PLC. If it is not a write instruction, it is other instructions (such as inspection instructions, debugging instructions). After executing other operations, the lower computer sends a return message and the monitoring communication ends. If the message is not received, the message will be resent. If it exceeds five times, it will be determined that the message sending failed.

[0147] Example 3

[0148] This embodiment is basically the same as Embodiment 1 and Embodiment 2, except that this embodiment describes a method for debugging a lower computer by a host computer using a breakpoint vector table and a ladder vector table in a virtual debugging system. The debugging method in S3 of the method specifically includes: realization of breakpoints and breakpoint vector tables, control of ladders and realization of ladder vector tables, construction and debugging of a virtual debugging system, and realization of multiple debugging functions.

[0149] The programs mentioned in this article include main programs and subprograms. The main program is the entry point to the subprogram. When executing the program, the subprogram can be called from the main program, which is common knowledge in the art.

[0150] In the graphical design interface of the debugging function, the program needs to be paused at a certain ladder diagram position, which is called a ladder diagram breakpoint (breakpoint). The graphical design interface of the debugging function is common knowledge in the art. The breakpoint vector table is a structure array consisting of a sequence number, a program number, and a line number, such as Figure 7 As shown. After clicking Add Breakpoint, the program number and line number in the ladder diagram debugging information of that line will be added to the breakpoint vector table. For example, (0, 5) means pausing at the fifth line in the main program, and (1, 10) means pausing at the 10th line in subroutine 1. This debugging system supports viewing the data of the breakpoint vector table, which makes it clearer and easier to determine the location of the breakpoint, facilitating subsequent debugging work.

[0151] The debugging information is a structure including program number and line number, such as Figure 7 As shown. The specific initialization process of debugging information for each line of program is: the program number of the ladder program in the main program is 0, the program number of all ladder programs in subprogram 1 is 1, and the program number of all ladder programs in subprogram 2 is 2, and it increases by 1 each time in ascending order. The line number of the first line of the ladder program in the main program is 0, the second line of the ladder program is 1, and the second line of the ladder program is 2. The line number of the first line of the ladder program in the subprogram is 0, and the second line of the ladder program is 1. The ladder line number will be reset in different programs, starting from 0 and increasing by 1 for each line. The rung number defaults to 1 at the beginning of the program. When entering the function or subroutine called in the program, the rung number increases by 1, and when jumping out of the function or subroutine, the rung number decreases by 1, and so on.

[0152] Further, the breakpoint and breakpoint vector table are specifically implemented as follows: click Add Breakpoint, first traverse the breakpoint vector table to determine whether it is added repeatedly, if it is added repeatedly, it will be displayed that the breakpoint already exists, if it is not added repeatedly, the program number and line number of the ladder diagram program line will be added to the breakpoint vector table; click Delete Breakpoint, traverse the breakpoint vector table, if there is a breakpoint, delete the breakpoint information, if not, it will be displayed that the deletion failed;

[0153] The ladder vector table is a structure array consisting of program number, line number and ladder number (default is 1), such as Fig. 9As shown, the step information in the step vector table is (0, 21, 1) and (1, 10, 2). To realize step jumping out of the step by means of the step vector table, it is only necessary to traverse the step vector table each time and the step information stored in the step vector table is relatively small. Each time a step is entered, a step information is added, and each time a step is jumped out, a step information is deleted (there may be only 1-5 steps of information in the actual debugging process). Compared with the method of checking whether there is a next step at the same level as its parent step each time a step is jumped out, until reaching the busbar (a geometric term, which is common knowledge in the art), the method is simpler and more direct, which greatly saves the time spent on step control during the debugging process.

[0154] Furthermore, the control of the ladder and the realization of the ladder vector table are specifically as follows: Fig.10 As shown: the enter ladder instruction will locate the next function or subroutine call in the program according to the ladder vector table. First, the ladder information of the next line of ladder diagram program of the calling function or subroutine is added to the ladder vector table, and then the function or subroutine is entered, and the ladder number is increased by 1; when the ladder is jumped out, the function is executed or the subroutine is executed, the program returns to the previous ladder by subtracting 1, and querying the ladder vector table according to the ladder number at this time to find the ladder information corresponding to the ladder number at this time. According to the program number and line number in the ladder information, jump to the specified position and delete this ladder information in the ladder vector table, so as to realize the ladder control of the program during debugging.

[0155] For example: before entering the ladder, find the location of the calling function or subroutine. The program number, row number and rung number of the ladder diagram program in this row are (0, 20, 1). Before entering the ladder, the program number, row number and rung number of the ladder diagram program in the next row of the ladder diagram program in this row are stored in the ladder vector table. The program number, row number and rung number that need to be saved are (0, 21, 1). Then enter the ladder and first enter the first row of the function or subroutine (here taking entering the subroutine as an example). Enter the subroutine 1. At this time, the program number, row number and rung number are (1, 0, 2). If you want to jump out of the ladder, just subtract 1 from the rung, find the rung information with rung number 1 in the vector table, and then jump directly to the program number and row number (0, 21). Then delete the rung information in the ladder vector table (0, 21, 1), and so on to achieve ladder control.

[0156] To ensure the safety of debugging, this system uses the original program in the lower computer to be backed up in the flash reserved backup address, and then uses the original system as a virtual debugging system for debugging. After debugging, the virtual debugging system is restored to the original system. Fig.11 shown.

[0157] Furthermore, the construction and debugging of the virtual debugging system: after backing up the original program in the flash, the original system is used as a virtual debugging system for debugging. The backed-up program is compared with the original program to verify whether the backup is correct. If the verification is successful, the virtual debugging system starts working. After the debugging is completed, all debugging information including the debugged program is cleared, and the backed-up original program is written to the original system. The program resumes normal operation and the virtual debugging system is restored to the original system. If the backup program verification fails, the program backup error information is returned.

[0158] Furthermore, the implementation of the multiple debugging functions includes, for example, Fig.13 As shown: program control and ladder control; the program control includes: single-step execution, continuous execution, pause, end debugging, add breakpoints, and clear breakpoints; the ladder control includes: enter the ladder, next ladder, and jump out of the ladder; the various debugging functions can accurately and efficiently control each line of the ladder diagram program, intuitively display the status of the running instructions and the values ​​of each contact used during the debugging process, and at the same time, the data of the memory address during the debugging process can be viewed by calling the monitoring chart.

[0159] Preferably, the virtual commissioning system workflow is as follows: Fig.12 As shown: First, initialize the program, assign a unique debugging information to each line of the program, and wait for debugging commands (including single-step execution, continuous execution, end debugging, add breakpoints, clear breakpoints, pause, clear breakpoints, soft reset, enter rung, next rung, and jump out of rung). The program starts running. If there is a new debugging command during the program running, execute the new debugging command, otherwise continue to run; before running to each line of code, the program number and line number of the line of code are compared with the program number and line number in the breakpoint vector table to determine whether there is a breakpoint. If there is no breakpoint, execute the next line of program; if there is a breakpoint, the program pauses at this line and waits for the next debugging command until the debugging is completed; after the debugging is completed, delete the original program, and the virtual debugging system restores the original system.

[0160] The ladder diagram exists in the form of steps during the entire design process, so online debugging is divided into program control and ladder control based on this.

[0161] After debugging starts, single-step execution, continuous execution, end debugging, add breakpoints, enter rung, next rung and soft reset are enabled, and pause, clear breakpoints and jump out rung are enabled and disabled.

[0162] Single-step execution: After clicking single-step execution, the debugging instruction and single-step execution command code are sent (the message format is identification code, terminal address and command code, the identification code is the debugging instruction, the terminal address is the lower computer address, and the command code is the single-step execution command code). The message needs to be returned to obtain the program number and line number of the current program pause. There is no need to perform breakpoint detection on this line of ladder diagram program (the breakpoint detection is to compare the program number and line number of the ladder diagram program with the breakpoint vector table) to directly enter the next line of ladder diagram program and pause at this line of program.

[0163] Continuous execution: When no breakpoints are added (when the breakpoint vector table is empty), click Continuous Execution to send debugging instructions and continuous execution command codes. No return message is required, breakpoint detection will not be performed, pause, end debugging, and soft reset are enabled, and the rest are disabled. The program runs normally until it stops at the end. When breakpoints are added, click Continuous Execution to detect the program number and line number of each line of the program, disable the pause enable, and enable the rest. The program will eventually pause at the breakpoint.

[0164] Pause: The pause function can only be enabled during continuous running. Click Pause, send the debug command and pause command code, and return the message to get the program number and line number of the current program pause. After the program is paused, the pause function is turned off and the rest functions are turned on.

[0165] End debugging: Click to end debugging, send debugging instructions and debugging end command code, return message, all debugging system enables are turned off, all debugging information and debugging programs are deleted, and the backed-up program is rewritten into the original system. Debugging ends and the program returns to normal operation.

[0166] Add breakpoint: Click Add Breakpoint, send debugging instructions and add breakpoint command code, need to return message, get the program number and line number of the current breakpoint, add the program number and line number of the current line of ladder diagram program to the breakpoint vector table. If the breakpoint vector table already has the breakpoint information of the current line, it will show that it is added repeatedly; if the breakpoint is set successfully, add a breakpoint mark to the line of ladder diagram program in the debugging system interface, and intuitively show that the program is paused here.

[0167] Clear breakpoints: Clear breakpoints can be cleared in single line or all. Click Clear Single Line to send debugging instructions and clear single line command code without returning message. The program number and line number of the specified line will be deleted in the breakpoint vector table, and the breakpoint mark of the ladder diagram program in the debugging system interface will be cleared. Click Clear All to send debugging instructions and clear all command code without returning message. All breakpoint information in the breakpoint vector table will be deleted, and all breakpoint marks in the debugging system will be cleared. You can check whether the breakpoint mark in the debugging system interface or the breakpoint information in the breakpoint vector table is cleared to determine whether the clearing is successful.

[0168] Soft reset: Click soft reset to send debugging instructions and soft reset command codes, without returning messages, turn off the pause enable and turn on the rest of the enable. The breakpoint information will be retained, the program will be restored to the debugging ready state, and other debugging operations will be performed from the first line of the main program.

[0169] Enter the ladder: Click Enter the ladder, send the debug command and the Enter the ladder command code, and return the message to get the ladder number of the current ladder program, pause the enable and turn off the rest of the enable. The Enter the ladder command will automatically find the next location in the program where the function or subroutine is called. Before entering the ladder, the program number, line number and ladder number of the next line of the ladder program of the line of ladder program will be stored in the ladder vector table. Enter the function or subroutine, pause at the first line of the ladder program of the function or subroutine, and increase the ladder number by 1. At this time, the ladder number of the ladder program is 2 (the default ladder number is 1, and the ladder number increases by 1 each time the ladder is entered). If there is no function or subroutine called in the program, it will be displayed that the ladder failed to enter.

[0170] Next rung: Click the next rung to send the debug command and the next rung command code. You need to return a message to get the program number, line number and rung number of the current ladder diagram program that is paused. The pause enable is turned off and the rest are turned on. The enter rung command will automatically find the next location in the program where the function or subroutine is called and pause at this line. If there is no function or subroutine called in the program, it will show that the search for the next rung failed.

[0171] Jump out of the ladder: Click Jump out of the ladder, send the debugging instruction and jump out of the ladder command code, need to return the message, get the current ladder program paused program number, line number and ladder number, pause enable close and other enable open. Jump out of the ladder, function execution or subroutine execution, return to the previous ladder program, is completed according to the dynamic ladder number, the ladder number minus 1, query the ladder information with the same ladder number in the ladder vector table and jump to the line program.

[0172] The graphical interface of the debugging system described in this embodiment distinguishes the instructions by color according to whether the energy flow passes through. The instructions with energy flow passing through are highlighted, and the instructions without energy flow passing through are dark gray. The connection line style with energy flow passing through is set to solid line and highlighted, and the connection line style without energy flow passing through is set to dashed line and the color is set to dark gray. The graphical interface has buttons such as single-step execution, continuous execution, add breakpoints, clear breakpoints, pause, enter rung, next rung, jump out of rung, pause, soft reset, debug end, monitoring chart, etc.

[0173] Monitoring chart: Clicking the monitoring chart will open the monitoring chart during debugging. Six monitoring modes can be selected, which supports viewing the internal data address or register value of the lower computer. The registers and their functions are common knowledge in the field and will not be repeated here.

[0174] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included in the protection scope of the claims of the present invention.

Claims

1. A method for implementing a PLC online monitoring and debugging system, characterized in that: include; S1, the upper computer sends a request message to the lower computer through the communication module; the communication module includes an instant communication protocol and a data acquisition and analysis module, the instant communication protocol specifies the format, transmission and analysis method of the data; the data acquisition and analysis module packages and analyzes the received data and transmits it to the lower computer; S2, the lower computer responds to the identification code and command code in the request message and returns the response request, which is packaged and analyzed by the data acquisition and analysis module and transmitted to the upper computer; S3, the upper computer receives the response request to realize online monitoring and debugging of the lower computer; The online monitoring of S3 specifically includes polling monitoring mode and manual monitoring mode; the polling monitoring: the lower computer returns a response request to the upper computer according to the set polling cycle, and the upper computer receives and performs real-time data refresh on the monitoring chart interface; Manual monitoring: the upper computer sends a monitoring request message through a serial port interrupt, and after the monitoring request message is sent, the upper computer is restored to a receiving state to prepare to receive a response message from the lower computer: the serial port interrupt is manually selected; The method of serial port interruption is specifically as follows: when the serial port interruption is entered, it is determined whether the lower computer receives the serial port interruption: If the lower computer receives a serial port interrupt, the timer is started and the SENDING flag is set to 1, indicating that the upper computer receives and assembles the data frame returned by the lower computer. If the data is not received, the timer is reset and waits for the data frame to be received and assembled. If the receiving is completed, the SENDING flag is set to 0, which means that the host computer has completed the receiving and the serial port interrupt returns; If the lower computer does not receive the serial port interrupt, the timer is started and the upper computer resends the serial port interrupt request; if the upper computer does not receive the data frame request returned by the lower computer, it will display that the serial port interrupt reception is abnormal; The online monitoring also includes global monitoring function, I / O monitoring function and custom monitoring function; The global monitoring: monitors all variables, addresses and instructions in use within the program; The I / O monitoring: monitors the status of all I points and Q points in use, and the monitoring chart displays the I points and Q points used by the program and determines the connection status of the I points and Q points by 0 or 1; The custom monitoring includes: ① monitoring a single data address: obtaining the value of a specified data address and displaying it in real time on a host computer monitoring chart; ② monitoring a continuous data address: obtaining the value of a continuous data address, where the continuous data address stores the same type of data; ③ monitoring a data block: obtaining the value of a specified data block, where the data stored in the data block is of the same type; The debugging of S3 includes: the realization of breakpoints and breakpoint vector tables, the control of ladders and the realization of ladder vector tables, the construction and debugging of virtual debugging systems, and the realization of various debugging functions; the breakpoints need to pause the program at a certain ladder diagram position in the graphical design interface of the debugging function; the breakpoint vector table is a structure array composed of sequence numbers, program numbers and line numbers; The implementation of the breakpoint and breakpoint vector table is specifically as follows: Click Add Breakpoint, first traverse the breakpoint vector table to determine whether it is added repeatedly: If you add it repeatedly, it will show that the breakpoint already exists; If it is not repeated, the program number and line number of the ladder diagram program line are added to the breakpoint vector table; Click to delete the breakpoint and traverse the breakpoint vector table: If there is a breakpoint, delete the breakpoint information; If there is no breakpoint, it will show that the deletion failed; The control of the ladder and the realization of the ladder vector table are specifically as follows: entering the ladder instruction automatically finds the position of the next calling function or subroutine in the program, first adds the ladder information of the ladder diagram program of the next line of the calling function or subroutine to the ladder vector table, and then enters the function or subroutine, and the ladder number is increased by 1; when jumping out of the ladder, the function execution is completed or the subroutine execution is completed, when the program returns to the previous ladder, it only needs to reduce the ladder number by 1, query the ladder vector table according to the ladder number at this time, find the ladder information corresponding to the ladder number at this time, and delete the ladder information in the ladder vector table after jumping to the specified position according to the ladder information, so as to realize the ladder control of the program during debugging; the ladder vector table is a structure array composed of program number, line number and ladder number; the ladder information includes program number and line number; The construction and debugging of the virtual debugging system: after backing up the original program in the lower computer in the flash, the original system is used as the virtual debugging system for debugging operations; after the debugging is completed, all debugging information including the debugged program is cleared, the backed-up original program is written into the original system, the program resumes normal operation, and the virtual debugging system is restored to the original system; The implementation of the multiple debugging functions includes: program control and ladder control; the program control includes single-step execution, continuous execution, pause, end debugging, add breakpoints, and clear breakpoints; the ladder control includes entering the ladder, the next ladder, and jumping out of the ladder.

2. The method for implementing a PLC online monitoring and debugging system according to claim 1, characterized in that: The data acquisition and analysis module performs packaging processing and analysis on the received data, including: the host computer sends request data, the data acquisition and analysis module packages the request data into a data packet, and determines whether the data packet needs to be split, and then converts the byteArray type data packet into a binary data stream for outflow through data conversion; The determination of whether data packet splitting is required specifically includes: firstly determining whether the size of the encapsulated data packet is greater than the maximum length of data sent per frame: If it is greater, it will be processed in packets, and a sequence number will be added after each small data packet; if the data packet fails to be sent, the lost packet will be confirmed by the sequence number, and the host computer will resend the data packet; If it is not greater, no packet subdivision is performed and the data packet is sent directly; if the data packet fails to be sent, the entire data packet is resent through the host computer.

3. The method for implementing a PLC online monitoring and debugging system according to claim 1, characterized in that: The data collection and analysis module packages and analyzes the received data and further includes: When the upper computer and the lower computer communicate, the priority of the communication event is configured. The data acquisition and analysis module first processes and analyzes the data. If there is a priority, different priorities are assigned according to the priority defined by the instant communication protocol; if there is no priority, it is transmitted in order.

4. The method for implementing a PLC online monitoring and debugging system according to claim 1, characterized in that: S2 specifically includes: the lower computer parses the received data, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified: If verification is not required, the lower computer directly executes the request message; if verification is unsuccessful, the data packet reception error occurs and the lower computer returns an abnormal response; if verification is successful, the data packet reception is complete and correct, and the lower computer performs the corresponding operation according to the identification code and command code in the data packet, and returns the corresponding request response; After the lower computer returns the corresponding request response, it packages the PLC's request response data to determine whether the data packet needs to be split. The data packet is then converted into a binary data stream after data conversion. The upper computer parses the received data packet, extracts the identification code and command code of the data packet, and determines whether the data needs to be verified: If verification is not required, the host computer directly executes the request response; if the verification is unsuccessful, the data packet is received incorrectly and the host computer prompts a reception error; if the verification is successful, the data packet reception is complete and correct, and according to the command code in the data packet, the host computer executes the end response, receives data and stores the returned data in the RECVDATA array, responds abnormally or ends the debugging operation.

5. A PLC online monitoring and debugging system, characterized in that: It includes an upper computer and a lower computer that communicate through a communication module; the upper computer sends a request message to the communication module, which is processed by the communication module and sent to the lower computer for operation; after the lower computer completes the operation, it sends a response request to the communication module, which is then processed by the communication module and sent to the upper computer; The communication module includes an instant communication protocol and a data collection and analysis module. The instant communication protocol specifies the format, transmission and analysis methods of data; the data collection and analysis module packages and analyzes the received data; The upper computer includes a monitoring module and a debugging module. The monitoring module is used to implement the monitoring of the lower computer in the implementation method of a PLC online monitoring and debugging system as described in any one of claims 1 to 4, and the debugging module is used to implement the debugging of the lower computer in the implementation method of a PLC online monitoring and debugging system as described in any one of claims 1 to 4.

6. A PLC online monitoring and debugging system according to claim 5, characterized in that: The data acquisition and analysis module includes a data processing unit, a data conversion unit and a data analysis unit; The data processing unit is responsible for splitting the data packets and packaging the data into a whole data packet; The data conversion unit is responsible for converting the bytearray type data packet into a binary data stream; The data parsing unit is responsible for parsing the received data packets, first determining whether CRC verification is required, and if verification is required, parsing and transmitting the data packets to the upper computer or the lower computer; if verification is not required, parsing and transmitting the data packets directly.