A method for monitoring programmable controller data with discrete data block communication
By using a custom protocol and monitoring dictionary for block communication of discrete data in a programmable controller, data redundancy and real-time problems when the monitoring span of discrete data is solved, and efficient and real-time data monitoring effect is achieved.
Patent Information
- Application Number
- CN202210269393.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-18
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2042-03-18
AI Technical Summary
The prior art is difficult to effectively monitor two discrete data with large address spans in programmable controllers, resulting in problems of data redundancy and poor real-time performance.
Using a custom protocol for block communication of discrete data, the data monitoring process is optimized, redundant data transmission is reduced, and the real-time and efficiency of monitoring is improved.
It realizes efficient and real-time monitoring of discrete data in programmable controllers, avoids data redundancy, reduces time costs, and has good scalability.
Smart Images

Figure CN114690699B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of programmable controller data monitoring, and in particular to a programmable controller data monitoring method for discrete data block communication. Background Art
[0002] With the continuous development of industrial control, the degree of automation is getting higher and higher, the control system in the industrial field is becoming more and more complex, and the processor of the programmable controller supports 32-bit data operations. When developing software for programmable controllers, a large number of variables will be used and there may be two variables with a large span that need to be monitored.
[0003] If the monitoring method based on the traditional Modbus communication protocol is used, there are two solutions when monitoring two variables with a large address span, that is, discrete data:
[0004] 1. Send the Modbus frame twice separately, that is, in each frame, the actual address of the variable is the system address in the Modbus frame, and the variable length is the number of bytes of the data segment in the Modbus frame.
[0005] 2. Merge and send the Modbus frame once, that is, read all the data between the two variable addresses.
[0006] The first method is not applicable because the program cycle of the programmable controller is fast and the time left for the monitoring thread is short. Therefore, the time spent on the three steps of sending data frames, executing the monitoring thread of the programmable controller, and receiving data frames accounts for the vast majority of the time spent on a single data monitoring. Then, sending them twice separately will bring huge time costs and does not have good real-time performance.
[0007] The second method is also not applicable because if the address span of the two variables is large, it will cause too much data redundancy.
[0008] Therefore, a programmable controller data monitoring method for discrete data block communication is needed, that is, a simple, efficient, real-time monitoring method that can support discrete data. Summary of the invention
[0009] The problem to be solved by the present invention is to provide a programmable controller data monitoring method that can monitor common data and discrete data simply, efficiently and in real time. In view of this, the present invention proposes a programmable controller data monitoring method for discrete data block communication.
[0010] In order to solve the above technical problems, the technical solution of the present invention is:
[0011] A programmable controller data monitoring method for discrete data block communication comprises the following steps:
[0012] S1. Export the program in the programmable logic controller PLC, which is an XML format file;
[0013] S2. Read and parse the variables defined in the XML format file, encapsulate the relevant information of the variables into a data structure and generate a monitoring dictionary;
[0014] S3, confirm the variables to be monitored, and generate a communication list containing the information of the variables to be monitored;
[0015] S4, execute the monitoring process with the programmable controller PLC according to the communication list to obtain the actual value of the variable;
[0016] S5. Determine whether the variable to be monitored has changed. If so, proceed to step S3; otherwise, proceed to step S4.
[0017] Preferably, in step S2, the data structure encapsulates the variable name, the actual address of the variable calculated from the partition where the variable is located and the offset, the variable address length and the variable value, wherein the variable value defaults to 0.
[0018] Preferably, the monitoring dictionary is set with variable name as key and data structure as value.
[0019] Preferably, in step S2, the variable address is an actual address calculated based on the partition where the defined variable is located and the offset.
[0020] Preferably, step S4 includes the following sub-steps:
[0021] S4-1, obtain variable information such as actual address of the variable, variable address length, etc. through the correspondence formed by the variable name in the communication list and the monitoring dictionary;
[0022] S4-2, generating and sending a data frame in a frame format according to the protocol;
[0023] S4-3, after receiving the data frame, the PLC parses the data frame, obtains a byte stream on a continuous address starting with the actual address of the specified variable and with a total length equal to the variable address length, generates a data frame according to the protocol reception frame format, and returns it to the sender;
[0024] S4-4. After receiving the return data frame, the PLC cuts the bytes of the return data in the return data frame and calculates the decimal variable value according to the variable information.
[0025] Preferably, the protocol is a custom protocol for communicating discrete data in blocks.
[0026] The present invention has the following characteristics and beneficial effects:
[0027] 1. The present invention utilizes a custom protocol for discrete data block communication to effectively solve the problem of monitoring two variables with a large address span, thereby avoiding data redundancy.
[0028] 2. The present invention utilizes a monitoring dictionary, a communication list, and a custom protocol, which not only meets the characteristics of a programmable controller having a fast program running cycle and a short time left for the monitoring thread, but also can well ensure the real-time and high efficiency of the data monitoring method, thereby achieving the effect of saving time costs.
[0029] 3. The custom protocol used in the present invention has good scalability and can achieve the effect of modifying multiple variables simultaneously. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0031] Figure 1 A framework flow chart of a programmable controller data monitoring method for discrete data block communication provided by the present invention;
[0032] Figure 2 A sending data frame format of a custom protocol for discrete data block communication of a programmable controller data monitoring method for discrete data block communication provided by the present invention;
[0033] Figure 3 The invention provides a receiving data frame format of a user-defined protocol for discrete data block communication in a programmable controller data monitoring method for discrete data block communication. DETAILED DESCRIPTION
[0034] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.
[0035] The following will further illustrate the technical solution provided by the present invention in conjunction with the accompanying drawings, and provide a complete and clear description of the implementation methods, technical means, and operation procedures in the embodiments of the present invention. It should be noted that the embodiments described are not all embodiments, but only part of the embodiments of the present invention.
[0036] The present invention provides a programmable controller data monitoring method for discrete data block communication, such as Figure 1 As shown, the following steps are included:
[0037] S1. Export the program in the programmable logic controller PLC, which is an XML format file;
[0038] S2. Read and parse the variables defined in the XML format file, encapsulate the relevant information of the variables into a data structure and generate a monitoring dictionary;
[0039] S3. Confirm the variables to be monitored and generate a communication list containing the information of the variables to be monitored. Since data monitoring has good real-time performance, it is not suitable to confirm the variables to be monitored from the beginning every time, so the communication list is used as an intermediate structure.
[0040] S4, execute the monitoring process with the programmable controller PLC according to the communication list to obtain the actual value of the variable;
[0041] S5. Determine whether the variable to be monitored has changed. If so, proceed to step S3; otherwise, proceed to step S4.
[0042] In the above technical solution, the use of monitoring dictionaries, communication lists and custom protocols can not only meet the characteristics of the programmable controller's fast program running cycle and short time left for the monitoring thread, but also can well ensure the real-time and efficiency of the data monitoring method, thereby achieving the effect of saving time costs.
[0043] Furthermore, in step S2, the data structure encapsulates the variable name, the actual address of the variable calculated from the partition where the variable is located and the offset, the variable address length and the variable value, wherein the variable value defaults to 0.
[0044] Furthermore, the monitoring dictionary is set with the variable name as the key and the data structure as the value.
[0045] Furthermore, in step S2, the variable address is an actual address calculated based on the partition where the defined variable is located and the offset.
[0046] According to a further configuration of the present invention, step S4 includes the following sub-steps:
[0047] S4-1, obtain variable information such as actual address of the variable, variable address length, etc. through the correspondence formed by the variable name in the communication list and the monitoring dictionary;
[0048] S4-2, generating and sending a data frame in a frame format according to the protocol;
[0049] S4-3, after receiving the data frame, the PLC parses the data frame, obtains a byte stream on a continuous address starting with the actual address of the specified variable and with a total length equal to the variable address length, generates a data frame according to the protocol reception frame format, and returns it to the sender;
[0050] S4-4. After receiving the return data frame, the PLC cuts the bytes of the return data in the return data frame and calculates the decimal variable value according to the variable information.
[0051] Furthermore, the protocol is a custom protocol for discrete data block communication, which has good scalability and can achieve the effect of modifying multiple variables simultaneously.
[0052] Specifically, Figure 2 As shown in the figure, the sending data frame format of the custom protocol for discrete data block communication is 5nbyte (n is a positive integer), which is: 2byte start symbol, 1byte data frame number, 4byte actual variable address, 1byte variable type, and 2byte CRC check. Among them, the value of the variable type is the variable byte size. If you want to monitor multiple variables at the same time, place the byte stream of the variable actual address and variable type in order, and finally add the CRC check.
[0053] like Figure 3 As shown in the figure, the receiving data frame format of the custom protocol for discrete data block communication is (4+n) bytes (n is a positive integer), which is: start symbol 2 bytes, data frame number 1 byte, byte stream n bytes, CRC check 2 bytes. The byte stream is the sequential listing of the byte streams corresponding to the variables in the sending data frame, and needs to be divided by variables when parsing.
[0054] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the described embodiments. For those skilled in the art, various changes, modifications, substitutions and variations of these embodiments including components are made without departing from the principles and spirit of the present invention, and still fall within the scope of protection of the present invention.
Claims
1. A programmable controller data monitoring method for discrete data block communication, It is characterized in that The steps include: S1. Export the program in the programmable logic controller PLC, which is an XML format file; S2. Read and parse the variables defined in the XML format file, encapsulate the relevant information of the variables into a data structure and generate a monitoring dictionary; S3, confirm the variables to be monitored, and generate a communication list including the names of the variables to be monitored; S4, execute the monitoring process with the programmable controller PLC according to the communication list to obtain the actual value of the variable; S5. Determine whether the variable to be monitored has changed. If so, proceed to step S3; otherwise, proceed to step S4.
2. A programmable controller data monitoring method for discrete data block communication according to claim 1, It is characterized in that In step S2, the data structure encapsulates the variable name, the actual address of the variable calculated from the partition where the variable is located and the offset, the variable address length and the variable value, wherein the variable value defaults to 0.
3. A programmable controller data monitoring method for discrete data block communication according to claim 2, It is characterized in that The monitoring dictionary is set up with variable names as keys and data structure values as values.
4. A programmable controller data monitoring method for discrete data block communication according to claim 2, It is characterized in that In step S2, the variable address is an actual address calculated according to the partition where the defined variable is located and the offset.
5. A programmable controller data monitoring method for discrete data block communication according to claim 2, It is characterized in that The step S4 includes the following sub-steps: S4-1, obtaining the actual address and length of the variable address through the correspondence between the variable name in the communication list and the monitoring dictionary; S4-2, generating and sending a data frame in a frame format according to the protocol; S4-3, after receiving the data frame, the PLC parses the data frame, obtains a byte stream on a continuous address starting with the actual address of the specified variable and with a total length equal to the variable address length, generates a data frame according to the protocol reception frame format, and returns it to the sender; S4-4. After receiving the return data frame, the PLC cuts the bytes of the return data in the return data frame and calculates the decimal variable value according to the variable information.
6. A programmable controller data monitoring method for discrete data block communication according to claim 5, It is characterized in that The protocol is a custom protocol for communicating discrete data in blocks.
Citation Information
Patent Citations
Communication service mapping and encapsulating method for transformer substation monitoring system
CN103414694A
Industrial equipment data acquisition method
CN112711218A