Universal serial port data transmission method and system
By using predefined protocol formats and two-step logic verification mechanisms in serial port communication, the problem of unstable data transmission in serial port transparent data communication is solved, communication efficiency and reliability are improved, and the data retransmission process is optimized.
Patent Information
- Application Number
- CN202410925257.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-10-25
AI Technical Summary
In serial port transparent data communication, due to factors such as device distance, environmental interference, and signal strength, data transmission is unstable and unreliable, especially when the amount of data is large, data loss or transmission errors are prone to occur.
Using the predefined serial port transmission protocol format, the receiving end receives the data frame word by word and performs two-step logical verification. The sending end performs data retransmission management based on the received confirmation or negative function word to ensure the integrity and stability of the data frame. .
It improves the efficiency and reliability of serial communication, avoids the problems of data frame sticking and response after completion of reception, improves the efficiency of data retransmission, and enhances the stability of data transmission.
Smart Images

Figure CN118842850A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer serial port communication, and in particular to a universal serial port data transmission method and system. Background Art
[0002] In serial port transparent data communication, upstream devices such as Bluetooth, infrared, etc. are easily affected by factors such as the user's device distance, environmental interference, signal strength, etc., which may cause errors or transmission failures in the data transmitted through the serial port. Especially when the amount of data transmitted is large, it is more likely to cause data loss, transmission errors, etc., which seriously affects the stability and reliability of serial port communication. Summary of the invention
[0003] The main purpose of the present invention is to provide a universal serial port data transmission method, which aims to solve the technical problem that in serial port transparent data communication, upstream data is transmitted through unreliable media and stable and reliable transmission cannot be guaranteed at the serial port layer.
[0004] To achieve the above object, in a first aspect, the present invention provides a universal serial port data transmission method, which is applied to a receiving end, and the universal serial port data transmission method comprises:
[0005] Configure predefined serial port transmission protocol format;
[0006] Receive the data frame sent by the transmitting end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continue to receive the subsequent bytes of data of the data frame according to the serial port transmission protocol format;
[0007] Perform a two-step logic check on the received data frame, and send an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result, informing the sending end to perform a corresponding action according to the information frame.
[0008] In a second aspect, the present invention further provides a universal serial port data transmission method, which is applied to a sending end, and the universal serial port data transmission method comprises:
[0009] Configure predefined serial port transmission protocol format;
[0010] When sending data for the first time, send a reset function word and start the retransmission timer;
[0011] According to the serial port transmission protocol format, the data frame to be transmitted is sent to the receiving end;
[0012] Receive the information frame responded by the receiving end after performing two-step logic check on the data frame, delete the data frame from the retransmission timer when it is determined that the information frame contains a confirmation function word, and retransmit the data when it is determined that the information frame contains a negative function word.
[0013] In a third aspect, the present invention further provides a universal serial port data transmission method, which is applied to a universal serial port data transmission system, wherein the universal serial port data transmission system includes a transmitting end and a receiving end, and the universal serial port data transmission method includes:
[0014] The sending end and the receiving end are respectively configured with a predefined serial port transmission protocol format;
[0015] When the transmitting end sends data for the first time, it sends a reset function word and starts a retransmission timer;
[0016] The transmitting end sends the data frame to be transmitted to the receiving end according to the serial port transmission protocol format;
[0017] The receiving end receives the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continues to receive subsequent bytes of data of the data frame according to the serial port transmission protocol format;
[0018] The receiving end performs a two-step logic check on the received data frame, and sends an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result;
[0019] The transmitting end deletes the data frame from the retransmission timer when receiving an information frame containing a confirmed function word, and retransmits the data frame when receiving an information frame containing a negative function word.
[0020] In a fourth aspect, the present invention further provides a universal serial port data transmission system, comprising a transmitting end and a receiving end;
[0021] The transmitting end is used to configure a predefined serial port transmission protocol format; when sending data for the first time, send a reset function word and start a retransmission timer; send a data frame to be transmitted to the receiving end according to the serial port transmission protocol format; receive an information frame responded by the receiving end after performing a two-step logic check on the data frame, and when it is determined that the information frame contains a confirmation function word, delete the data frame from the retransmission timer, and when it is determined that the information frame contains a negative function word, retransmit the data frame;
[0022] The receiving end is used to configure a predefined serial port transmission protocol format; receive the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continue to receive subsequent byte data of the data frame according to the serial port transmission protocol format; perform a two-step logic check on the received data frame, and send an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result.
[0023] The present invention provides a universal serial port data transmission method and system, wherein the receiving end receives the data frame sent by the sending end word by word, and when it is determined that the first N bytes of the data frame match the frame header, the receiving end continues to receive the subsequent bytes of the data frame according to the pre-configured serial port transmission protocol format, and performs a two-step logic check, and sends the information frame containing the confirmation function word or the negation function word to the sending end according to the logic check result, and the sending end performs a corresponding action according to the information frame containing the confirmation function word or the negation function word. The present invention performs frame header matching judgment on the data frame transmitted by the sending end at the receiving end, which can avoid the problem of data frame sticking. Secondly, the information frame is responded to the sending end through the two-step logic check method, while realizing the correct integrity check of the data frame, it avoids the problem of responding only after the data frame is received, thereby improving the efficiency and reliability of serial port communication; in addition, the present invention performs data retransmission at the sending end according to the information frame containing the negation function word, effectively improving the data retransmission efficiency, and further improving the reliability and stability of data transmission. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 A schematic diagram of a flow chart of a universal serial port data transmission method provided by a first embodiment of the present invention;
[0025] Figure 2 for Figure 1 A detailed flow chart of step S40 of the universal serial port data transmission method;
[0026] Figure 3 A schematic diagram of a flow chart of a universal serial port data transmission method provided in a second embodiment of the present invention;
[0027] Figure 4 for Figure 3 A detailed flow chart of step S20 and step S30 of the universal serial port data transmission method;
[0028] Figure 5 A schematic diagram of a flow chart of a universal serial port data transmission method provided in a third embodiment of the present invention;
[0029] Figure 6 A schematic structural diagram of a universal serial port data transmission system provided in a fourth embodiment of the present invention.
[0030] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0032] Embodiment 1
[0033] Reference Figure 1 The first embodiment of the present invention provides a universal serial port data transmission method, which is applied to a receiving end, and the receiving end can be a server or a terminal device, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services; the terminal device can be a smart phone, a tablet computer, a desktop computer, etc. The universal serial port data transmission method specifically includes the following steps:
[0034] Step S11, configuring a predefined serial port transmission protocol format.
[0035] In this embodiment, the serial port transmission protocol format is divided into a header part and a data packet part, the header part contains information of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part contains information of a data packet and a frame check code.
[0036] Preferably, the frame header uses any defined byte; the function word is divided into three types: confirmation function word, negation function word and reset function word; the sequence number is used to mark the data frame; the header check code is a two-byte header cyclic redundancy check code, which is used to check whether the header part is correct; the length of the data packet is a positive integer represented by the data length field; the frame check code is used to perform a cyclic redundancy check on the entire data frame.
[0037] Step S12, receiving the data frame sent by the transmitting end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continuing to receive subsequent bytes of data of the data frame according to the serial port transmission protocol format.
[0038] In this embodiment, the receiving end receives bytes of the data frame one by one. If the first N (N is a positive integer) bytes of data received match the frame header, the receiving end continues to receive subsequent byte data. If the first N bytes of data received do not match the frame header, the first N bytes of data are received again.
[0039] As a preference, when the serial port transmission protocol format consists of a frame header, a function word, a sequence number, a data length, a header check code, a data packet and a frame check code, reference Figure 2 , the step S12 specifically includes the following steps:
[0040] Step S121, receiving the first N bytes of data of the data frame, where N is one or two;
[0041] Step S122, detecting whether the first N bytes of data are a frame header;
[0042] Step S123: If yes, continue to receive the function word, sequence number, data length and header check code.
[0043] In this embodiment, the frame header of the serial port transmission protocol format is preferably represented by a byte 0XAA. For the receiving end, if the first byte data received is 0XAA, the function word, sequence number, data length and header check code are continuously received until all the header parts are received. If the first byte data received is not 0XAA, it is determined that the data received at this time is dirty data and needs to be discarded and re-read.
[0044] It can be understood that this embodiment can effectively prevent dirty data by reading the first N bytes of the data frame and performing frame header matching.
[0045] Step S13, performing a two-step logic check on the received data frame, and sending an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result, informing the sending end to perform a corresponding action according to the information frame.
[0046] In this embodiment, the two-step logic check is to first perform a header check, and after determining that the header part of the data frame is correct through the header check, perform a CRC check of the entire data frame. Accordingly, the logic check result includes a first step check result and a second step check result, wherein the first step check result indicates whether the header content is correct or incorrect, and the second step check result indicates whether the CRC check result matches or does not match the frame check code.
[0047] As a preference, refer to Figure 2 In step S13, performing a two-step logic check on the received data frame, and sending an information frame containing a confirmation function word or a negative function word to the sending end according to the logic check result specifically comprises the following steps:
[0048] Step S131, after receiving all the header parts, judging whether the header parts are correct according to the header check code;
[0049] Step S132, if the header part is correct, continue to receive the data packet part; if an error occurs in the header part, send the information frame containing the negative function word to the sending end;
[0050] Step S133, after receiving all the data parts, performing CRC check on all the byte data before the frame check code, and determining whether the CRC check result matches the frame check code;
[0051] Step S134: if the CRC check result matches the frame check code, the information frame containing the confirmed function word is sent to the sending end; otherwise, the information frame containing the denied function word is sent to the sending end.
[0052] In this embodiment, after the receiving end reads all the header parts, the first cyclic redundancy check code is calculated according to the frame header, function word, sequence number, and data length. Whether the header part is correct is determined by detecting whether the calculated first cyclic redundancy check code matches the read header check. If the calculated first cyclic redundancy check code matches the read header check, it is determined that the header part is correct, and the data packet part is continued to be received according to the serial port transmission protocol format, that is, all data packets are read according to the data length field in the header part, and then the two-byte frame check code is read. If the calculated first cyclic redundancy check code does not match the read header check, an information frame containing a negative function word is responded according to the serial port transmission protocol format to notify the sending end that an error has occurred in the data frame currently being transmitted.
[0053] After receiving all the data packet parts, a CRC check is performed on the data from the frame header to the last byte of the data packet. At this time, the second cyclic redundancy check code is calculated based on the frame header, function word, sequence number, data length, header check code and data packet received before the frame check code. The calculated result is used as the CRC check result, and it is determined whether the CRC check result matches the frame check code. If the CRC check result matches the frame check code, it is determined that the currently transmitted data frame is accurate and complete, and in accordance with the serial port transmission protocol format, an information frame containing a confirmation function word is responded to to notify the sending end that the currently transmitted data frame has been successfully and correctly received; if the CRC check result does not match the frame check code, it is determined that the currently transmitted data frame is erroneous and incomplete, and in accordance with the serial port transmission protocol format, an information frame containing a negative function word is responded to to notify the sending end that the currently transmitted data frame is erroneous and needs to be resent.
[0054] Furthermore, after receiving all the header parts, the receiving end can detect whether the time for receiving the header part has timed out. If so, it will discard it and continue to re-read the data. If not, it will perform a header check. Similarly, after receiving all the data packet parts, the receiving end can detect whether the time for receiving the data packet part has timed out. If so, it will respond with an information frame containing a negative function word in the serial port transmission protocol format. If not, it will perform a CRC check on the entire data frame.
[0055] It can be understood that the universal serial port data transmission method of this embodiment uses a two-step logic check at the receiving end, first performing a header check, and after determining through the header check that the header part before the data packet is correct, a cyclic redundancy check of the entire data frame is performed, so that when an error occurs in the header part, a quick response is given to the sending end without waiting for the complete data frame to be received before responding, thereby improving communication efficiency. Secondly, by using an information frame containing a negative function word, the sending end can quickly perceive that the transmitted data frame is erroneous, without having to wait until a timeout to retransmit the data, thereby improving the reliability and stability of data transmission.
[0056] In other embodiments, when the receiving end performs a two-step logic check on the data frame, an information frame including a function word and a sequence number may be sent to the sending end according to the result of the logic check. More specifically, after receiving all the header parts, determine whether the header part is correct based on the header check code. If the header part is correct, continue to receive the data packet part, otherwise send an information frame with a function word of a negative function word and a sequence number of the data frame received by the receiving end to notify the sending end that an error has occurred in the data frame currently being transmitted; further, after receiving all the data parts, perform a CRC check on all byte data before the frame check code. If the CRC check result matches the frame check code, it is determined that the data frame currently being transmitted is accurate and complete, and in accordance with the serial port transmission protocol format, send an information frame with a function word of a confirmation function word and a sequence number of the data frame received by the receiving end to notify the sending end that the data frame currently being transmitted has been successfully and correctly received; if the CRC check result does not match the frame check code, it is determined that the data frame currently being transmitted is erroneous and incomplete, and in accordance with the serial port transmission protocol format, send an information frame with a function word of a negative function word and a sequence number of the data frame received by the receiving end to notify the sending end that the data frame currently being transmitted is erroneous. It is understandable that the receiving end of this embodiment responds to the function word to the sending end while responding to the received data frame sequence number, which can avoid the problem of repeated transmission of data frames.
[0057] In summary, in the universal serial port data transmission method of this embodiment, the receiving end receives the data frame word by word, and when it is determined that the first N bytes of the data frame are the frame header, it continues to transmit and receive the subsequent byte data according to the predefined serial port transmission protocol format, and performs a two-step logic check, and responds to an information frame containing a confirmation function word or a negative function word according to the logic check result, so as to notify the sending end to perform a corresponding action according to the information frame. The present invention performs frame header matching judgment on the data frame transmitted by the sending end at the receiving end, which can avoid the problem of data frame sticking. Secondly, the information frame is responded to the sending end through the two-step logic check method, while realizing the correct integrity check of the data frame, it avoids the problem of responding only after the data frame is received, thereby improving the efficiency and reliability of serial port transparent data communication.
[0058] Embodiment 2
[0059] Reference Figure 3 The first embodiment of the present invention provides a universal serial port data transmission method, which is applied to a sending end; the sending end can be a server or a terminal device, wherein the server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services; the terminal device can be a smart phone, a tablet computer, a desktop computer, etc. The universal serial port data transmission method specifically includes the following steps:
[0060] Step S21, configuring a predefined serial port transmission protocol format.
[0061] In this embodiment, the serial port transmission protocol format is divided into a header part and a data packet part, the header part contains information of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part contains information of a data packet and a frame check code.
[0062] Preferably, the frame header uses any defined byte; the function word is divided into three types: confirmation function word, negation function word and reset function word; the sequence number is used to mark the data frame to be transmitted; the header check code is the header cyclic redundancy check code, which is used to check whether the header part is correct; the length of the data packet is a positive integer represented by the data length field; the frame check code is used to perform a cyclic redundancy check on the entire data frame.
[0063] For the data length field, it can be reasonably configured according to the specific usage scenario. For scenarios such as control with small amounts of data, the number of bytes in the data length can be defined less, which can save transmission costs and reduce transmission delays.
[0064] Step S22: When sending data for the first time, a reset function word is sent and a retransmission timer is started.
[0065] In this embodiment, after the sending end and the receiving end establish a communication connection, the first data frame sent will send a reset function word, which can avoid the problem of inconsistency between the data frame receiving sequence number maintained by the receiving end and the data frame sending sequence number maintained by the sending end after the sending end is disconnected from the receiving end due to special circumstances. After the reset, the data frame sending sequence number of the sending end is set to 0, and the data frame receiving sequence number of the receiving end is set to 1.
[0066] After the reset function word is sent, the retransmission timer is started. After each subsequent data frame is sent by the sender, the data frame will be passed to the retransmission timer. When the retransmission timer is started, if it is found that the response of a data frame DATA(i) has timed out, the data frame DATA(i) will be retransmitted.
[0067] If the subsequent sending end determines that the number of retransmissions of a data frame DATA(i) exceeds (that is, is greater than or equal to) the preset retransmission threshold, it determines that the data frame DATA(i) cannot be effectively transmitted. At this time, the sending end generates an error message and sends the transmission error message to the application layer. The application layer can consider restarting the system or reconnecting to the receiving end according to the actual situation.
[0068] Step S23, sending the data frame to be transmitted to the receiving end according to the serial port transmission protocol format.
[0069] In this embodiment, the transmitting end assembles the data frames to be transmitted according to the structure of the serial port transmission protocol format, and sends the data frames to the receiving end. The number of the data frames to be transmitted is set according to the demand.
[0070] Step S24, receiving the information frame responded by the receiving end after performing two-step logic check on the data frame, and when it is determined that the information frame contains a confirmation function word, deleting the data frame from the retransmission timer; when it is determined that the information frame contains a negative function word, retransmitting the data frame.
[0071] In this embodiment, the two-step logic check is to first perform a header check, and after determining that the header part of the data frame is correct through the header check, then perform a CRC check on the entire data frame.
[0072] Preferably, when the serial port transmission protocol format consists of a frame header, a function word, a sequence number, a data length, a header check code, a data packet and a frame check code, the receiving end performs a two-step logic check on the data frame, specifically comprising the following steps:
[0073] Step 1: After receiving all the header parts, the receiving end determines whether the header part is correct based on the header check code. If an error occurs in the header part, an information frame containing a negative function word is returned according to the serial port transmission protocol format, otherwise, the receiving end continues to receive the data packet part.
[0074] More specifically, after the receiving end reads all the header parts, it calculates the first cyclic redundancy check code according to the frame header, function word, sequence number and data length, and determines whether the header part is correct by detecting whether the first cyclic redundancy check code matches the header check code. If the first cyclic redundancy check code matches the header check code, it is determined that the header part is correct. At this time, the subsequent byte data of the data frame can continue to be received. If the first cyclic redundancy check code does not match the header check code, it is determined that an error occurs in the header part. At this time, an information frame containing a negative function word is responded according to the serial port transmission protocol format.
[0075] Step 2, after receiving all the data packet parts, perform CRC check on the byte data received before the frame check code, and determine whether the CRC check result matches the frame check code. If the CRC check result matches the frame check code, return an information frame containing a confirmed function word according to the serial port transmission protocol format, otherwise return an information frame containing a negative function word.
[0076] More specifically, after the receiving end reads all the data packet parts, it calculates the second cyclic redundancy check code based on all the byte data in the data frame except the frame check code, and uses the calculated result as the CRC check result, and determines whether the CRC check result matches the frame check code. If the CRC check result matches the frame check code, it responds with an information frame containing a confirmed function word according to the serial port transmission protocol format, and if the CRC check result does not match the frame check code, it responds with an information frame containing a negative function word according to the serial port transmission protocol format.
[0077] It is understandable that the receiving end may respond to the sequence number of the data frame while responding to the negative function word to notify the sending end to retransmit the data frame with the corresponding sequence number.
[0078] In an alternative embodiment, based on Figure 3 The universal serial port data transmission method described herein refers to Figure 4 , the step S24 specifically includes the following steps:
[0079] S241, determining whether an information frame responded by the receiving end is received within a timeout threshold;
[0080] S242, when receiving the information frame responded by the receiving end within the timeout threshold, parsing the function word contained in the information frame, and determining whether the function word is a confirmation function word;
[0081] S243, if the function word is a confirmation function word, deleting the data frame from the retransmission timer, and continuing to send the next data frame;
[0082] S244: If the function word is a negative function word, the data frame is reset in the retransmission timer, and the data frame is retransmitted once.
[0083] In this embodiment, for the current data frame sent by the transmitting end to the receiving end, if the information frame in which the receiving end responds after performing a two-step logic check on the current data frame is obtained within the preset timeout threshold, and it is judged that the function word contained in the information frame is a confirmation function word, the current data frame is deleted from the retransmission timer, and the next data frame can be sent. If it is judged that the function word contained in the information frame is a negative function word, it is determined that the current data frame is damaged midway, and the current data frame is reset in the retransmission timer at this time, and the current data frame is retransmitted. If the information frame in which the receiving end responds after performing a two-step logic check on the current data frame is not obtained within the timeout threshold, the subsequent step S245 is entered to determine the number of retransmissions. Among them, the timeout threshold is set according to demand.
[0084] refer to Figure 4 Further, after step S241, step S24 further includes the following steps:
[0085] S245, when no information frame responded by the receiving end is received within the timeout threshold, the number of retransmissions of the data frame is increased by one;
[0086] S246, detecting whether the number of retransmissions of the data frame exceeds a retransmission number threshold;
[0087] S247, if the number of retransmissions of the data frame does not exceed the retransmission number threshold, continue to retransmit the data frame;
[0088] S248: If the number of retransmissions of the data frame exceeds a retransmission threshold, a transmission error message is generated.
[0089] In this embodiment, for the current data frame sent by the transmitting end to the receiving end, if the receiving end does not obtain the information frame responding to the current data frame after performing two-step logic verification on the current data frame within the timeout threshold, retransmission is performed, and the number of retransmissions of the current data frame is increased by 1. If the retransmission times out and the number of retransmissions of the current data frame exceeds the preset retransmission number threshold, transmission error information is generated to notify the application layer to process. The retransmission number threshold is greater than or equal to 3.
[0090] In summary, in the universal serial port data transmission method of this embodiment, when the transmitting end sends data for the first time, it sends a reset function word, and after starting the retransmission timer, sends the digital frame to be transmitted to the receiving end according to the predefined serial port transmission protocol format, and then obtains the information frame containing a negative function word or a confirmation function word in response to the receiving end after performing a two-step logical check on the data frame, and performs corresponding actions according to the received information frame containing a negative function word or a confirmation function word. This embodiment uses the reset function word to solve the problem that after the transmitting end is accidentally disconnected, the transmitting end can continue to communicate seamlessly with the transmitting end after re-enabling the transmitting end, thereby improving the reliability and stability of data transmission; in addition, at the transmitting end, the retransmission timer is used to timely retransmit data when the information frame is not received after the timeout, and when the information frame is received without timeout, the function word contained in the information frame is used to quickly perceive whether the transmitted data frame is erroneous or incomplete, thereby timely retransmitting data, improving the data frame error perception capability and data retransmission efficiency, and further improving the reliability and stability of data transmission.
[0091] Embodiment 3
[0092] Reference Figure 5 The third embodiment of the present invention provides a universal serial port data transmission method, which is applied to a universal serial port data transmission system. The universal serial port data transmission system includes a transmitting end and a receiving end. The universal serial port data transmission method includes:
[0093] Step S31: the sending end and the receiving end are respectively configured with a predefined serial port transmission protocol format.
[0094] In this embodiment, the serial port transmission protocol format is divided into a header part and a data packet part, the header part includes information of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part includes information of a data packet and a frame check code. As shown in Table 1, the serial port transmission protocol format uses 1 byte 0XAA as a frame header, 1 byte as a function word, 4 bytes representing the sequence number of the data frame, 2 bytes representing the data length, 2 bytes representing the header check code, the length of the data packet is set according to the positive integer represented by the data length field, and the last 2 bytes represent the frame check code.
[0095] Table 1 Structure table of serial port transmission protocol format
[0096]
[0097] It can be understood that in this embodiment, 2 bytes are used as the check code of the header. This can avoid the situation where subsequent data frames are stuck when there is a problem with the transmission of the data length field in the frame data. At the same time, it can provide feedback to the sender earlier that there is a problem with the data frame being transmitted and needs to be resent, rather than having to wait until a timeout before resending.
[0098] Furthermore, the receiving end can detect which data frames are sent repeatedly by comparing the sequence numbers of the received data frames, and can respond to the sending end with a sequence number for the repeated frames.
[0099] Step S32: When the transmitting end sends data for the first time, it sends a reset function word and starts a retransmission timer.
[0100] For the sending end, when sending data for the first time, it is necessary to maintain an increasing 4-byte integer as the sequence number of the data frame to be transmitted, and send a reset function word to notify the receiving segment that it should clear the buffer data again and prepare to receive data again.
[0101] After the reset function word is sent, the retransmission timer is started. After each subsequent data frame is sent by the sender, the data frame will be passed to the retransmission timer. When the retransmission timer is started, if it is found that the response of the data frame has timed out, the data frame will be retransmitted. If it is found that the number of retransmissions of the data frame exceeds the retransmission threshold, the transmission error information will be sent to the application layer.
[0102] Furthermore, for the sending end, when the sequence number reaches the maximum value of 4 bytes, the sequence number is reset to the initial value, which can avoid the problem of being unable to communicate normally with the receiving end after the sequence number exceeds the maximum value represented by the number of bytes.
[0103] Step S33: the transmitting end sends the data frame to be transmitted to the receiving end according to the serial port transmission protocol format.
[0104] For the sending end, according to the structure of the serial port transmission protocol format, the data frame to be transmitted is assembled and the data frame is sent to the receiving end.
[0105] Step S34, the receiving end receives the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continues to receive subsequent bytes of data of the data frame according to the serial port transmission protocol format.
[0106] For the receiving end, the bytes of the data frame are received one by one. If the first N bytes received match the frame header, the subsequent byte data will continue to be received. If the first N bytes received do not match the frame header, the data will be discarded and read again.
[0107] Preferably, the step S34 specifically includes the following steps:
[0108] Step S341, receiving the first N bytes of data of the data frame, where N is one or two;
[0109] Step S342, detecting whether the first N bytes of data are a frame header;
[0110] Step S343, if yes, continue to receive the function word, sequence number, data length and header check code.
[0111] It is understandable that the specific definitions of the above steps S341 to S343 in this embodiment can refer to the steps S121 to S123 of the first embodiment, and will not be repeated here.
[0112] Step S35, the receiving end performs a two-step logic check on the received data frame, and sends an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result.
[0113] In step S35, the two-step logic check is to first perform a header check, and after determining that the header part of the data frame is correct through the header check, then perform a CRC check on the entire data frame. Preferably, the step S35 specifically includes the following steps:
[0114] Step S351, after receiving all the header parts, judging whether the header parts are correct according to the header check code;
[0115] Step S352, if the header part is correct, continue to receive the data packet part; if an error occurs in the header part, send the information frame containing the negative function word to the sending end;
[0116] Step S353, after receiving all the data parts, performing CRC check on all the byte data before the frame check code, and determining whether the CRC check result matches the frame check code;
[0117] Step S354: if the CRC check result matches the frame check code, the information frame containing the confirmed function word is sent to the sending end; otherwise, the information frame containing the denied function word is sent to the sending end.
[0118] It is understandable that the specific definitions of the above steps S351 to S354 in this embodiment can refer to the steps S131 to S134 in the first embodiment, and will not be repeated here.
[0119] Step S36, when the transmitting end receives an information frame including a confirmation function word, the transmitting end deletes the data frame from the retransmission timer, and when the transmitting end receives an information frame including a negative function word, the transmitting end retransmits the data frame.
[0120] Preferably, the step S36 comprises the following steps:
[0121] Step S361, determining whether an information frame responded by the receiving end is received within a timeout threshold;
[0122] Step S362, when receiving the information frame responded by the receiving end within the timeout threshold, parsing the function word contained in the information frame, and determining whether the function word is a confirmation function word;
[0123] Step S363, if the function word is a confirmation function word, the data frame is deleted from the retransmission timer and the next data frame is sent; if the function word is a negative function word, the data frame is reset in the retransmission timer and the data frame is retransmitted once;
[0124] Step S364, when the information frame responded by the receiving end is not received within the timeout threshold, the number of retransmissions of the data frame is increased by one to detect whether the number of retransmissions of the data frame exceeds the retransmission number threshold;
[0125] Step S365: If the number of retransmissions of the data frame does not exceed the retransmission threshold, continue to retransmit the data frame; if the number of retransmissions of the data frame exceeds the retransmission threshold, generate transmission error information.
[0126] It is understandable that the specific definitions of the above steps S361 to S365 in this embodiment can refer to steps S241 to S248 of the second embodiment, and will not be repeated here.
[0127] In summary, in the universal serial port data transmission method of this embodiment, the receiving end receives the data frame sent by the sending end word by word, and when it is determined that the first N bytes of the data frame match the frame header, the receiving end continues to receive the subsequent bytes of the data frame according to the pre-configured serial port transmission protocol format, and performs a two-step logic check, and sends the information frame containing the confirmation function word or the negation function word to the sending end according to the result of the logic check, and the sending end performs a corresponding action according to the information frame containing the confirmation function word or the negation function word. In this embodiment, the receiving end performs a frame header matching judgment on the data frame transmitted by the sending end, which can avoid the problem of data frame sticking. Secondly, the information frame is responded to the sending end through the two-step logic check method. While realizing the correct integrity check of the data frame, it avoids the problem of responding only after the data frame is received, thereby improving the efficiency and reliability of serial port communication. In addition, in this embodiment, at the sending end, data retransmission is performed according to the information frame containing the negation function word, which effectively improves the data retransmission efficiency and further improves the reliability and stability of data transmission.
[0128] Embodiment 4
[0129] Reference Figure 6 , a fourth embodiment of the present invention provides a universal serial port data transmission system, including a transmitting end and a receiving end;
[0130] The transmitting end is used to configure a predefined serial port transmission protocol format; when sending data for the first time, send a reset function word and start a retransmission timer; send a data frame to be transmitted to the receiving end according to the serial port transmission protocol format; receive an information frame responded by the receiving end after performing a two-step logic check on the data frame, and when it is determined that the information frame contains a confirmation function word, delete the data frame from the retransmission timer, and when it is determined that the information frame contains a negative function word, retransmit the data frame;
[0131] The receiving end is used to configure a predefined serial port transmission protocol format; receive the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continue to receive subsequent byte data of the data frame according to the serial port transmission protocol format; perform a two-step logic check on the received data frame, and send an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result.
[0132] Furthermore, the universal serial port data transmission system also includes a server, which is used to define the serial port transmission protocol format, and the serial port transmission protocol format includes a header part and a data packet part, the header part consists of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part consists of a data packet and a frame check code.
[0133] It is understandable that the server in this embodiment is a third-party server, and both the sending end and the receiving end can obtain the serial port transmission protocol format from the server for automatic configuration.
[0134] Furthermore, the sending end is also used to determine whether the information frame responded by the receiving end is received within the timeout threshold; when the information frame responded by the receiving end is received within the timeout threshold, the function word contained in the information frame is parsed, and it is determined whether the function word is a confirmation function word; if the function word is a confirmation function word, the data frame is deleted from the retransmission timer and the next data frame is sent; if the function word is a negative function word, the data frame is reset in the retransmission timer and the data frame is retransmitted once.
[0135] Furthermore, the sending end is also used to increase the number of retransmissions of the data frame by one when the information frame responded by the receiving end is not received within the timeout threshold; detect whether the number of retransmissions of the data frame exceeds the retransmission threshold; if the number of retransmissions of the data frame does not exceed the retransmission threshold, continue to retransmit the data frame; if the number of retransmissions of the data frame exceeds the retransmission threshold, generate transmission error information.
[0136] Furthermore, the receiving end is also used to receive the first N bytes of data of the data frame; detect whether the first N bytes of data are frame headers, where N is one or two; if so, continue to receive function words, sequence numbers, data lengths and header check codes.
[0137] Furthermore, the receiving end is also used to determine whether the header part is correct according to the header check code after receiving all the header parts; if the header part is correct, continue to receive the data packet part; if an error occurs in the header part, send the information frame containing the negative function word to the sending end; after receiving all the data parts, perform CRC check on all byte data before the frame check code, and determine whether the CRC check result matches the frame check code; if the CRC check result matches the frame check code, send the information frame containing the confirmed function word to the sending end, otherwise send the information frame containing the negative function word to the sending end.
[0138] It is understandable that the specific embodiments of the universal serial port data transmission system of the present invention can refer to the specific embodiments of the universal serial port data transmission method, which will not be described in detail herein.
[0139] The above-mentioned universal serial port data transmission system is used to implement the universal serial port data transmission method of any of the above-mentioned embodiments, and has corresponding beneficial effects.
[0140] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method or system including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method or system. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method or system including the element.
[0141] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0142] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A universal serial port data transmission method, characterized in that: Applied to the receiving end, the universal serial port data transmission method includes: Configure predefined serial port transmission protocol format; Receive the data frame sent by the transmitting end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continue to receive the subsequent bytes of data of the data frame according to the serial port transmission protocol format; Perform a two-step logic check on the received data frame, and send an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result, informing the sending end to perform a corresponding action according to the information frame.
2. The universal serial port data transmission method according to claim 1, characterized in that: The serial port transmission protocol format is divided into a header part and a data packet part, the header part includes information of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part includes information of a data packet and a frame check code; the data frame sent by the transmitting end is received word by word, and when it is determined that the first N bytes of the data frame match the frame header, the subsequent bytes of the data frame are continuously received according to the serial port transmission protocol format, including: Receive the first N bytes of data of the data frame, where N is one or two; Detect whether the first N bytes of data are a frame header; If yes, continue to receive the function word, sequence number, data length and header check code.
3. The universal serial port data transmission method as claimed in claim 2, characterized in that: The step of performing a two-step logic check on the received data frame and sending an information frame including a confirmation function word or a negation function word to the transmitting end according to the logic check result includes: After receiving all the header parts, judging whether the header parts are correct according to the header check code; If the header part is correct, continue to receive the data packet part; if an error occurs in the header part, send the information frame containing the negative function word to the sending end; After receiving all the data parts, performing CRC check on all the byte data before the frame check code, and determining whether the CRC check result matches the frame check code; If the CRC check result matches the frame check code, the information frame containing the confirmation function word is sent to the sending end, otherwise the information frame containing the negative function word is sent to the sending end.
4. A universal serial port data transmission method, characterized in that: Applied to the sending end, the universal serial port data transmission method includes: Configure predefined serial port transmission protocol format; When sending data for the first time, send a reset function word and start the retransmission timer; According to the serial port transmission protocol format, the data frame to be transmitted is sent to the receiving end; Receive the information frame that the receiving end responds to after performing two-step logic verification on the data frame, and when it is determined that the information frame contains a confirmation function word, delete the data frame from the retransmission timer; when it is determined that the information frame contains a negative function word, retransmit the data frame.
5. The universal serial port data transmission method as claimed in claim 4, characterized in that: The serial port transmission protocol format is divided into a header part and a data packet part, the header part contains information of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part contains information of a data packet and a frame check code; The receiving end performs a two-step logic check on the data frame, including: After receiving all the header parts, the receiving end determines whether the header part is correct according to the header check code. If an error occurs in the header part, an information frame containing a negative function word is returned according to the serial port transmission protocol format, otherwise, the receiving end continues to receive the data packet part; After receiving all the data packet parts, a CRC check is performed on the byte data received before the frame check code, and it is determined whether the CRC check result matches the frame check code. If the CRC check result matches the frame check code, an information frame containing a confirmed function word is returned according to the serial port transmission protocol format, otherwise an information frame containing a negative function word is returned.
6. The universal serial port data transmission method as claimed in claim 5, characterized in that: The receiving end responds to the information frame after performing two-step logic check on the data frame, and when it is determined that the information frame includes a confirmation function word, the data frame is deleted from the retransmission timer, and when it is determined that the information frame includes a negative function word, the data frame is retransmitted, including: Determining whether an information frame responded by the receiving end is received within a timeout threshold; When receiving an information frame responded by the receiving end within a timeout threshold, parsing the function word contained in the information frame, and determining whether the function word is a confirmation function word; If the function word is a confirmation function word, deleting the data frame from the retransmission timer and continuing to send the next data frame; If the function word is a negative function word, the data frame is reset in the retransmission timer and the data frame is retransmitted once.
7. The universal serial port data transmission method according to claim 6, characterized in that: After determining whether the information frame responded by the receiving end is received within the timeout threshold, the method further includes: When the information frame responded by the receiving end is not received within the timeout threshold, the number of retransmissions of the data frame is increased by one; Detecting whether the number of retransmissions of the data frame exceeds a retransmission number threshold; If the number of retransmissions of the data frame does not exceed the retransmission number threshold, continue to retransmit the data frame; If the number of retransmissions of the data frame exceeds a retransmission threshold, transmission error information is generated.
8. A universal serial port data transmission method, characterized in that: Applied to a universal serial port data transmission system, the universal serial port data transmission system includes a transmitting end and a receiving end, and the universal serial port data transmission method includes: The sending end and the receiving end are respectively configured with a predefined serial port transmission protocol format; When the transmitting end sends data for the first time, it sends a reset function word and starts a retransmission timer; The transmitting end sends the data frame to be transmitted to the receiving end according to the serial port transmission protocol format; The receiving end receives the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continues to receive subsequent bytes of data of the data frame according to the serial port transmission protocol format; The receiving end performs a two-step logic check on the received data frame, and sends an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result; The transmitting end deletes the data frame from the retransmission timer when receiving an information frame containing a confirmed function word, and retransmits the data frame when receiving an information frame containing a negative function word.
9. A universal serial port data transmission system, characterized in that: The universal serial port data transmission system comprises a transmitting end and a receiving end; The transmitting end is used to configure a predefined serial port transmission protocol format; when sending data for the first time, send a reset function word and start a retransmission timer; send a data frame to be transmitted to the receiving end according to the serial port transmission protocol format; receive an information frame responded by the receiving end after performing a two-step logic check on the data frame, and when it is determined that the information frame contains a confirmation function word, delete the data frame from the retransmission timer, and when it is determined that the information frame contains a negative function word, retransmit the data frame; The receiving end is used to configure a predefined serial port transmission protocol format; receive the data frame sent by the sending end word by word, and when it is determined that the first N bytes of data of the data frame match the frame header, continue to receive subsequent byte data of the data frame according to the serial port transmission protocol format; perform a two-step logic check on the received data frame, and send an information frame containing a confirmation function word or a negation function word to the sending end according to the logic check result.
10. The universal serial port data transmission system as claimed in claim 9, characterized in that: The serial port transmission protocol format includes a header part and a data packet part, wherein the header part is composed of a frame header, a function word, a sequence number, a data length and a header check code, and the data packet part is composed of a data packet and a frame check code.
Citation Information
Cited By
Communication system of electric bicycle multi-substation wireless charging system
CN119449502A
Multi-serial interface reliable data transmission system based on USB bus
CN121009043A
