A serial real-time data uploading response communication method

By combining data frames and command frames, the problem of disordered data upload order and communication overhead in the data acquisition system is solved, realizing efficient and real-time data transmission, which is suitable for application scenarios with high sampling rates and small data volumes.

CN117331864BActive Publication Date: 2026-06-12HUBEI FANGYUAN ENVIRONMENTAL PROTECTION SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUBEI FANGYUAN ENVIRONMENTAL PROTECTION SCI & TECH CO LTD
Filing Date
2023-09-27
Publication Date
2026-06-12

AI Technical Summary

Technical Problem

In data acquisition systems, real-time uploaded sampling data is prone to disorder due to interference and bit errors. Furthermore, the host computer cannot distinguish the settings and monitoring information of the slave computer. Conventional communication methods increase communication overhead, affecting the real-time performance and accuracy of the data.

Method used

A communication method combining data frames and command frames is adopted. Data frames are short frames without frame headers or trailers and are distinguished by encoding and reassembly flags. Command frames are long frames encapsulated to process real-time and non-real-time data respectively, ensuring data frame order and communication efficiency.

🎯Benefits of technology

It enables real-time and accurate data uploading at high sampling rates, reduces communication overhead, and improves communication efficiency, making it particularly suitable for real-time uploading scenarios with small data volumes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117331864B_ABST
    Figure CN117331864B_ABST
Patent Text Reader

Abstract

The application provides a serial port real-time data uploading response communication method, a data frame format is used when a lower computer uploads real-time data, and a response command frame format is used when the lower computer responds to a host computer command. The data frame is a short frame, each data frame is one byte, one real-time data uploading is divided into one or more data frames, there is no frame header and frame tail, and only limited bit positions are used for distinguishing; the command frame is a long frame, and the command data is encapsulated through the frame header and the frame tail. By using the encoding mode, the data frame and the command frame can be distinguished, and each byte of the data frame can also be distinguished in sequence, the host computer can conveniently recombine data when decoding, and error frame data can be found in time. The real-time data of the lower computer is transmitted by using the short frame, and the command response data which is not real-time and has relatively large data volume is transmitted by using the long frame, so that the real-time data uploading is not affected, and the monitoring information uploading problem is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of communication technology, and in particular to a response communication method for real-time data upload via serial port. Background Technology

[0002] In some data acquisition systems, the lower-level device needs to upload real-time sampled data to the upper-level device via a serial communication port. Simultaneously, the upper-level device needs to use this communication port to set parameters and monitor the operational status of the lower-level device. Depending on the size of the data, this real-time uploaded sampled data may require one or more bytes. At high sampling rates, interference and bit errors during real-time upload can cause sequence disorder, potentially leading the upper-level device to incorrectly reassemble multiple bytes of a single sampled data, resulting in erroneous results. Furthermore, the upper-level device cannot distinguish between the setting and monitoring information sent by the lower-level device.

[0003] The conventional communication method involves the lower-level machine uploading sampled data in real time and the response communication between the upper and lower-level machines using a uniformly encapsulated frame structure. This frame structure requires the addition of corresponding frame headers, frame trailers, and other fields for easy parsing. This adds several extra bytes of frame information to each real-time uploaded sampled data, increasing communication overhead. At higher sampling rates, the real-time nature of the uploaded sampled data cannot be guaranteed, leading to data loss. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a serial port real-time data upload response communication method. The data uploaded by the lower-level machine is transmitted using two different frame structures based on the transmitted data and response commands. The lower-level machine uses a data frame format for uploading real-time data, and a response command frame format for responding to commands from the upper-level machine. Data frames are short frames, each consisting of one byte. A single real-time data upload is divided into one or more data frames, without frame headers or trailers, distinguished only by a limited number of bits. Command frames are long frames, encapsulating the command data through frame headers and trailers. This encoding method not only distinguishes between data frames and command frames but also allows for sequential differentiation of the individual bytes within a data frame. This facilitates data reconstruction during decoding by the upper-level machine and enables timely detection of erroneous frames. The lower-level machine transmits real-time data in short frames, while non-real-time command response data with a relatively large volume is transmitted in long frames. This approach solves the problem of uploading monitoring information without affecting real-time data upload.

[0005] The technical solution adopted by this invention to solve its technical problem is: a response communication method for real-time data upload via serial port, comprising the following steps:

[0006] S1. The lower-level machine sends data frame groups to the upper-level machine in real time. The data frame group is composed of data frames. Each data frame is obtained by encoding each group of data after splitting the real-time data to be sent by the lower-level machine to the upper-level machine. The length of each data frame is 1 byte, where the first n+1 bits are the encoding reassembly flag bits and the last 7-n bits are the data bits, 0 < n < 7.

[0007] S2. After receiving the data frame group sent by the lower computer, the host computer reassembles the data bits of each data frame into valid real-time data according to the encoding method represented by the encoding reassembly flag bit.

[0008] S3. When the host computer receives a command message from the host computer, it parses the command message and encapsulates the information to be returned according to the parsing of the command message, forming a response command frame consisting of a frame header, data message, and frame trailer, and sends it to the host computer. During the transmission of the response command frame, the transmission of measurement data is stopped. The first n+1 bits of the frame header and frame trailer are encoding and reassembly flag bits, and the last 7-n bits are data bits, where 0 < n < 7.

[0009] S4. After receiving the frame header of the response command frame from the slave device, the host computer continues to receive the data message and frame tail of the response command frame. At the same time, it determines whether the reception of the response command frame is complete by combining the length of the data message content and the frame tail data. If the command frame reception is complete, the host computer parses the command response frame according to the data message in the response command frame and performs corresponding processing.

[0010] n takes values ​​from 1 to 3.

[0011] In the response command frame of the lower-level machine, the data message consists of message length, frame type, message content, and checksum.

[0012] The beneficial effects of this invention based on its technical solution are as follows:

[0013] This invention provides a serial port real-time data upload response communication method that combines data frame and command frame structures. The data that the lower-level machine needs to report in real time is encoded with corresponding flag bits and then split and reassembled into corresponding data frames. The header and trailer of the command frame are uniformly encoded with flag bits according to the same rules, forming a command frame structure of "frame header + data packet + frame trailer". When the lower-level machine sends data to the upper-level machine, it uses the above data frame structure. Upon receiving data, the upper-level machine parses whether the received data is a data frame or a command frame based on the corresponding flag bit encoding. If the received data is parsed as a data frame, it reassembles it into the corresponding actual real-time data according to the flag bit encoding rules. After receiving the header of the lower-level machine's response command frame, the upper-level machine continues to receive the data packet and trailer of the response command frame. While receiving the command frame data, it determines whether the reception of the response command frame is complete by combining the length of the data packet content and the trailer data. Once the command frame reception is complete, the upper-level machine parses the command response frame based on the data packet in the response command frame and performs corresponding processing. Based on this, while the lower-level machine uploads a small amount of real-time data, it also solves the problem of parameter setting and monitoring information transmission from the upper-level machine. Command frames can be divided into different command frames based on their data message structure. Command frames are further divided into multiple command frames according to their frame type, such as read status commands and set parameter commands. The data message length of each command frame may vary. This communication mechanism, which combines data frames and command frames, has the advantages of low communication overhead and high communication efficiency when the amount of real-time data uploaded by the lower-level machine is small. Attached Figure Description

[0014] Figure 1 This is a schematic diagram of the response command frame and data frame structure in a serial port real-time data upload response communication method provided by the present invention. Detailed Implementation

[0015] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0016] This invention provides a response communication method for real-time data upload via serial port, referring to... Figure 1 This includes the following steps:

[0017] S1. The lower-level machine sends data frame groups to the upper-level machine in real time. The data frame group is composed of data frames. Each data frame is obtained by encoding each group of data after splitting the real-time data to be sent by the lower-level machine to the upper-level machine. The length of each data frame is 1 byte, where the first n+1 bits are the encoding reassembly flag bits and the last 7-n bits are the data bits, 0 < n < 7.

[0018] S2. After receiving the data frame group sent by the lower computer, the host computer reassembles the data bits of each data frame into valid real-time data according to the encoding method represented by the encoding reassembly flag bit.

[0019] S3. When the host computer receives a command message from the host computer, it parses the command message and encapsulates the information to be returned according to the parsing of the command message, forming a response command frame consisting of a frame header, data message, and frame trailer, and sends it to the host computer. During the transmission of the response command frame, the transmission of measurement data is stopped. The first n+1 bits of the frame header and frame trailer are encoding and reassembly flag bits, and the last 7-n bits are data bits, where 0 < n < 7.

[0020] S4. After receiving the frame header of the response command frame from the slave device, the host computer continues to receive the data message and frame tail of the response command frame. At the same time, it determines whether the reception of the response command frame is complete by combining the length of the data message content and the frame tail data. If the command frame reception is complete, the host computer parses the command response frame according to the data message in the response command frame and performs corresponding processing.

[0021] In the response command frame of the lower-level machine, the data message consists of message length, frame type, message content, and checksum.

[0022] The following explains the possible values ​​of n.

[0023] Assuming the lower-level machine needs to upload y bits of valid data in real time, after adding flag bits, the number of data frames after encoding and reassembly is z bytes. Adding one command frame, the total number of communication frames sent from the lower-level machine to the upper-level machine is z+1. The number of flag bits required for encoding and reassembly is n+1, where n<7. Therefore:

[0024] y = [8 - (n+1)] * z (1)

[0025] 2 n < z+1 ≤ 2 n+1 (2)

[0026] Case 1: In the communication frame uploaded by the lower-level machine, 1 bit is used as a flag bit, i.e., n+1=1. Substituting into equation (2), we get z=1, which means that the data frame encoded as the communication frame is 1 frame. Substituting into formula (1), we get y=7, which means that the data frame uploaded by the lower-level machine can contain 7 bits of valid data. The communication frame structure contains 1 data frame and 1 command frame.

[0027] Case 2: The communication frame uploaded by the lower-level machine uses 2 bits as a flag bit, i.e., n+1=2. Substituting into formula (2), we get z=2 or z=3. That is, the data frame used as the communication frame encoding can be 2 or 3 frames. Substituting z=2 and z=3 into formula (1) respectively, we get y=12 and y=18. That is, when the communication frame uploaded by the lower-level machine uses 2 bits as a flag bit, the data frame that can be encoded can be 2 or 3 frames. When the data frame is 2 frames, the 2 data frames can contain 12 bits of valid data. The frame structure uploaded by the lower-level machine contains 2 data frames and 1 command frame. When the data frame is 3 frames, the 3 data frames can contain 18 bits of valid data. The frame structure uploaded by the lower-level machine contains 3 data frames and 1 command frame.

[0028] Case 3: The communication frame uploaded by the lower-level machine uses 3 bits as a flag bit, i.e., n+1=3. Substituting into formula (2), we get z=4, z=5, z=6 or z=7. That is, the data frame used as the communication frame encoding can be 4, 5, 6 or 7 frames. Substituting z=4, z=5, z=6 or z=7 into formula (1), we get y=20, y=25, y=30 or y=35. That is, when the communication frame uploaded by the lower-level machine uses 3 bits as a flag bit, the maximum number of data frames that can be encoded is 7.

[0029] When there are 4 data frames, each data frame can contain 20 bits of valid data. The frame structure for lower-level machine upload communication includes 4 data frames and 1 command frame. When there are 5 data frames, each data frame can contain 25 bits of valid data. The frame structure for lower-level machine upload communication includes 5 data frames and 1 command frame. When there are 6 data frames, each data frame can contain 30 bits of valid data. The frame structure for lower-level machine upload communication includes 6 data frames and 1 command frame. When there are 7 data frames, each data frame can contain 35 bits of valid data. The frame structure for lower-level machine upload communication includes 7 data frames and 1 command frame.

[0030] Similarly, by using more bits as flag bits in the communication frames uploaded by the lower-level machine, the effective real-time data bit length corresponding to the number of data frames in the corresponding communication frames can be calculated.

[0031]

[0032]

[0033] Table 1 shows the frame structure encoded using 1-4 flag bits.

[0034] Table 1 shows the frame structure design using 1 to 4 flag bits encoded according to equations (1) and (2).

[0035]

[0036] Table 2 Comparison of data transmission efficiency

[0037] Table 2 shows the communication comparison between the multi-short frame structure of the present invention and the traditional frame structure (frame header + data packet length + frame type + data packet + checksum + frame tail) calculated according to the number of bits of data uploaded by the lower-level machine in real time, based on formulas (1) and (2). When the effective data to be transmitted by the lower-level machine is less than or equal to 35 bits and less than 4 bits of encoding is used, the data transmission efficiency of the present invention is more than 143% of that of the traditional frame structure.

[0038] It can be seen that as the number of flag bits increases, the data frame overhead increases significantly. When the number of flag bits used for encoding is greater than 3, the communication overhead for real-time data upload is large. Therefore, the response communication method based on real-time serial port data upload provided by this invention is particularly suitable for applications where the amount of real-time data upload is not large. For example, if the lower-level machine is a voltage data acquisition device, using a 16-bit A / D converter to sample one voltage signal, it needs to sample voltage fluctuations in real time with a high sampling rate. Each sampled voltage data needs to be uploaded to the upper-level machine in real time. According to the formula, it is calculated that the corresponding 18-bit row can be transmitted to the upper-level machine in 3 bytes. However, if the traditional method is used, a frame header, data length, frame type, checksum, and frame trailer need to be added, totaling 8 bytes, which is 5 extra bytes and greatly affects the communication efficiency.

[0039] This embodiment uses the real-time uploading of 12-bit measurement data by a lower-level machine as an example to illustrate the process.

[0040] Reference Figure 1 The lower-level machine needs to upload valid data y = 12 bits, that is, at least 2 bytes. The minimum number of data frames in the communication frame is 2, that is, z = 2. According to equations (1) and (2), n = 1 can be obtained, that is, the flag bit of the communication frame needs to be 2 bits. Assuming that the two high bits of the communication frame byte, namely bit7 and bit6, are used as flag bits, bit7 and bit6 are defined as: 00 - first data frame; 01 - second data frame; 10 - invalid data; 11 - frame header and frame tail of command frame.

[0041] The 12-bit measurement data is split into its high 6 bits and low 6 bits. The high 6 bits are placed into the low 6 bits of the first byte, with the high two bits (bits 7 and 6) set to 00. The low 6 bits are placed into the low 6 bits of the second byte, with the high two bits (bits 7 and 6) set to 01. The command frame header and trailer each use 1 byte, with the high two bits (bits 7 and 6) set to 11. The header is defined as 11001110 (hexadecimal CE), and the trailer header is defined as 11001101 (hexadecimal CD). The command frame is defined as: header + data packet + trailer format, where the data packet is defined as: packet length (1 byte) + frame type (1 byte) + packet (length equal to packet length) + checksum (1 byte), such as... Figure 1 As shown.

[0042] When uploading measurement data, the lower-level computer sends 12-bit measurement data HHHHHHLLLLLL in real time, splits HHHHHHLLLLLL into two bytes: 00HHHHHH and 01LLLLLL, and uploads these two bytes to the upper-level computer. After receiving 00HHHHHH and 01LLLLLL from the lower-level computer, the upper-level computer reassembles them into valid 12-bit measurement data HHHHHHLLLLLL according to the flag bit encoding rules.

[0043] When the slave device receives a command from the host computer, it parses the message content, encapsulates the parsed command requirements according to the command frame format, and assembles the data to be returned into a data packet. This data packet, along with the frame header (CE) and frame trailer (CD), forms a command response frame consisting of a "frame header + data packet + frame trailer," which is then sent to the host computer. The slave device stops sending data frames during the transmission of the command response frame. After receiving the frame header of the slave device's response command frame, the host computer continues to receive the data packet and frame trailer of the response command frame. While receiving the command frame data, the host computer uses the length of the data packet content and the frame trailer data to determine whether the reception of the response command frame is complete. If the command frame reception is complete, the host computer parses the command response frame according to the data packet in the response command frame and performs the corresponding processing.

[0044] This invention provides a response communication method based on real-time data upload via serial port. By encoding the header and trailer of the command frame together with the real-time uploaded data, the lower-level computer uploads the recombined encoded data frame and command frame to the upper-level computer. After receiving the data, the upper-level computer parses the corresponding data frame and command frame according to the encoding rules. It adopts a data frame and command frame structure different from traditional communication frames, namely a long and short frame structure. This structure can transmit data in real time according to a certain order based on the encoding rules, and can also send and receive non-real-time command data. It is particularly suitable for real-time reporting communication needs with high sampling rate and small data volume.

Claims

1. A response communication method for real-time data upload via serial port, characterized in that... Includes the following steps: S1. The lower-level machine sends data frame groups to the upper-level machine in real time. The data frame group is composed of data frames. Each data frame is obtained by encoding each group of data after splitting the real-time data to be sent by the lower-level machine to the upper-level machine. The length of each data frame is 1 byte, where the first n+1 bits are the encoding reassembly flag bits and the last 7-n bits are the data bits, 0 < n < 7. S2. After receiving the data frame group sent by the lower computer, the host computer reassembles the data bits of each data frame into valid real-time data according to the encoding method represented by the encoding reassembly flag bit. S3. When the host computer receives a command message from the host computer, it parses the command message and encapsulates the information to be returned according to the parsing of the command message, forming a response command frame consisting of a frame header, data message, and frame trailer, and sends it to the host computer. During the transmission of the response command frame, the transmission of measurement data is stopped. The first n+1 bits of the frame header and frame trailer are encoding and reassembly flag bits, and the last 7-n bits are data bits, where 0 < n < 7. S4. After receiving the frame header of the response command frame from the slave device, the host computer continues to receive the data message and frame tail of the response command frame. At the same time, it determines whether the reception of the response command frame is complete by combining the length of the data message content and the frame tail data. If the command frame reception is complete, the host computer parses the command response frame according to the data message in the response command frame and performs corresponding processing.

2. The response communication method for real-time serial port data upload according to claim 1, characterized in that: n takes values ​​from 1 to 3.

3. The response communication method for real-time serial port data upload according to claim 1, characterized in that: In the response command frame of the lower-level machine, the data message consists of message length, frame type, message content, and checksum.