A method to improve PLC data acquisition efficiency
By setting read and write buffers in the PLC, centrally storing data and simplifying the communication instructions of the host computer, the problem of low data acquisition efficiency of PLC is solved, and more efficient communication and more flexible system configuration is achieved.
Patent Information
- Application Number
- CN202210796340.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-06
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2042-07-06
AI Technical Summary
In industrial control systems, the prior art is difficult to effectively improve the efficiency of PLC data acquisition, resulting in large programming workload, poor versatility, excessive read and write operations, and low communication efficiency.
By setting the read buffer and write buffer in the PLC, the switch quantity IO, analog quantity IO and other data are centrally stored. The host computer only needs to use one read instruction and one write instruction to complete communication with the PLC.
The code of the host computer communication program is simplified, the number of read and write times is reduced, the communication efficiency is improved, and data communication of different systems can be realized by modifying XML configuration files, saving development time.
Smart Images

Figure CN114995280B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of PLC data acquisition, and in particular to a method for improving PLC data acquisition efficiency. Background Art
[0002] At present, programmable logic controllers (PLCs) are widely used in the industrial field. Data communication between host computers and PLCs is an important part of PLC-based industrial control systems. Among them, Siemens PLCs are widely used in various industrial fields. With the development of Ethernet technology, most models of Siemens PLCs have Ethernet ports, which support communication with host computers via Ethernet.
[0003] In industrial control systems, there are usually multiple PLCs. The communication data between each PLC and the host computer includes multiple data types such as switch input / output, analog input / output, and control variables in the PLC (including bytes, words, double words, and floating points). Each data has a different address in the PLC memory. The host computer may use the data collected from each PLC for multiple different functions and occasions. Therefore, the host computer needs to carry out targeted design and programming for multiple communication data in each PLC, which is a lot of work, and its design and program cannot be universal.
[0004] Configuration software has good support for communication with PLC, but the host computer programs in many industrial control systems are not suitable for or have no intention to use configuration software as the host computer software. OPC server can be a proxy for communication, but designers need to do two parts of work, one is the communication between OPC server and PLC, and the other is the communication between host computer software and OPC server. Therefore, in many cases, OPC server is not an ideal choice.
[0005] When designing a PLC-based data acquisition system, it is a good choice to base it on some dynamic link libraries, such as Prodave provided by Siemens or the open source Linodave. The host computer program can read and write the specified IO points or memory data of the specified PLC by itself to complete data interaction. Designers need to design read and write programs for each switch IO point, each analog IO point, and the data in the memory in each PLC, and also need to perform data conversion on the analog IO points. Since the addresses of each IO point and the addresses of the control variables (data in the memory) are not continuous, the host computer needs to write a separate program for each address, resulting in two basic problems: (1) The programming workload is large and the versatility is not strong. The program of one project is difficult to directly apply to other projects; (2) There are too many read and write operations, the program execution time is long, and the communication efficiency is low. These two problems are more serious when there are many PLCs that need to communicate and the amount of data is large. Summary of the invention
[0006] The purpose of the present invention is to provide a method for improving the efficiency of PLC data acquisition, which aims to centralize the switch quantity IO, analog quantity IO and other data of the PLC with dispersed addresses into a read and write buffer, so that the host computer can complete the communication with the PLC through one read instruction and one write instruction, thereby simplifying the code of the host computer communication program, reducing the number of read and write times, and improving the communication efficiency.
[0007] In order to achieve the above object, the present invention provides a method for improving PLC data acquisition efficiency, which is applied to a PLC system, wherein the PLC system includes a host computer, a switch, and at least one PLC, wherein the host computer communicates with the at least one PLC through the switch, including:
[0008] Each PLC includes a read buffer and a write buffer, wherein the read buffer and the write buffer store at least data types including: switch quantity I / O, analog quantity I / O and control parameters;
[0009] The host computer is provided with a read buffer and a write buffer corresponding to each PLC;
[0010] The host computer sends a data reading instruction; so that each PLC confirms the corresponding data from the corresponding read buffer according to the reading instruction;
[0011] The host computer reads the data corresponding to the PLC;
[0012] The bit machine sends a data write instruction; so that each PLC confirms the data to be output from the corresponding write buffer according to the write instruction;
[0013] The host computer writes the data to be output into the write buffer corresponding to the PLC.
[0014] In one implementation, the read buffer and the write buffer include at least:
[0015] Starting address;
[0016] Offset;
[0017] the bit number corresponding to the offset;
[0018] Each bit number corresponds to a data address.
[0019] In one implementation, the step of the host computer reading the data corresponding to the PLC includes:
[0020] The host computer reads the byte array corresponding to the PLC;
[0021] The step of the host computer writing the data to be output into the write buffer corresponding to the PLC comprises:
[0022] The host computer packages the output data into a byte array, and writes the packaged byte array into the data corresponding to the PLC.
[0023] In one implementation, the step of the host computer reading the byte array corresponding to the PLC includes:
[0024] The host computer obtains the switch input according to the offset and bit address of the data byte in the read buffer, obtains the analog input according to the offset, and obtains the control variables of other data types according to the byte address, so as to unpack the byte array corresponding to the PLC and read the unpacked byte array.
[0025] In one implementation, the step of the host computer packaging the output data into a byte array includes:
[0026] The host computer obtains the switch input according to the offset and bit address of the data byte in the write buffer, obtains the analog input according to the offset, and obtains the control variables of other data types according to the byte address, so as to package the output data into a byte array.
[0027] In one implementation, the method further includes:
[0028] The host computer loads a data acquisition program component to enable one-time access to multiple PLCs;
[0029] The implementation of the data acquisition program component includes:
[0030] Create a dictionary to represent each PLC. The key of the dictionary is the PLC code specified by the user, and the value of the dictionary is an object representing the PLC class.
[0031] According to the setting of each PLC parameter, data is read or written to the actual PLC. In each PLC object, a byte array of data read from the PLC and a byte array of data to be written to the PLC are saved;
[0032] Read data from the PLC and write it into a byte array of the read data, then write the byte array of the written data into the PLC; after a write is completed, the program sleeps for a specified time, and then restarts a new read and write process:
[0033] The loop is executed until it exits.
[0034] In one implementation, the host computer and each PLC buffer are configured with corresponding configuration files, and the information of the PLC buffer is described by the corresponding configuration files.
[0035] In one implementation, the root data node of the configuration file is PLCs, the first layer data node is PLC, and there may be multiple PLC data nodes; each PLC data node contains multiple parameter data nodes.
[0036] In one implementation, the configuration file is an XML configuration file;
[0037] The host computer reads the corresponding XML configuration file, fills the PLC dictionary and the read-write buffer dictionary in each PLC according to the file content, and initializes the read-write buffer in each PLC according to the buffer length;
[0038] During data collection, the system will complete the communication between the host computer and the PLC according to the system described in the XML configuration file.
[0039] In one implementation, the XML configuration file is an editable and importable configuration file.
[0040] A method for improving PLC data acquisition efficiency provided by an embodiment of the present invention has the following beneficial effects:
[0041] 1. By centralizing the PLC's switch quantity IO, analog quantity IO and other data with scattered addresses into the read and write buffers, the host computer can complete the communication with the PLC through one read instruction and one write instruction, which simplifies the code of the host computer communication program, reduces the number of read and write times, and improves communication efficiency;
[0042] 2. The specific format of the read and write buffer can be specified by the user according to the requirements of the data acquisition system. Different data acquisition systems only need to modify the read and write buffer format without modifying the program;
[0043] 3. By adding an XML configuration file in a specified format, the communication program can obtain the corresponding system configuration; by modifying the configuration file, the communication program can complete the data communication of different systems, helping designers save a lot of development time and improve work efficiency;
[0044] 4. The host computer program unpacks the byte array read from the PLC, separates the actual switch quantity, analog quantity and other data, and converts them into the data types commonly used in the host computer; at the same time, the program packs the parameter values set by the user into the byte array and writes it to the PLC at one time. This method allows the user program to directly correspond to the IO points and data used by the acquisition system, while shielding the details of the technical implementation, so that the user thinks that he is directly facing the IO points and data, reducing the difficulty of writing the user program. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1It is a structural schematic diagram of a method for improving PLC data acquisition efficiency according to an embodiment of the present invention.
[0046] Figure 2 The present invention is a communication diagram of a method for improving PLC data collection efficiency according to an embodiment of the present invention.
[0047] Figure 3 The present invention is a flowchart of a method for improving PLC data acquisition efficiency according to an embodiment of the present invention.
[0048] Figure 4 It is a schematic diagram of a specific implementation of a method for improving PLC data acquisition efficiency according to an embodiment of the present invention. DETAILED DESCRIPTION
[0049] The following describes the embodiments of the present invention through specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention.
[0050] The illustrations provided in this embodiment are only used to illustrate the basic concept of the present invention in a schematic manner. Therefore, the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0051] It should be noted that if Figure 1 As shown, the present invention discloses a schematic diagram of a method for improving PLC data collection efficiency, which is applied to a PLC system, wherein the PLC system includes a host computer, a switch, and at least one PLC, wherein the host computer communicates with the at least one PLC via the switch. Figure 2 As shown, the technical solution provided by the present invention can be used in various data acquisition systems based on Siemens PLC. The following takes the use of two S7-200 SMART PLCs SR20 and SR40 for data acquisition as an example.
[0052] The hardware equipment of the acquisition system described in this example includes a PC, a switch, an S7-200 SMART PLC model SR20, and an S7-200 SMART PLC model SR40. The devices are connected by network cables. The IP address of the PC is planned to be 192.168.2.10, the IP address of the SR20 PLC is 192.168.2.11, and the IP address of the SR40 PLC is 192.168.2.12.
[0053] exist Figure 2 In the system shown, the points to be collected by SR20 include switch input points I0.0~I0.3, switch output points Q0.0~Q0.3, analog input point AIW16, and analog output point AQW16; the points to be collected by SR40 include switch input points I0.0~I0.5, switch output points Q0.0~Q0.2, analog input point AIW16, and analog output point AQW16.
[0054] According to the above system requirements, the input buffer in SR20 requires at least 3 bytes, and the output buffer requires at least 3 bytes. The input buffer in SR40 requires at least 3 bytes, and the output buffer requires at least 3 bytes. Therefore, both SR20 and SR40 are designed with 4 bytes for input buffer and 4 bytes for output buffer. In the buffer, a 1-byte position is left between the switch quantity and the analog quantity for easy expansion. The first address of the read buffer in the PLC storage area is 200, and the first address of the write buffer is 300. Table 1 is the data buffer of SR20PLC, and Table 2 is the data buffer of SR40PLC; in each PLC, data transfer instructions can be used to complete the interaction between the data in the buffer and the data on the actual IO point.
[0055] Table 1
[0056]
[0057] Table 2
[0058]
[0059] Each PLC includes a read buffer and a write buffer, wherein the read buffer and the write buffer store at least data types including: switch quantity I / O, analog quantity I / O and control parameters;
[0060] Specific steps are as follows Figure 3 As shown, including:
[0061] S101, the host computer sends a data reading instruction; so that each PLC confirms the corresponding data from the corresponding read buffer according to the reading instruction;
[0062] S102, the host computer reads the data corresponding to the PLC;
[0063] S103, the bit machine sends a data write instruction, so that each PLC confirms the data to be output from the corresponding write buffer according to the write instruction;
[0064] S104, the host computer writes the data to be output into the write buffer corresponding to the PLC.
[0065] In order to reduce the number of times the host computer reads and writes to the PLC, the switch I / O, analog I / O and control parameters (data in the memory) with scattered addresses are concentrated into two continuous storage areas in the PLC through the program in the PLC, which are named read buffer and write buffer respectively. The read buffer is the data read by the host computer from the PLC, including switch input, analog input, and control variables; the write buffer is the data written by the host computer to the PLC, including switch output, analog output and control parameters. In the buffer, the switch quantity occupies one bit, the analog quantity occupies two bytes, and other data can occupy bits, bytes, words or double words according to requirements. Table 1 gives an example of the buffer. The offset in Table 1 refers to the number of bytes starting from the first address of the buffer, the bit number refers to the bit in the byte, and the corresponding data address refers to the data address actually used in the PLC. Table 1 mainly uses switch quantity and analog input. If it is a write buffer, the corresponding data address is mainly switch quantity and analog output. The buffer may have spare addresses, that is, some bits or bytes in the buffer may not be used (such as the first bit of the byte with an offset of 1 in Table 1), but may still be read and written by the host computer.
[0066] The buffer determines the location and size of the buffer according to the starting address and the number of bytes. The host computer reads or writes the data of the entire buffer at one time, avoiding multiple reading and writing of data in different addresses of the PLC, thereby improving communication efficiency. The host computer acquisition software can use Prodave components or open source Libnodave components to directly read and write the read-write buffer in the PLC memory through Ethernet to complete communication.
[0067] The data read by the host computer is a byte array, which needs to be parsed out according to the actual situation, such as switch input, analog input, etc. On the other hand, the host computer program needs to package the specific output data, such as switch output, analog output, etc., into a byte array, and then write it into the PLC write buffer at one time.
[0068] The communication data of each PLC in multiple PLCs needs to be unpacked and packaged by the host computer.
[0069] When unpacking, the switch input is obtained according to the offset and bit address of the data byte in the read buffer, the analog input is obtained according to the offset, and the control variables of other data types are obtained according to the byte address. For example, in the read buffer shown in Table 1, the data of the 0th bit of the 0th byte represents I0.0; the data of the 2nd and 3rd bytes represent AIW16. When packing, the opposite process is used to save the data into the data byte.
[0070] Data conversion function. In the host computer, the switch quantity usually uses Boolean data, the analog quantity usually uses floating point data, and other types can be byte, short integer, integer, floating point, etc. In the data communicated with the PLC, the switch quantity is represented by 1 bit, and the analog quantity is represented by two bytes. The analog quantity in the PLC is a digital quantity within a certain digital range. The bytes in the PLC use Big Endian encoding, and the host computer uses Little Endian encoding. The host computer program completes the conversion of data type, range and encoding method while unpacking and packing.
[0071] The data acquisition program component can read and write a large number of byte arrays to multiple PLCs at one time, complete the unpacking and packing of data, complete the conversion of data type, range and encoding method, and provide an easily accessible interface to the outside world.
[0072] Use the following method:
[0073] Create a dictionary to represent each PLC. The key of the dictionary is the PLC code specified by the user, and the value of the dictionary is an object representing the PLC class, including the parameters shown in Table 3. The program reads or writes data to the actual PLC according to the setting of each PLC parameter. In each PLC object, a byte array of data read from the PLC and a byte array of data to be written to the PLC are saved. The program first reads data from the PLC and writes the byte array of read data, and then writes the byte array of written data to the PLC; after a write is completed, the program sleeps for a specified time, and then restarts a new read and write process: loop execution until the program exits.
[0074] Table 3 PLC parameters
[0075]
[0076] At the same time, in each PLC object, a dictionary of parameters read from the PLC and a dictionary of parameters to be written to the PLC are saved. The keys of the two dictionaries are the names of the parameters, and the values are objects representing the PLC parameter classes. Table 4 lists the information requirements for each parameter (IO point) contained in the PLC. Based on the information of each IO point, the program unpacks the byte array read from the PLC to obtain relevant data; or packs the data in the host computer into a byte array and writes it to the PLC.
[0077] Table 4 Information of parameters (IO points) in PLC
[0078] meaning Value range Parameter name The parameter object is usually identified by the PLC address of the input / output point. Data type of the parameter 0: switch quantity; 1: analog quantity. The byte offset of the argument in the buffer Start from 0. The bit number of the parameter in the byte The value range is [0,7], only used for switch value The maximum value of the parameter Only valid for analog quantity, used in D / A and A / D conversion Minimum value of the parameter Only valid for analog quantity, used in D / A and A / D conversion Analog type Current type, voltage type and other types and their value ranges
[0079] Analog quantity processing. The analog input read from the PLC is a two-byte integer. The program converts the two-byte integer into floating-point data in proportion according to the byte offset of the parameter in the buffer and the maximum and minimum value range of the parameter in Table 3, thereby obtaining the analog input value that can be directly used in the program. The floating-point analog data in the host computer is converted into double-byte integer data within the specified range by the program before being written to the PLC, and is stored in the write buffer according to the specified byte offset, and then written to the PLC.
[0080] Switch quantity processing. The switch quantity input read from the PLC is bit data. The program converts the bit data into Boolean data according to the byte offset of the parameter in the buffer and the bit number of the parameter in the byte in Table 3, thereby obtaining a switch input that can be used directly. Before writing the Boolean data in the host computer to the PLC, the program stores it in the write buffer according to the specified byte offset and bit number, and then writes it to the PLC.
[0081] When the user program reads data from the PLC, it does not need to understand the details of accessing the PLC, nor does it need to know the composition of the specific buffer. Instead, it only needs to obtain the parameter value through the PLC code and the parameter name of the parameter to be read in the PLC. The basic access format is:
[0082] PLC dictionary [PLC code]. Read parameter dictionary [parameter name]. Parameter value,
[0083] When the user program writes data to the relevant PLC, it uses a method similar to reading PLC data, indicating the PLC code to obtain the corresponding PLC, indicating the parameter name in the PLC, and then assigning the corresponding parameter value. The usage format is:
[0084] PLC dictionary [PLC code]. Read parameter dictionary [parameter name]. Parameter value = set value.
[0085] The data type of the parameter value can be switch quantity, analog quantity or other data types, and the user program can use it according to actual needs.
[0086] This method can shield the technical implementation details of the packaging, unpacking, data conversion and communication processes, greatly reducing the difficulty of writing user programs.
[0087] In order to ensure the reliability of the network connection between the PC and the PLC device, the present invention adopts a finite state machine design method to monitor the PC-PLC connection status, and can automatically try to reconnect when a connection error occurs until the connection is successful.
[0088] Specifically, the communication component includes a main control program class, which is used to improve the user interface and control the operation of the communication program. The core of the main control program is a dictionary, and its prototype is as follows:
[0089] Dictionary<string,Smart> plcs;
[0090] This dictionary is used to save Smart classes. Each Smart class object represents a PLC and contains parameters such as the PLC's IP address, read / write buffer, etc. This example includes two PLCs, one named SR20 and the other named SR40.
[0091] Each Smart class contains two byte arrays representing buffers, which are used to save data read from or ready to be written to the PLC. The prototype is as follows:
[0092] byte[]readbuf; / / buffer for data read from PLC
[0093] byte[]writebuf; / / Prepare to write data buffer of PLC
[0094] In this example, the length of the byte array of both SR20 and SR40 PLCs is 4 bytes, corresponding to the buffer.
[0095] At the same time, in each Smart class, there is a dictionary representing the read parameters and a dictionary representing the write parameters, whose prototypes are as follows:
[0096] Dictionary<string,PlcPara> ReadParams{get; private set;} / / read parameters
[0097] Dictionary<string,PlcPara> WriteParams{get; private set;} / / write parameters
[0098] The ReadParams dictionary is used to record the data separated from the read buffer byte array; the WriteParams dictionary is used to receive the assignment of the user program and packaged into the write buffer byte array by the program. The keys of the two dictionaries are parameter names, and the values are objects of the PlcPara class. An object of the PlcPara class represents a parameter. For details, see Table 2 and Table 5. For example, a PlcPara object can be used to represent the data of I0.0. The parameter name can be I0.0, the byte offset of the parameter is 0, and the bit number is 0.
[0099] The communication component reads the data in the read buffer of the PLC into the readbuf byte array at one time, and then accesses each parameter in the ReadParams dictionary in turn, parses the corresponding parameter value from the byte array according to the byte offset and bit number of the parameter record, and converts it to the appropriate data type. After reading the data, the program traverses the parameter values in WriteParams, converts the parameter values into bits or byte arrays in bytes according to the byte offset and bit number of the parameter record, assigns values to the writebuf byte array, and then writes it to the PLC at one time. In data conversion, the analog quantity is converted proportionally within the maximum and minimum value range.
[0100] In this example, the ReadParams in the SR20PLC contains 4 switch inputs and one analog input, and the WriteParams contains 4 switch outputs and one analog output; the ReadParams in the SR40 PLC contains 6 switch inputs and one analog input, and the WriteParams contains 3 switch outputs and one analog output. For easy access, each parameter uses its address as the parameter name.
[0101] Using the user program of this communication component, you can obtain the state of the switch input at address I0.0 in the following way:
[0102] plcs[SR20].ReadParams[I0.0].Value
[0103] The data to be output can be assigned in a similar way:
[0104] plcs[SR20].WriteParams[AQW16].Value = parameter value.
[0105] In this way, the details of technical implementation are shielded, allowing users to directly face the input / output points of the PLC, simplifying the program, improving design efficiency, and increasing accuracy.
[0106] In order to improve the efficiency of acquisition system programming, the communication component has been added with the function of reading XML-based configuration files. A special XML file format has been designed for this purpose, and the communication component's main control program has been added with the function of reading XML configuration files, so that the program can fill in the dictionary representing the PLC and the read-write parameter dictionary in each PLC according to the content of the XML file, and set the correct read-write buffer size.
[0107] In this way, the program can complete the data collection work for different systems by simply configuring the configuration file that meets the requirements of the system, thereby omitting the work of programming for technical details and only needing to write the configuration file according to the system requirements.
[0108] The configuration file for this example is as follows:
[0109] When the hardware device or its configuration information is updated, by updating the configuration file and then restarting the program, data collection can be completed according to the new hardware system, greatly improving the efficiency of program system design.
[0110] In addition, to further improve design efficiency, a configuration file editing tool is provided. The editing result of this example is as follows: Figure 4 As shown. The tool also provides the function of importing excel files. Users can also edit the configuration information of the acquisition system in excel, then import it into the tool and save it as an XML configuration file. In actual applications, the editing tool software is more used to fine-tune the configuration of existing systems, and the excel file is used for the initial design of the system. The two work together to greatly improve work efficiency. Table 5 and Table 6 are examples of tables in excel. Table 5 is the information table of the PLC in this example, and Table 6 is the information table of the collected parameters. Table 5 should be the first table in excel, and Table 6 is the second. The tool program will generate the corresponding configuration file based on this.
[0111] Table 5 PLC information table
[0112]
[0113] Table 6 Parameter information table collected by PLC
[0114] PLC Coding Input / Output name Data Types Byte offset Maximum Minimum Signal Type SR20 In I0.0 0 0 0 0 0 0 SR20 In I0.1 0 0 1 0 0 0 SR20 In I0.2 0 0 2 0 0 0 SR20 In I0.3 0 0 3 0 0 0 SR20 In AIW16 1 2 0 150 0 0 SR20 Out Q0.0 0 0 0 0 0 0 SR20 Out Q0.1 0 0 1 0 0 0 SR20 Out Q0.2 0 0 2 0 0 0 SR20 Out Q0.3 0 0 3 0 0 0 SR20 Out AQW16 1 2 0 60 0 0 SR40 In I0.0 0 0 0 0 0 0 SR40 In I0.1 0 0 1 0 0 0 SR40 In I0.2 0 0 2 0 0 0 SR40 In I0.3 0 0 3 0 0 0 SR40 In I0.4 0 0 4 0 0 0 SR40 In I0.5 0 0 5 0 0 0 SR40 In AIW16 1 2 0 6 0 0 SR40 Out Q0.0 0 0 0 0 0 0 SR40 Out Q0.1 0 0 1 0 0 0 SR40 Out Q0.2 0 0 2 0 0 0 SR40 Out AQW16 1 2 0 10 0 0
[0115] Furthermore, in order to improve the design efficiency, an XML configuration file is designed for the planned data acquisition system and the buffer of each PLC to describe the information of each PLC and data buffer in the system. The specific format is as follows:
[0116] The root data section of the file is PLCs, the first layer data section is PLC, and there can be multiple PLC data sections. Each PLC data section contains multiple parameter data sections, the meanings of which are shown in Table 7.
[0117] Table 7 Meaning of PLC data section in XML file
[0118]
[0119] The read / write parameter dictionary section contains multiple Param data sections representing parameters. The section records the parameter information, and its meaning is shown in Table 8.
[0120] Table 8 Meaning of parameter data section in XML file
[0121] name meaning Name Parameter name Type Data type of the parameter ByteOfset Byte offset from the start of the buffer Bit The bit number in the byte, especially for bool type Max The maximum value of the analog value represented by the parameter Min The minimum value of the analog quantity represented by the parameter Polar Polarity of analog-to-digital and digital-to-analog conversion
[0122] When the data acquisition component starts, it reads the corresponding XML configuration file, fills the PLC dictionary and the read-write buffer dictionary in each PLC according to the file content, and initializes the read-write buffer in each PLC according to the buffer length, preparing for data acquisition. During data acquisition, the system will complete the communication between the host computer and the PLC according to the system described in the XML configuration file.
[0123] After the user designs the acquisition system, he can write an XML file according to the composition of the acquisition system, and the acquisition component can complete the data acquisition work according to the parameters specified in the file. In this way, the process of data acquisition design can be simplified and the convenience of using PLC for data acquisition can be improved.
[0124] This tool can create, open, save and edit XML configuration files for PLC communication, including adding, deleting and editing PLC information, as well as adding, deleting and editing the read and write parameters of each PLC. Through this tool, you can easily edit the information of PLC and its communication parameters in the data acquisition system into the corresponding XML configuration files to improve work efficiency.
[0125] In addition to being able to edit XML files directly in the tool software, the tool also has the function of importing excel files. The excel file has a fixed format and consists of two tables. The first table records the information of all PLCs in the system; the second table records the read and write parameter information. Designers edit the excel table according to the composition of the data acquisition system, and then use the tool to import the edited excel table to generate a configuration file that meets the requirements. In actual applications, the editing tool software is more used to fine-tune the configuration of existing systems, and the excel file is used in the initial design of the system. The two work together to greatly improve work efficiency. In this way, the data acquisition system can be completed faster.
[0126] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A method for improving PLC data acquisition efficiency, applied to a PLC system, wherein the PLC system comprises a host computer, a switch, and at least one PLC, wherein the host computer communicates with the at least one PLC via the switch, and wherein: include: Each PLC includes a read buffer and a write buffer, wherein the read buffer and the write buffer store at least data types including: switch quantity I / O, analog quantity I / O and control parameters; The host computer is provided with a read buffer and a write buffer corresponding to each PLC; The host computer sends a data reading instruction; so that each PLC confirms the corresponding data from the corresponding read buffer according to the reading instruction; The host computer reads the data corresponding to the PLC; The host computer sends a data write instruction; so that each PLC confirms the data to be output from the corresponding write buffer according to the write instruction; The host computer writes the data to be output into the write buffer corresponding to the PLC; The step of the host computer reading the data corresponding to the PLC includes: The host computer reads the byte array corresponding to the PLC; The step of the host computer writing the data to be output into the write buffer corresponding to the PLC comprises: The host computer packages the output data into a byte array, and writes the packaged byte array into the data corresponding to the PLC; The step of the host computer reading the byte array corresponding to the PLC includes: The host computer obtains the switch input according to the offset and bit address of the data byte in the read buffer, obtains the analog input according to the offset, and obtains the control variables of other data types according to the byte address, so as to unpack the byte array corresponding to the PLC and read the unpacked byte array.
2. A method for improving PLC data acquisition efficiency according to claim 1, characterized in that: The read buffer and the write buffer at least include: Starting address; Offset; the bit number corresponding to the offset; Each bit number corresponds to a data address.
3. A method for improving PLC data acquisition efficiency according to claim 1, characterized in that: The step of the host computer packaging the output data into a byte array includes: The host computer obtains the switch input according to the offset and bit address of the data byte in the write buffer, obtains the analog input according to the offset, and obtains the control variables of other data types according to the byte address, so as to package the output data into a byte array.
4. A method for improving PLC data acquisition efficiency according to claim 1, characterized in that: The method further comprises: The host computer loads a data acquisition program component to enable one-time access to multiple PLCs; The implementation of the data acquisition program component includes: Create a dictionary to represent each PLC. The key of the dictionary is the PLC code specified by the user, and the value of the dictionary is an object representing the PLC class. According to the setting of each PLC parameter, data is read or written to the actual PLC. In each PLC object, a byte array of data read from the PLC and a byte array of data to be written to the PLC are saved; Read data from the PLC and write it into a byte array of the read data, then write the byte array of the written data into the PLC; after a write is completed, the program sleeps for a specified time, and then restarts a new read and write process: The loop is executed until it exits.
5. A method for improving PLC data acquisition efficiency according to claim 1, characterized in that: The host computer and each PLC buffer are configured with corresponding configuration files, and the information of the PLC buffer is described by the corresponding configuration files.
6. A method for improving PLC data acquisition efficiency according to claim 5, characterized in that: The root data node of the configuration file is PLCs, the first layer of data nodes is a PLC data node, and there are multiple PLC data nodes; each PLC data node contains multiple parameter data nodes.
7. A method for improving PLC data acquisition efficiency according to claim 6, characterized in that: The configuration file is an XML configuration file; The host computer reads the corresponding XML configuration file, fills the PLC dictionary and the read-write buffer dictionary in each PLC according to the file content, and initializes the read-write buffer in each PLC according to the buffer length; During data collection, the system will complete the communication between the host computer and the PLC according to the system described in the XML configuration file.
8. A method for improving PLC data acquisition efficiency according to claim 7, characterized in that: The XML configuration file is an editable and importable configuration file.
Citation Information
Patent Citations
Method and device for reading and writing PLC data
CN108037725A
Batch reading method, batch writing method, corresponding devices for PLC (programmable logic controller) and system
CN110262370A