General PLC data processing method and device
By splitting the PLC data transmission protocol into communication transmission protocol and data description files, and using the upper computer software to generate data description files, the problem of complex protocol formulation and maintenance difficulties in the existing PLC data transmission methods is solved, and efficient PLC data transmission and automated processing are achieved.
Patent Information
- Application Number
- CN202211477317.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2042-11-23
AI Technical Summary
The existing PLC data transmission methods have commercial copyright restrictions, complex programming interfaces, and customized protocols require human participation and complex maintenance, resulting in low development and debugging efficiency.
The communication transmission protocol is split into two parts: communication transmission protocol and structured data description file. The upper computer software processes the PLC symbol table to generate a data description file, describe the specific content of the data domain, and realizes the upper computer automatically process the data description file to obtain a detailed description of the binary byte stream.
It simplifies the process of formulating communication and transmission protocols, reduces communication and maintenance costs, improves development and debugging efficiency, and realizes data acquisition and transmission automation between the host computer and the PLC.
Smart Images

Figure CN115826492B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data information transmission, and in particular to a universal PLC data processing method and device. Background Art
[0002] PLC (Programmable Logic Controller) has become a widely used control device in industrial production due to its simple expansion and reliable performance. PLC collects a large amount of sensor data and generates a lot of process data during operation, which is of great value for storage and analysis. Therefore, obtaining data from PLC through the host computer is a prerequisite for building real-time monitoring, human-computer interaction, data storage and analysis systems to further improve production or management quality.
[0003] Generally, there are three ways to collect and transmit data from PLC:
[0004] The first is to use the host computer software provided by the PLC manufacturer. This type of software uses the PLC's private protocol to obtain data and stores it in a private data format. However, the host computer software provided by the PLC manufacturer is generally commercial copyright, which is expensive. It can usually only communicate with its own PLC and is difficult to integrate with other software to achieve the purpose of data exchange.
[0005] The second is to build an OPC (OLE for Process Control, object linking and embedding process control) server and develop host computer software, using the OPC protocol and related interface functions to obtain data. Similarly, the OPC server is generally a commercial copyright, with complex programming interfaces, and can only be deployed in devices running Windows systems, with many restrictions.
[0006] The third method is to use a custom communication transmission protocol, where both the host computer and the PLC follow the protocol agreement to transmit data. The disadvantage is that it requires human participation in the negotiation of the protocol, stipulating data grouping, transmission order, specifying data names, and explaining the length of each data. There are many subjective factors, data definition is coupled with the communication transmission protocol, and it is difficult to understand, resulting in high communication costs and complex maintenance.
[0007] Moreover, there is no fixed standard and format for data exchange between the host computer and PLC through a custom protocol. The existing method is usually to write a text-based communication transmission protocol file, which specifies the specific fields and formats of the data frames used for communication transmission, and the two communicating parties communicate according to the transmission format. The "data field" field of the data frame generally represents the PLC data transmitted in the frame, which is filled by the PLC. After the host computer receives it, it decodes and stores it according to the protocol agreement. Therefore, in the text of the communication transmission protocol, a large part of the content is a text description of the naming, grouping, specified order, and specified length of the PLC data in the "data field", among which the grouping and specified order are very subjective. This method of describing data in the protocol makes the communication transmission protocol bloated and difficult to maintain. The host computer cannot automatically process the communication transmission protocol text, and the development and debugging efficiency is very low. Summary of the invention
[0008] The purpose of the present invention is to disclose a universal PLC data processing method and device, so as to split a single communication transmission protocol into two parts: a communication transmission protocol and a structured data description file that can be automatically and universally processed by a host computer, so as to improve the development and debugging efficiency.
[0009] To achieve the above object, the general PLC data processing method disclosed in the present invention includes:
[0010] Step S100: The host computer configures a data structure buffer according to the collection and transmission rule table created by the user;
[0011] Step S200, the host computer exports the PLC symbol table, selects records corresponding to the variable types of the acquisition and transmission rule table from the exported PLC symbol table, converts them into structure variables and stores them in groups in the corresponding data structure buffer, and creates a general data description file; the data description file is used to describe the number of structure variables associated with the data domain, the name, length and offset information of each structure variable and the sorting information in the data domain and is independent of the communication transmission protocol;
[0012] Step S300, the PLC puts the contents of the corresponding variables into a buffer with a continuous address in sequence according to the order of each structure variable in the data description file and updates the buffer content in each scanning cycle, and after receiving the read command from the host computer, the PLC uploads the contents of the buffer through a data frame according to the format of the communication transmission protocol; wherein the description of the PLC data determined by the data description file is omitted in the communication transmission protocol;
[0013] Step S400, the host computer extracts the data field in the data frame through protocol analysis and processing, and temporarily stores it as a binary byte stream; then automatically completes data extraction and analysis of the temporarily stored byte stream according to the data description file to obtain the binary value corresponding to each of the structure variable names in the data uploaded by the PLC.
[0014] Preferably, the specific process of generating the data description file includes:
[0015] S4: The host computer generates a new structured data description file in the standard universal markup language format. First, a "data domain" root node element is generated, and a "total number of data" child node element is created in the "data domain" root node element.
[0016] S5: The host computer reads the PLC symbol table row by row, and determines the PLC variable type of the "address" field content of each row one by one. If the type is not in the acquisition and transmission rule table, the corresponding row is discarded, otherwise the information of the corresponding row is extracted and saved in the corresponding member of the structure variable, and the structure variable is additionally stored in the corresponding data structure buffer; and after the last row is read, the value of the attribute of the "total number of data" element in the data description file is updated to the number of valid rows;
[0017] S6: The host computer sorts the structure variables of each data structure buffer in ascending order according to the addresses of the PLC variables stored in the members to form a sorted data structure buffer;
[0018] S7: The host computer takes out the sorted structure variables in the first buffer in sequence according to the order of the acquisition and transmission rule table, creates a new "transmission variable" sub-node element in the description file for each structure variable, and the sub-elements of the sub-node element at least include "name", "length" and "offset", and then writes the sub-node element to the "data domain" root node of the data description file;
[0019] S8: The host computer sequentially completes the extraction of all remaining buffer structure variables and the generation and writing of "transfer variable" sub-node elements according to the operations described in S7 to form the final data description file.
[0020] To achieve the above-mentioned purpose, the present invention also discloses a universal PLC data processing device, which is specifically a host computer, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the series of steps corresponding to the host computer in the above-mentioned method are implemented.
[0021] Preferably, the functional modules in the computer program include:
[0022] Control processing module: It is the main control module of the host computer software, used to initiate corresponding operations and complete the software's logic control, communication transmission control and data processing;
[0023] Rule database module: It is composed of a transmission rule database and corresponding operation interface functions. The transmission rule database contains a collection transmission rule table. Each collection transmission rule table corresponds to a specific model of PLC.
[0024] Symbol table processing module: used to complete the processing of the PLC symbol table, extract a row of the symbol table in turn, extract the PLC variable name from the "Symbol" column of the row, extract the type and starting address of the PLC variable from the "Address" column, and save the extracted information by the members of the structure variable, and store the structure variables in groups in the corresponding buffer;
[0025] Description file management module: used for writing and reading the data description file.
[0026] The present invention has the following beneficial effects:
[0027] 1. Split a single communication transmission protocol into two parts: the communication transmission protocol and a structured data description file. The data description file is used to describe the specific content of the "data domain" in the communication transmission protocol. The data description file can be automatically generated by the software, and the host computer can automatically process the data description file to obtain the detailed description of the binary byte stream in the "data domain". Compared with the traditional method, the communication transmission protocol no longer requires any PLC data description.
[0028] 2. Mainstream PLCs all support symbol tables, which contain information such as variable names, variable types, and starting addresses in the PLC. Therefore, the present invention processes the symbol table of the PLC through the host computer software, extracts the information of the variables in the symbol table, groups the variables according to the types, and sorts them according to the starting addresses of the variables, and further automatically generates a cross-platform universal data description file, which uses information such as data name, length, transmission order, offset, etc. to describe the composition of the "data domain" in the communication transmission protocol. During the communication transmission process, the PLC only needs to organize data upload according to the description file, and the host computer only needs to segment the binary data stream according to the description file to obtain all the data. A large amount of text definition work on the "data domain" in the communication transmission protocol in the prior art is completely discarded, which greatly simplifies the protocol formulation and negotiation process. Since the data description file adopts a fixed generation rule and has universality, the data acquisition and transmission between the host computer and the PLC are automated.
[0029] 3. The present invention can realize efficient reading and transmission of PLC data without the aid of PLC manufacturer's host computer software or third-party components, protocols, etc., and is applicable to any model of PLC.
[0030] 4. The present invention has no requirements on the operating system of the host computer and is applicable to any form of PC, tablet computer, embedded board, etc.
[0031] 5. Separating data description from the communication transmission protocol greatly simplifies the formulation of the communication transmission protocol and provides great convenience for communication and maintenance.
[0032] 6. The information of the data description file is extracted from the PLC symbol table and automatically generated by the software using fixed rules. No human intervention is required, which greatly reduces the workload and eliminates omissions and errors.
[0033] 7. When data on the PLC side is added or deleted, the host computer only needs to update the data description file according to the new symbol table, without any other communication.
[0034] 8. When the host computer software is rewritten or replaced, you only need to re-read the data description file.
[0035] 9. Very suitable for batch reading and transmission of PLC data.
[0036] The present invention will be further described in detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The drawings constituting a part of this application are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0038] Figure 1 It is a schematic diagram of the generation process of the data description file disclosed in the embodiment of the present invention.
[0039] Figure 2 It is a framework diagram of a PLC data processing system disclosed in an embodiment of the present invention.
[0040] Figure 3 It is a schematic diagram of the S7-200PLC collection and transmission rule table disclosed in the embodiment of the present invention.
[0041] Figure 4 It is a screenshot of partial contents of a data description file generated according to a PLC symbol table disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0042] The embodiments of the present invention are described in detail below with reference to the accompanying drawings, but the present invention can be implemented in many different ways as defined and covered by the claims.
[0043] Example 1
[0044] This embodiment discloses a general PLC data processing method. It mainly includes three parts: generating a data description file, formulating a communication transmission protocol, and transmitting data. The three parts are described in detail as follows:
[0045] 1. Reference Figure 1 , the process of generating a data description file is:
[0046] S1: Formulate a collection and transmission rule table to define the transmission rules of PLC data, where each row represents a PLC variable. The table contains several fields: "host computer variable type", "PLC variable type", "data length", and "classification number". The "host computer variable type" is the corresponding form of the "PLC variable type" in the host computer, the data length is the number of bytes occupied by the "PLC variable type" in the transmission, and the "classification number" is a numerical value used to act as a "command code" in communication.
[0047] S2: The host computer prepares a data structure buffer for each PLC variable according to the row order of the collection and transmission rule table described in S1 (each buffer can accommodate several structure variables, and the members of the structure variable are used to store the variable name, type and address parsed when reading the PLC symbol table). Each PLC variable (i.e., each of the buffers) can be regarded as a group.
[0048] S3: Export the PLC symbol table and save it as a .csv or other text format file. It is required to export at least the contents of the "Symbol" and "Address" columns, or the corresponding contents of other columns that can be equivalent to the fields representing the name, type and address of the PLC variable. The content of the "Symbol" column contains the name of the PLC variable, and the content of the "Address" column contains the type and starting address of the PLC variable.
[0049] S4: The host computer generates a new structured data description file, which can adopt the standard universal markup language (XML) format. First, a root node element is generated, such as a "data domain" element. Subsequent elements are nested in the "data domain" element, and a new "total number of data" child node element is created in the "data domain" element.
[0050] S5: The host computer reads the PLC symbol table file line by line, determines the PLC variable type of the "address" field content of the line, and discards the line if the type is not in the acquisition and transmission rule table described in S1, otherwise extracts the information of the line and saves it in the corresponding member of the S2 structure variable, and stores the structure variable in the corresponding data structure buffer (i.e., the group mentioned above). After the last line is read, the value of the attribute of the "total number of data" element in the data description file is updated to the number of valid lines.
[0051] S6: sorting the storage content (ie, structure variables) of each data structure buffer in S2 in ascending order according to the addresses of the PLC variables stored in the members to form a sorted data structure buffer.
[0052] S7: According to the order of the transmission rule table described in S1, the sorted contents (structure variables) in the first buffer are taken out in sequence, and a new "transmission variable" sub-node element is created in the description file for each structure variable. The element contains sub-elements such as "name", "length", and "offset". The value of the "length" element is the length of the PLC variable data of this type, in bytes. The "name" is the name of the PLC variable. Both values are obtained from the members of the structure variable. The "offset" is the starting position of the variable in the group, in bytes, which can be calculated in sequence. The sub-node element is written to the "data domain" root node of the data description file.
[0053] S8: According to the operation described in S7, the fetching of all remaining buffer structure variables and the generation and writing of "transfer variable" sub-node elements are completed in sequence to form the final data description file.
[0054] 2. There are two ways to formulate communication transmission protocols:
[0055] The first is to develop a communication transmission protocol. The developed protocol must have at least several fields: "data field length", "data field", and "command code". The "command code" field indicates which group of data needs to be uploaded by the PLC, or all groups of data can be uploaded together.
[0056] A simpler way is to use a known communication transmission protocol. The simplest way is to use the modbus protocol and use the "command code" 03H to transmit all grouped data at one time.
[0057] 3. The data communication transmission process is:
[0058] The PLC places the contents of each "transfer variable" in the data description file into a buffer with continuous addresses and updates the buffer contents in each scan cycle.
[0059] The host computer initiates a read command, and the PLC uploads the contents of the above buffer through a data frame in the format of the communication transmission protocol.
[0060] The host computer extracts the "data field" in the data frame through protocol analysis and processing, and temporarily stores it as a binary byte stream.
[0061] The host computer reads the data description file, and each time it obtains the content of a "transmission variable" sub-node element, it operates on the binary byte stream according to the "name", "length", and "offset" information provided by the element to obtain the variable name and binary value of the corresponding PLC data for subsequent processing.
[0062] Example 2
[0063] Corresponding to the above-mentioned embodiments, this embodiment discloses a universal PLC data processing device, which is specifically a host computer, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a series of steps corresponding to the host computer in the above-mentioned embodiment method when executing the computer program.
[0064] Among them, the interaction between the host computer and the PLC and the related data processing in this embodiment at least include:
[0065] Step S100: The host computer configures a data structure buffer according to the collection and transmission rule table created by the user;
[0066] Step S200, the host computer exports the PLC symbol table, selects records corresponding to the variable types of the acquisition and transmission rule table from the exported PLC symbol table, converts them into structure variables and stores them in groups in the corresponding data structure buffer, and creates a general data description file; the data description file is used to describe the number of structure variables associated with the data domain, the name, length and offset information of each structure variable and the sorting information in the data domain and is independent of the communication transmission protocol;
[0067] Step S300, the PLC puts the contents of the corresponding variables into a buffer with a continuous address in sequence according to the order of each structure variable in the data description file and updates the buffer content in each scanning cycle, and after receiving the read command from the host computer, the PLC uploads the contents of the buffer through a data frame according to the format of the communication transmission protocol; wherein the description of the PLC data determined by the data description file is omitted in the communication transmission protocol;
[0068] Step S400, the host computer extracts the data field in the data frame through protocol analysis and processing, and temporarily stores it as a binary byte stream; then automatically completes data extraction and analysis of the temporarily stored byte stream according to the data description file to obtain the binary value corresponding to each of the structure variable names in the data uploaded by the PLC.
[0069] like Figure 2As shown, the system used in this embodiment consists of three parts: PLC, physical channel, host computer and software: the PLC can be a PLC of any brand and model, the physical channel is a communication channel supported by both the PLC and the host computer (RS232, RS485, Ethernet or field bus interface, etc.), and the host computer can be a PC, tablet, embedded motherboard, etc. running any operating system.
[0070] The upper computer software is divided into control processing module, rule database module, symbol table processing module, description file management module and channel management module.
[0071] Control processing module: It is the main control module of the host computer software. All operations are initiated by this module to complete the software's logic control, communication transmission control, and data processing.
[0072] Rule database module: It is composed of a transmission rule database and corresponding operation interface functions. The database contains several acquisition and transmission rule tables, each of which corresponds to a specific model of PLC. The acquisition and transmission rule table generally contains fields such as "id", "host computer variable type", "PLC variable type", "data length", and "classification number". A row of the acquisition and transmission rule table represents a rule (for example, the analog input type AIW of the PLC is a rule), and the "id" field represents the order of the rules, which is also the order between PLC data groups. The "host computer variable type" and the "PLC variable type" are one-to-one corresponding. For example, the host computer variable type corresponding to the analog input AIW in the PLC is a 16-bit short integer, and the "data length" is the number of bytes occupied by the current variable type in the transmission. The "classification number" is used to distinguish data groups and is also used for the "command code" in the communication transmission protocol.
[0073] Symbol table processing module: This module completes the processing of the PLC symbol table saved in text format, extracts one row of the symbol table in turn, extracts the PLC variable name from the "Symbol" column of the row, and extracts the type and starting address of the PLC variable from the "Address" column. The extracted information is saved by the members of the S2 structure variable, and the structure variable is stored in the corresponding buffer of the group.
[0074] Description file management module: This module provides writing and reading of description files. Writing refers to writing a line of information in the processed symbol table into a "transmission variable" node in the description file. Reading refers to reading the values of each "transmission variable" node and sub-node in the description file into the memory, which is used to process the "data domain" binary byte stream received in the communication transmission.
[0075] Channel management module: provides a set of high-level channel read and write operation functions, so that the control processing module can use a unified interface to read and write different physical channels without having to worry about the details of each physical channel reading and writing, which facilitates program maintenance.
[0076] Example 3
[0077] This embodiment is an example of the specific application of the above two embodiments.
[0078] For the convenience of description, the following defines a structure variable named Var and a buffer vector used to store this structure variable. <structvar>Var contains three members: name, type, and address. The structure variables mentioned in the examples have the same structure as Var, and the data structure buffers mentioned are the same as vector. <structvar>With the same structure, this definition uses the C++ language description, but other high-level programming languages have equivalent functions:
[0079] Structure variable definition:
[0080] structVar{
[0081] stringname; / / name
[0082] stringtype; / / type
[0083] stringaddress; / / starting address
[0084] }
[0085] Buffer definition:
[0086] vector <structvar>
[0087] In this embodiment, the data transmission workflow between the host computer software and the PLC is specifically as follows:
[0088] S20: Determine whether the data description table exists, if yes, jump to S25 for execution. Otherwise, generate the data description table with S21-S24.
[0089] S21: The control processing module reads the corresponding rule table in the rule database according to the actual PLC type, and establishes a data buffer vector for each rule (each PLC variable type) <structvar>, used to store the above Var structure variables.
[0090] S22: The control processing module processes the symbol table exported by the PLC through the symbol table processing module, reading one line at a time to determine whether the variables in this line are allowed by the rules (for example, intermediate variables such as the PLC timer and counter have no communication transmission value, so they will not match the rules and are filtered out). If the rules allow, the PLC variable name, variable type, and starting address carried by this line are extracted and stored in the members of the structure variable Var, and the structure variable is stored in the corresponding data buffer according to the variable type.
[0091] S23: After completing the reading of all rows of the PLC symbol table, the control processing module follows the data buffer vector<struct Var> The structure variables in the buffer are sorted in sequence, and the sorting rule is the ascending order of the starting address of the PLC variable stored in the structure variable Var.
[0092] S24: The control processing module takes out all structure variables in sequence according to the sequence of the data buffer and the sequence of the structure variables in the buffer, and manipulates the description file management module to generate a "transmission variable" node for each structure variable, assigns values to the "name", "type", "length", and "offset" sub-elements of the node, and writes all "transmission variable" nodes into the "data domain" root node of the data description file in sequence.
[0093] S25: The control processing module requires the PLC to upload data according to the communication transmission protocol. The PLC puts the corresponding data into an area with continuous addresses in sequence according to the "transmission variable" node sequence of the data description file and places the area into the "data field" of the data frame for overall upload. The control processing module extracts the binary byte stream corresponding to the "data field" field and temporarily stores it in the memory.
[0094] S26: The control processing module reads the value of the "transmission variable" node into the memory through the description file management module, extracts the binary byte stream according to the information of the "transmission variable" node, and obtains the binary content of the corresponding data.
[0095] Example 4
[0096] This embodiment is a further example of the specific application scenario of Embodiment 3.
[0097] For the data collection and transmission of S7-200PLC, the specific process of formulating corresponding rule tables and generating data description files is as follows: Figure 3 , Figure 4 As shown:
[0098] S301: Generate an S7-200 rule table in the database, and add several data columns such as "id", "PLC variable type", "host computer variable type", "variable length" and "classification number" to the table, such as Figure 3 As shown in the figure, the "id" field data is used to classify different PLC variable types, and the "PLC variable type" field data is used to enumerate the PLC variable types that need to be transmitted through communication. In this example, they are switch input, output, analog input, output, and intermediate V register types. Considering that there is not much PLC data, the classification number directly uses the command code 03H in the modbus protocol, which means reading all at once.
[0099] S302: Export the S7-200PLC symbol table to the host computer. The software scans the rule table and reads Figure 3 According to the 11 rules in the symbol table, 11 structure variable buffers are established. For example, the 7th buffer is used to store analog input variables corresponding to the symbol table. Each time the software reads a line of the symbol table, it determines whether the variable type is in the rule table. For example, if the variable type in a line of the symbol table is AIW, the PLC variable name in the line is extracted and stored in the name member of Var. The type member of Var stores the corresponding variable type in the rule table. Address stores the address of the PLC variable, and the Var variable is stored in the 7th buffer. After all lines of the symbol table are extracted, the update of the 11 buffers is completed;
[0100] S303: According to the order of the buffers, sort each buffer in ascending order of the var variable address member to form a sorted buffer. Traverse the buffers one by one, take out a Var structure variable, generate a corresponding Transmission_variable node, and assign the value of the member variable of Var to the child element of the Transmission_variable (i.e., transmission variable) element. After all Var structure variables are traversed, generate a data description file, such as Figure 4 In the Transmission_variable element corresponding to the analog input variable "7# High Pressure Pump Pressure" in the PLC symbol table, the value of the name node is the variable name "7# High Pressure Pump Pressure", the value of the type node is the host computer variable type s16, the value of the length node is 2 bytes, and the value of the offset node is the offset 28 bytes. The PLC prepares data in the order of the description file, and the host computer software automatically completes the data extraction and parsing of the byte stream after reading the description file.
[0101] In summary, the general PLC data processing method and device disclosed in the above embodiments of the present invention respectively have at least the following beneficial effects:
[0102] 1. Split a single communication transmission protocol into two parts: the communication transmission protocol and a structured data description file. The data description file is used to describe the specific content of the "data domain" in the communication transmission protocol. The data description file can be automatically generated by the software, and the host computer can automatically process the data description file to obtain the detailed description of the binary byte stream in the "data domain". Compared with the traditional method, the communication transmission protocol no longer requires any PLC data description.
[0103] 2. Mainstream PLCs all support symbol tables, which contain information such as variable names, variable types, and starting addresses in the PLC. Therefore, the present invention processes the symbol table of the PLC through the host computer software, extracts the information of the variables in the symbol table, groups the variables according to the type, and sorts them according to the starting address of the variables, and further automatically generates a cross-platform universal data description file, which uses information such as data name, length, transmission order, offset, etc. to describe the composition of the "data domain" in the communication transmission protocol. During the communication transmission process, the PLC only needs to organize data upload according to the description file, and the host computer only needs to segment the binary data stream according to the description file to obtain all the data. A large amount of text definition work on the "data domain" in the communication transmission protocol in the prior art is completely discarded, which greatly simplifies the protocol formulation and negotiation process. Since the data description file adopts a fixed generation rule and has universality, the data acquisition and transmission between the host computer and the PLC are automated.
[0104] 3. The present invention can realize efficient reading and transmission of PLC data without the aid of PLC manufacturer's host computer software or third-party components, protocols, etc., and is applicable to any model of PLC.
[0105] 4. The present invention has no requirements on the operating system of the host computer and is applicable to any form of PC, tablet computer, embedded board, etc.
[0106] 5. Separating data description from the communication transmission protocol greatly simplifies the formulation of the communication transmission protocol and provides great convenience for communication and maintenance.
[0107] 6. The information of the data description file is extracted from the PLC symbol table and automatically generated by the software using fixed rules. No human intervention is required, which greatly reduces the workload and eliminates omissions and errors.
[0108] 7. When data on the PLC side is added or deleted, the host computer only needs to update the data description file according to the new symbol table, without any other communication.
[0109] 8. When the host computer software is rewritten or replaced, you only need to re-read the data description file.
[0110] 9. Very suitable for batch reading and transmission of PLC data.
[0111] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.< / structvar> < / structvar> < / structvar> < / structvar>
Claims
1. A general PLC data processing method, It is characterized in that include: Step S100: The host computer configures a data structure buffer according to the collection and transmission rule table created by the user; Step S200, the host computer exports the PLC symbol table, selects records corresponding to the variable types of the acquisition and transmission rule table from the exported PLC symbol table, converts them into structure variables and stores them in groups in the corresponding data structure buffer, and creates a general data description file; the data description file is used to describe the number of structure variables associated with the data domain, the name, length and offset information of each structure variable and the sorting information in the data domain and is independent of the communication transmission protocol; Step S300, the PLC puts the contents of the corresponding variables into a buffer with a continuous address in sequence according to the order of each structure variable in the data description file and updates the buffer content in each scanning cycle, and after receiving the read command from the host computer, the PLC uploads the contents of the buffer through a data frame according to the format of the communication transmission protocol; wherein the description of the PLC data determined by the data description file is omitted in the communication transmission protocol; Step S400, the host computer extracts the data field in the data frame through protocol analysis and processing, and temporarily stores it as a binary byte stream; then automatically completes data extraction and analysis of the temporarily stored byte stream according to the data description file to obtain the binary value corresponding to the name of each structure variable in the data uploaded by the PLC; The specific process of generating the data description file includes: S4: The host computer generates a new structured data description file in the standard universal markup language format. First, a "data domain" root node element is generated, and a "total number of data" child node element is created in the "data domain" root node element. S5: The host computer reads the PLC symbol table row by row, and determines the PLC variable type of the "address" field content of each row one by one. If the type is not in the acquisition and transmission rule table, the corresponding row is discarded, otherwise the information of the corresponding row is extracted and saved in the corresponding member of the structure variable, and the structure variable is additionally stored in the corresponding data structure buffer; and after the last row is read, the value of the attribute of the "total number of data" element in the data description file is updated to the number of valid rows; S6: The host computer sorts the structure variables of each data structure buffer in ascending order according to the addresses of the PLC variables stored in the members to form a sorted data structure buffer; S7: The host computer takes out the sorted structure variables in the first buffer in sequence according to the order of the acquisition and transmission rule table, creates a new "transmission variable" sub-node element in the description file for each structure variable, and the sub-elements of the sub-node element at least include "name", "length" and "offset", and then writes the sub-node element to the "data domain" root node of the data description file; S8: The host computer completes the extraction of all remaining buffer structure variables and the generation and writing of "transfer variable" sub-node elements in sequence according to the operations in S7 to form the final data description file.
2. The method according to claim 1, It is characterized in that Each row of the acquisition and transmission rule table represents a type of PLC variable that needs to be acquired by the host computer and contains at least four fields: "host computer variable type", "PLC variable type", "data length" and "classification number"; The host computer prepares a data structure buffer for each PLC variable according to the row order of the acquisition and transmission rule table. Each buffer can accommodate at least two structure variables. The members of the structure variables are used to store the variable name, type and address parsed from the read PLC symbol table.
3. The method according to claim 2, It is characterized in that During the communication and transmission process between PLC and host computer, the modbus protocol is used to upload all group data corresponding to each data structure buffer, and the corresponding classification number is 03H.
4. The method according to claim 1, It is characterized in that The exported PLC symbol table includes at least two columns: "Symbol" and "Address". The "Symbol" column contains the name of the PLC variable, and the "Address" column contains the type and starting address of the PLC variable.
5. The method according to claim 1, It is characterized in that The order of each structure variable in the data domain is based on the ascending order of the starting address for variables of the same type, and the order of variables of different types in the data domain is based on the row order of the transmission rule table.
6. The method according to claim 1, It is characterized in that Also includes: The exported PLC symbol table is converted into a file in .csv format or other text format for extracting the structure variables required by the data description file.
7. A general PLC data processing device, which is specifically a host computer, including a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the computer program, the processor implements a series of steps corresponding to the host computer in any one of the methods described in claims 1 to 6 above.
8. The device according to claim 7, It is characterized in that The functional modules in the computer program include: Control processing module: It is the main control module of the host computer software, used to initiate corresponding operations and complete the software's logic control, communication transmission control and data processing; Rule database module: It is composed of a transmission rule database and corresponding operation interface functions. The transmission rule database contains a collection transmission rule table. Each collection transmission rule table corresponds to a specific model of PLC. Symbol table processing module: used to complete the processing of the PLC symbol table, extract a row of the symbol table in turn, extract the PLC variable name from the "Symbol" column of the row, extract the type and starting address of the PLC variable from the "Address" column, and save the extracted information by the members of the structure variable, and store the structure variables in groups in the corresponding buffer; Description file management module: used for writing and reading the data description file.
9. The device according to claim 8, It is characterized in that The functional modules in the computer program also include: Channel management module: used to provide a set of high-level channel read and write operation functions, so that the control processing module uses a unified interface to read and write different physical channels without having to worry about the details of each physical channel.
Citation Information
Patent Citations
Reading and conversion method for PLC (Programmable Logic Controller) instruction storage rule in PMW-format file
CN103218349A
PLC universal platform and design method thereof
CN104238438A