Disclosure of Invention
The invention provides a data acquisition method, a data acquisition device and a storage medium, and aims to solve the problem of large delay and low communication efficiency during data acquisition.
In order to achieve the above object, the present invention provides a data acquisition method, including:
step S1: clearing the execution marks of all the execution objects;
step S2: acquiring a first execution object in an execution object linked list, and reading the priority class of the execution object;
step S3: judging according to the priority class, and executing the step S4 when the priority class is the first priority; otherwise, executing step S7;
step S4: reading the device parameters of the execution object, obtaining the device data of the execution object based on the device parameters, and performing application processing;
step S5: judging a table pointer pNext in the execution object linked list, returning to the step S1 when the pNext is 0, otherwise executing the step S6;
step S6: reading the priority class of the next execution object according to the pointer direction of the table pointer pNext and returning to the step S3;
step S7: judging whether the execution flag of the execution object is set, if not, executing the step S8, otherwise, executing the step S5;
step S8: reading the priority class of the execution object and judging whether the priority class is the second priority, and executing the step S9 when the execution object is the second priority, otherwise executing the step S10;
step S9: returning to step S4 and setting the execution flag of the execution object;
step S10: reading the timer of the execution object and judging that the timer is effective due to expiration, executing the step S11 when the timer is effective due to expiration, otherwise returning to the step S5;
step S11: return to step S9 and reset the timer.
Further, the execution object linked list is constructed by a plurality of execution object links and a table pointer pNext, where the table pointer pNext is used for the link direction of the execution object.
Further, the execution object includes any one or more of a timer, a priority class, an execution flag, a device address, a function code, a register address, a register number, and a read-write data cache.
Further, the timer is used for timing transmission timing of the timing data with a long period.
Further, the priority class is used to identify a priority order; wherein the first priority is a highest priority for processing high real-time data; the second priority is a sub-optimal level for processing normal real-time data.
Further, the execution flag is a set flag for the execution object of the second priority to complete processing.
Further, the device address, the function code, the register address, the register number, and the read-write data buffer are used for communication packets.
Further, the data acquisition method is used for data acquisition of an RS-485 communication protocol.
In addition, the present invention provides a data acquisition apparatus, which includes a memory and a processor, wherein the memory stores a data acquisition program operable on the processor, and the data acquisition program implements the steps of the data acquisition method as described above when executed by the processor.
Meanwhile, the present invention provides a storage medium, which is a computer-readable storage medium, on which a data acquisition program is stored, where the data acquisition program can be executed by one or more processors to implement the steps of the data acquisition method as described above.
According to the data acquisition method, the data acquisition device and the storage medium, the data acquisition is processed through the priority level and the timer, the real-time response capability of key equipment data is improved, the real-time monitoring capability of a control system is greatly improved, the safety guarantee capability of the system is improved, meanwhile, the construction and maintenance cost of the control system is reduced, and the market popularization value is high.
The first embodiment is as follows:
in the first embodiment, the access priority of the device parameters is divided as follows: the high real-time data is of a first priority, the normal real-time data is of a second priority, and the long-period timing data is of a third priority (i.e., period control by a timer). In certain specific application areas, data priority types can be further subdivided or combined, and other similar prioritization and implementation methods are not specifically described in the text but still fall within the scope of the present invention.
Referring to FIG. 1, each access to a device parameter on the RS-485 bus has a specific communication protocol format, most commonly the Modbus communication protocol, such as the message format of a Modbus data read request sent by a host in FIG. 2, multiple parameters may exist in each device, and the register addresses between the multiple parameters may be consecutive or non-consecutive and may require different function codes to be used for the access. Because some extra protocol data overhead is needed during Modbus protocol communication, if each equipment parameter is acquired by using a separate message, the communication efficiency is greatly reduced, so that the parameters which need to be accessed and have continuous addresses are acquired by adopting the number of messages as small as possible in principle, and the communication efficiency is improved. However, if the high-priority device parameter is mixed in the bulk data, a communication message should be made for the high-priority device parameter separately, so as to reduce the acquisition time of the high-priority device parameter. In the data encapsulation of the device data access behavior, although the content of each communication message sent by the host is different, the basic formats of the messages are consistent, and all the messages include a device address, a function code, a register address, the number of registers and read-write data cache, specifically, in fig. 1, an address field refers to an ID of a device which the host wants to access, and the value of the ID is 1 to 127; the function code refers to an operation type which is indicated by the host to be executed by the accessed equipment and has a specific value; the register address refers to a starting address of a register, a coil and an input discrete quantity in the equipment which the host wants to access; the number of registers refers to the total number of registers, coils, input discrete quantities in the device that the host wants to access; the CRC check code is used for carrying out error check on the message data and ensuring the correctness of the data.
Therefore, the process of accessing the device parameters by the host is taken as an execution object, and the execution object comprises any one or more structures of a timer, a priority class, an execution mark, a device address, a function code, a register address, a register number and a read-write data cache; specifically, the timer is used for timing transmission timing of long-period timing data; the priority class is used for identifying a priority order; wherein the first priority is a highest priority for processing high real-time data; the second priority is a sub-optimal level for processing common real-time data; the execution flag is a set flag for the execution object of the second priority to complete processing; the device address, the function code, the register address, the register number and the read-write data cache are used for communication messages. And the execution objects are constructed into an execution object linked list in a linked list mode, the execution object linked list is constructed by a plurality of execution object links and a table pointer pNext, and the table pointer pNext is used for the link direction of the execution objects.
For example, in the first embodiment, the execution object is described based on a C + + programming language, and of course, the description of the execution object is not limited to the C + + programming language. The execution object is described as follows:
wherein, the member function DeviceAccess () is an application interface model related to basic functions of the Modbus protocol.
A plurality of different Access messages may exist in one device, each message corresponds to one Modbus _ Access object, so that a plurality of Access objects may exist in one device, the plurality of Access objects in a single device are connected into a linked list through a table pointer pNext to form an independent device Access object, and then a plurality of device objects on a bus form a linked list. Instead of setting up a separate device object, the access objects of all devices on a single RS-485 bus may be formed into a single linked list, and the single linked list is used for illustration in the first embodiment.
Referring to fig. 1, an embodiment of the present invention provides a data acquisition method, where the data acquisition method includes:
step S1: clearing the execution marks of all the execution objects;
step S2: acquiring a first execution object in an execution object linked list, and reading the priority class of the execution object;
step S3: judging according to the priority class, and executing the step S4 when the priority class is the first priority; otherwise, executing step S7;
step S4: reading the device parameters of the execution object, obtaining the device data of the execution object based on the device parameters, and performing application processing;
step S5: judging a table pointer pNext in the execution object linked list, returning to the step S1 when the pNext is 0, otherwise executing the step S6;
step S6: reading the priority class of the next execution object according to the pointer direction of the table pointer pNext and returning to the step S3;
step S7: judging whether the execution flag of the execution object is set, if not, executing the step S8, otherwise, executing the step S5;
step S8: reading the priority class of the execution object and judging whether the priority class is the second priority, and executing the step S9 when the execution object is the second priority, otherwise executing the step S10;
step S9: returning to step S4 and setting the execution flag of the execution object;
step S10: reading the timer of the execution object and judging that the timer is effective due to expiration, executing the step S11 when the timer is effective due to expiration, otherwise returning to the step S5;
step S11: return to step S9 and reset the timer.
Specifically, in the first embodiment, the whole execution object linked list is retrieved, and the execution object is directly executed as long as the retrieved execution object is the first priority execution object, otherwise, only one second-priority execution object is executed in each access execution object linked list retrieval cycle, that is, the second-priority execution object or the timing-expired third-priority execution object is executed, the second-priority execution object and the third-priority execution object compete for only one executed opportunity in each retrieval cycle of the execution object linked list, and then another second-priority execution object is executed in sequence and rotation when the execution object linked list retrieval cycle is accessed next time, so that all the second-priority execution objects and the timing-expired third-priority execution object can obtain a predictable execution opportunity.
Example two:
there are 12 devices on one RS-485 bus, each device has only one parameter (simplified description), A1, A2 are access execution objects of the first priority access parameter, B1, B2, B3, B4, B5, B6, B7, B8, B9 are access execution objects of the second priority access parameter, and C1 is access execution object of the timing access parameter.
The following steps are performed according to the data acquisition method:
step S1: clearing the execution marks of all the execution objects;
step S2: acquiring a first execution object in an execution object linked list, and reading the priority class of the execution object;
step S3: judging according to the priority class, and executing the step S4 when the priority class is the first priority; otherwise, executing step S7;
step S4: reading the device parameters of the execution object, obtaining the device data of the execution object based on the device parameters, and performing application processing;
step S5: judging a table pointer pNext in the execution object linked list, returning to the step S1 when the pNext is 0, otherwise executing the step S6;
step S6: reading the priority class of the next execution object according to the pointer direction of the table pointer pNext and returning to the step S3;
step S7: judging whether the execution flag of the execution object is set, if not, executing the step S8, otherwise, executing the step S5;
step S8: reading the priority class of the execution object and judging whether the priority class is the second priority, and executing the step S9 when the execution object is the second priority, otherwise executing the step S10;
step S9: returning to step S4 and setting the execution flag of the execution object;
step S10: reading the timer of the execution object and judging that the timer is effective due to expiration, executing the step S11 when the timer is effective due to expiration, otherwise returning to the step S5;
step S11: return to step S9 and reset the timer.
The priority access sequence obtained by using the method is as follows: when the timing access of C1 is not expired, the access sequence is A1-A2-B1, A1-A2-B2, A1-A2-B3, A1-A2-B4, A1-A2-B5, A1-A2-B6, A1-A2-B7, A1-A2-B8, A1-A2-B9; when the C1 timed access is effective, the access sequence is A1-A2-B1, A1-A2-B2, A1-A2-B3, A1-A2-B4, A1-A2-B5, A1-A2-B6, A1-A2-B7, A1-A2-B8, A1-A2-B9 and A1-A2-C1.
It can be seen that the first priority access parameters a1 and a2 can obtain an execution opportunity every three bus accesses, the data refresh rate is increased from one twelfth to one third of the conventional polling method, the data response speed is greatly increased, and the second-level response can be realized. The second priority parameters B1-B9 can obtain an execution opportunity every twenty-seven times of accesses, the data refresh rate is lower than that of the traditional polling method, but the real-time data acquisition can be ensured, and the general real-time application requirements can be met. The timing access parameters acquire data regularly according to the requirements of practical application, and the result of low communication efficiency caused by frequent occupation of bus communication time like the traditional polling method is avoided.
Compared with the prior art, the data acquisition method, the data acquisition device and the storage medium provided by the invention have the advantages that the data acquisition is processed through the priority level and the timer, the RS-485 bus is not required to be electrically transformed or additionally arranged, the real-time response capability of the data of the key equipment is improved in multiples, the real-time monitoring capability of the control system is greatly improved, the safety guarantee capability of the system is improved, the construction and maintenance cost of the control system is reduced, and the market popularization value is high.
The implementation method of the present invention is not limited to the above steps, and a method based on the central idea of multi-priority data collection should be considered to fall within the scope of the present invention.
In order to achieve the above object, the present invention further provides a data acquisition apparatus, which includes a memory and a processor, wherein the memory stores a data acquisition program operable on the processor, and the data acquisition program implements the steps of the data acquisition method when executed by the processor; the data acquisition method is used for data acquisition of an RS-485 communication protocol.
Furthermore, the present invention provides a storage medium, which is a computer-readable storage medium, on which a data acquisition program is stored, where the data acquisition program can be executed by one or more processors to implement the steps of the data acquisition method described above.
Referring to fig. 3, an internal structure diagram of a data acquisition device according to an embodiment of the present invention is provided, where the data acquisition device at least includes a memory 11, a processor 12, a communication bus 13, and a network interface 14.
The memory 11 includes at least one type of readable storage medium, which includes a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like. The memory 11 may in some embodiments be an internal storage unit of the data acquisition device, for example a hard disk of the data acquisition device. The memory 11 may also be an external storage device of the data acquisition apparatus in other embodiments, such as a plug-in hard disk provided on the data acquisition apparatus, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the memory 11 may also include both an internal storage unit of the data acquisition apparatus and an external storage device. The memory 11 may be used not only to store application software installed in the data acquisition apparatus and various types of data, such as codes of a data acquisition program, etc., but also to temporarily store data that has been output or is to be output.
The processor 12 may be a Central Processing Unit (CPU), a controller, a microcontroller, a microprocessor or other data Processing chip in some embodiments, and is used for executing program codes stored in the memory 11 or Processing data, such as executing a data acquisition program.
The communication bus 13 is used to realize connection communication between these components.
The network interface 14 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface), and is typically used to establish a communication link between the data acquisition device and other electronic devices.
Optionally, the data acquisition device may further include a user interface, the user interface may include a Display (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface may further include a standard wired interface and a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the data acquisition device and for displaying a visual user interface.
While fig. 3 shows only a data acquisition device having components 11-14 and a data acquisition program, those skilled in the art will appreciate that the configuration shown in fig. 3 does not constitute a limitation of the data acquisition device, and may include fewer or more components than shown, or some components in combination, or a different arrangement of components.
In the embodiment of the data acquisition apparatus shown in fig. 3, a data acquisition program is stored in the memory 11; the processor 12, when executing the data acquisition program stored in the memory 11, implements the following steps:
step S1: clearing the execution marks of all the execution objects;
step S2: acquiring a first execution object in an execution object linked list, and reading the priority class of the execution object;
step S3: judging according to the priority class, and executing the step S4 when the priority class is the first priority; otherwise, executing step S7;
step S4: reading the device parameters of the execution object, obtaining the device data of the execution object based on the device parameters, and performing application processing;
step S5: judging a table pointer pNext in the execution object linked list, returning to the step S1 when the pNext is 0, otherwise executing the step S6;
step S6: reading the priority class of the next execution object according to the pointer direction of the table pointer pNext and returning to the step S3;
step S7: judging whether the execution flag of the execution object is set, if not, executing the step S8, otherwise, executing the step S5;
step S8: reading the priority class of the execution object and judging whether the priority class is the second priority, and executing the step S9 when the execution object is the second priority, otherwise executing the step S10;
step S9: returning to step S4 and setting the execution flag of the execution object;
step S10: reading the timer of the execution object and judging that the timer is effective due to expiration, executing the step S11 when the timer is effective due to expiration, otherwise returning to the step S5;
step S11: return to step S9 and reset the timer.
Referring to fig. 4, a schematic diagram of program modules of a data acquisition program in an embodiment of the data acquisition apparatus of the present invention is shown, in this embodiment, the data acquisition program may be divided into a setting module 10, a determining module 20, a processing module 30, and an acquisition module 40, and exemplarily:
a setting module 10 for setting execution objects and priorities thereof;
a judging module 20, configured to judge to obtain an execution order based on the priority;
a processing module 30, configured to perform device data processing of the execution object and perform application processing;
and the acquisition module 40 is used for acquiring data of the execution object.
The functions or operation steps implemented when the program modules such as the setting module 10, the determining module 20, the processing module 30, and the collecting module 40 are executed are substantially the same as those of the above embodiments, and are not described herein again.
Furthermore, an embodiment of the present invention further provides a storage medium, where the storage medium is a computer-readable storage medium, and the storage medium stores a data acquisition program, where the data acquisition program is executable by one or more processors to implement the following operations:
step S1: clearing the execution marks of all the execution objects;
step S2: acquiring a first execution object in an execution object linked list, and reading the priority class of the execution object;
step S3: judging according to the priority class, and executing the step S4 when the priority class is the first priority; otherwise, executing step S7;
step S4: reading the device parameters of the execution object, obtaining the device data of the execution object based on the device parameters, and performing application processing;
step S5: judging a table pointer pNext in the execution object linked list, returning to the step S1 when the pNext is 0, otherwise executing the step S6;
step S6: reading the priority class of the next execution object according to the pointer direction of the table pointer pNext and returning to the step S3;
step S7: judging whether the execution flag of the execution object is set, if not, executing the step S8, otherwise, executing the step S5;
step S8: reading the priority class of the execution object and judging whether the priority class is the second priority, and executing the step S9 when the execution object is the second priority, otherwise executing the step S10;
step S9: returning to step S4 and setting the execution flag of the execution object;
step S10: reading the timer of the execution object and judging that the timer is effective due to expiration, executing the step S11 when the timer is effective due to expiration, otherwise returning to the step S5;
step S11: return to step S9 and reset the timer.
The specific implementation of the storage medium of the present invention is substantially the same as the embodiments of the data acquisition method and apparatus, and will not be described herein in a repeated manner.
It should be noted that the above-mentioned numbers of the embodiments of the present invention are merely for description, and do not represent the merits of the embodiments. And the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, apparatus, article, or method. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, apparatus, article, or method that comprises the element.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above, and includes instructions for enabling a terminal device (e.g., a drone, a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.