Disclosure of Invention
In view of this, the present invention provides a data transmission method and apparatus for a measurement device, which solve the problem of data loss during the waiting process of the measurement device during data transmission. According to the invention, the data queues are introduced to store data, and the data are sent according to the pointer positions, so that the data of a plurality of queues can be simultaneously sent to an upper computer as a group of data, thereby avoiding the problem of display errors in the measurement process.
To achieve the above object, according to one aspect of the present invention, there is provided a data transmission method of a measuring apparatus.
The invention discloses a data transmission method of measuring equipment, which comprises the following steps: saving a plurality of preset data queues and a plurality of corresponding queue pointers and sending data pointers at a lower computer of the measuring equipment, wherein the number of the data queues is associated with the number of sensors of the measuring equipment; respectively storing the read data in the sensors in corresponding data queues, and increasing the corresponding queue pointer value by 1; when the queue pointer values are all larger than the sending data pointer value, sending a plurality of data of the position pointed by the sending data pointer to an upper computer of the measuring equipment as a group of data, and incrementing the sending data pointer value by 1; and displaying the data received by the upper computer on an output terminal of the measuring equipment.
Optionally, when the queue pointer reaches the tail of the data queue, the queue pointer points to the head of the data queue and stores data from the head of the data queue again.
Optionally, before storing the read data in the sensors in the corresponding data queues respectively, the method further includes: judging whether the next position pointed by one or more queue pointers in the queue pointers is the same as the current position pointed by the sending data pointer; and if the data are the same, the lower computer waits without data filling and sends alarm information.
Optionally, the position pointed to by the queue pointer or the send data pointer is determined by the queue pointer value or the send data pointer value taking the remainder of the length of the data queue.
To achieve the above object, according to another aspect of the present invention, there is provided a data transmission device of a measuring apparatus.
The data transmission device of the measuring equipment comprises: the storage configuration module is used for saving a plurality of preset data queues and a plurality of corresponding queue pointers and sending data pointers at a lower computer of the measuring equipment, wherein the number of the data queues is related to the number of sensors of the measuring equipment; the data storage module is used for respectively storing the read data in the sensors in corresponding data queues, and simultaneously increasing the corresponding queue pointer value by 1; a data sending module, configured to send, when the queue pointer values are all greater than the send data pointer value, a plurality of data at a position pointed by the send data pointer as a set of data to an upper computer of the measurement device, where the send data pointer value is incremented by 1; and the data display module is used for displaying the data received by the upper computer on an output terminal of the measuring equipment.
Optionally, when the queue pointer reaches the tail of the data queue, the queue pointer points to the head of the data queue and stores data from the head of the data queue again.
Optionally, the data storage module is further configured to: judging whether the next position pointed by one or more queue pointers in the queue pointers is the same as the current position pointed by the sending data pointer; and if the data are the same, the lower computer waits without data filling and sends alarm information.
Optionally, the position pointed to by the queue pointer or the send data pointer is determined by the queue pointer value or the send data pointer value taking the remainder of the length of the data queue.
According to still another aspect of the present invention, there is provided a data transmission apparatus of a measurement apparatus.
A data transmission device of a measurement device, comprising: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the data transmission method of the measuring equipment provided by the invention.
According to yet another aspect of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, implements the data transmission method of the measurement device provided by the present invention.
According to the technical scheme of the invention, the data queues are introduced to store data, and the data are sent according to the pointer positions, so that the problem of data loss in the waiting process of the measuring equipment during data transmission is solved, the data of the queues can be simultaneously sent to an upper computer as a group of data, and the sensor is prevented from covering the previously acquired values, thereby avoiding the problem of display errors in the measuring process.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a schematic diagram illustrating main steps of a data transmission method of a measurement device according to an embodiment of the present invention. As shown in fig. 1, the data transmission method of the measurement device of the present invention mainly includes the following steps S11 to S14.
Step S11: and storing a plurality of preset data queues and a plurality of corresponding queue pointers and sending data pointers at a lower computer of the measuring equipment. Wherein the number of data queues is associated with the number of sensors of the measurement device. For example, when a parcel is put in storage, 3 parameters of length, width and height of one parcel need to be measured, at the moment, programming can be carried out through an upper computer, and 3 data queues are arranged in a lower computer of the measuring equipment and are respectively used for storing the measured values of the 3 parameters of length, width and height read by the lower computer from the sensor. Meanwhile, 3 queue pointers are respectively set for pointing to the positions of the data stored in each data queue. In addition, a thread is started independently, 1 current data sending pointer is set for pointing to the position of a group of data which should be sent currently, and the thread polls continuously in the background.
Fig. 2 is a schematic diagram of a data queue of a data transmission method of a measurement device according to an embodiment of the present invention. 3 queue pointers are correspondingly arranged on the 3 data queues in the figure respectively and point to the data storage position. The length n of the 3 data queues can be flexibly set according to application needs. The transmit data pointer is not shown.
Step S12: and respectively storing the read data in the sensors in corresponding data queues, and increasing the corresponding queue pointer value by 1. When the queue pointer reaches the tail of the data queue, the queue pointer points to the head of the data queue, and stores data from the head of the data queue again. Before storing in the corresponding data queues, the following decisions are needed: firstly, judging whether the next position pointed by one or more queue pointers in the queue pointers is the same as the current position pointed by the sending data pointer; and if the data are the same, the lower computer waits without data filling and sends alarm information. Wherein the position pointed to by the queue pointer or the transmit data pointer is determined by the queue pointer value or the transmit data pointer value taking the remainder of the length of the data queue.
Step S13: when the queue pointer values are all larger than the sending data pointer value, sending a plurality of data of the position pointed by the sending data pointer to an upper computer of the measuring equipment as a group of data, and incrementing the sending data pointer value by 1.
Step S12 and step S13 are described in detail below in conjunction with fig. 2. After the startup initialization, all queue pointers and data sending pointers point to the position of 0, and all queue pointer values and data sending pointer values are 0. The lower computer reads the data in the sensors and respectively stores the values in the 3 sensors in 3 data queues, and meanwhile, the queue pointer moves to the right, and the value of the queue pointer increases by 1. When the data in the sensor is read and saved in the queue, and the values of 3 queue pointers are all greater than 0, for example, it is assumed that the values of queue pointer 1 and queue pointer 2 are both 1 and both point to position 1 of the corresponding queue, the value of queue pointer 3 is 2 and point to position 2 of queue 3, and the value of the transmit data pointer is 0. At this time, when the thread for setting the data sending pointer polls, the values of the 3 queue pointers are judged to be larger than the value of the data sending pointer, then the 3 data of the 3 queue positions 1 are sent to the upper computer as a group of data, and the value of the data sending pointer is increased by 1 and points to the position 1. Therefore, the thread for sending the data pointer is set to continuously poll, and when the values of the 3 queue pointers are judged to be larger than the value of the data pointer, the next data sending is carried out, otherwise, the data filling is waited.
When the queue pointer reaches the tail of the data queue, the queue pointer points to the head of the data queue and stores data from the head of the data queue again. At this time, the position pointed by the queue pointer or the sending data pointer is the queue length surplus set by the queue pointer value or the sending data pointer value. For example, assuming that the queue length is 100, when the data pointer value of queue 1 is greater than 100, for example 101, the position pointed to by queue pointer 1 is determined by 101 taking over 100, i.e. queue pointer 1 will point to position 1 again, and the read data will be stored at position 1 of queue 1.
It should be noted that, while reading data from the sensor, the thread reading sensor data in the lower computer may first perform a series of judgments to eliminate the occurrence of a failure. Firstly, judging whether the position pointed by the queue pointer is the same as the position pointed by the data sending pointer, and if the position pointed by the queue pointer is different from the position pointed by the data sending pointer, reading data from a sensor by a lower computer; if not, continuing to judge whether the queue pointer value is equal to the sending data pointer value, if so, indicating that the lower computer does not have the sending data, and reading the data from the sensor by the lower computer; otherwise, the data transmission pointer is blocked, the data cannot be uploaded on time, namely, a fault occurs, and the lower computer waits for the data filling, and sends out an alarm signal. For example, assuming a data queue length of 100, a current data send pointer value of 55 points to location 55 in the queue, and queue pointer values for 3 data queues are all 154 points to location 54 in the data queue. When the next group of data is read, the next position pointed by the queue pointer is judged to be 55, and the next position is the same as the current position pointed by the sending data pointer at the moment, which indicates that the sending data pointer is blocked and cannot process data on time, so that the lower computer waits for not filling data and sends out an alarm signal. And continuing to store the data until the fault is processed.
Step S14: and displaying the data received by the upper computer on an output terminal of the measuring equipment.
According to the steps, the lower computer stores data by using the queues and sends the data to the upper computer according to the pointer position, the data of the queues can be simultaneously sent to the upper computer as a group of data, and the sensor is prevented from covering the previously acquired values, so that the problem of display errors in the measurement process is avoided.
Fig. 3 is a flowchart illustrating steps of a data transmission method of a measurement device according to an embodiment of the present invention. The data transmission method of the measuring device of the present invention is described below with reference to the flowchart.
As shown in the flowchart of fig. 3, initialization is performed first (step S31), and a plurality of data queues and a plurality of corresponding queue pointers that are preset and transmission data pointers are saved at a lower computer of the measuring apparatus, where the number of the data queues is associated with the number of sensors of the measuring apparatus. For example, in the embodiment of the present invention, 3 sensors respectively measure the length, width, and height information of a package, 3 data queues and 3 corresponding queue pointers are correspondingly set, an individual thread is simultaneously started, and 1 current data sending pointer is set.
After the initialization is completed, before the read data in the sensor is stored in the data queue (step S34), the thread in the lower computer that reads the sensor data determines whether there is a failure. First, it is determined whether the next position pointed by one or more queue pointers is the same as the position pointed by the send data pointer (step S32), if not, it indicates no fault, and the read data in the sensor can be saved in the data queue (step S34); if the data pointer is the same as the data pointer, the data pointer is blocked, the data cannot be sent to the upper computer in time, the queue pointer circulates to the position pointed by the data pointer from the beginning after reaching the tail of the data queue, at the moment, the lower computer waits for data filling, sends alarm information (step S33), and stores the data after the fault is eliminated.
Meanwhile, the thread which sets the data sending pointer is continuously polled in the background, whether all queue pointer values are larger than the data sending pointer value is judged (step S35), if the queue pointer values are larger than the data sending pointer value, a group of data at the next position pointed by the data sending pointer in the 3 data queues is stored, the data is sent (step S36) to the upper computer to be displayed on the output terminal of the measuring equipment; otherwise, it will continue to wait for data stuffing (step S37).
According to the flow, data storage can be achieved by using the data queue, and data are sent to the upper computer according to the pointer position, so that the problem that data are lost in the waiting process when the sensor transmits data is solved.
Fig. 4 is a schematic diagram of main modules of a data transmission device of a measurement apparatus according to an embodiment of the present invention. As shown in fig. 4, the data transmission device 40 of the measurement apparatus of the present invention mainly includes a storage configuration module 41, a data storage module 42, a data transmission module 43, and a data display module 44.
The storage configuration module 41 is configured to save a plurality of preset data queues and a plurality of corresponding queue pointers and transmit data pointers at a lower computer of the measuring apparatus, where the number of the data queues is associated with the number of sensors of the measuring apparatus.
The data storage module 42 is configured to store the read data in the sensors in corresponding data queues, respectively, and increase the corresponding queue pointer value by 1. When the queue pointer reaches the tail of the data queue, the queue pointer points to the head of the data queue, and stores data from the head of the data queue again.
Data storage module 42 may be further configured to determine whether a next location pointed to by one or more of the queue pointers is the same as a current location pointed to by the send data pointer; and if the data are the same, the lower computer waits without data filling and sends alarm information. Wherein the position pointed to by the queue pointer or the transmit data pointer is determined by the queue pointer value or the transmit data pointer value taking the remainder of the length of the data queue.
The data sending module 43 is configured to send, when the queue pointer values are all greater than the sending data pointer value, a plurality of data at a position pointed by the sending data pointer as a group of data to an upper computer of the measurement device, and increment the sending data pointer value by 1.
And the data display module 44 is used for displaying the data received by the upper computer on an output terminal of the measuring equipment.
According to the technical scheme of the embodiment of the invention, the data queue is introduced to store data, and the data is sent according to the pointer position, so that the problem of data loss in the waiting process of the measuring equipment during data transmission is solved, the data of a plurality of queues can be simultaneously sent to an upper computer as a group of data, and the sensor is prevented from covering the previously acquired values, thereby avoiding the problem of display errors in the measuring process.
According to the technical scheme of the embodiment of the invention, the lower computer firstly stores the data and then moves the pointer after reading the data in the sensor, and also firstly sends the data and then moves the pointer when sending the data to the upper computer. In practical application, the pointer can be moved first and then the data can be stored or sent, and the data can also be stored or sent in a different sequence from the moving sequence of the pointer, and the like.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.