CN111711609A - Protocol design method in serial port communication - Google Patents

Protocol design method in serial port communication Download PDF

Info

Publication number
CN111711609A
CN111711609A CN202010435541.2A CN202010435541A CN111711609A CN 111711609 A CN111711609 A CN 111711609A CN 202010435541 A CN202010435541 A CN 202010435541A CN 111711609 A CN111711609 A CN 111711609A
Authority
CN
China
Prior art keywords
data
frame
bytes
predefined
check
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010435541.2A
Other languages
Chinese (zh)
Inventor
王玉军
雍盛贵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Chuanyi Automation Co Ltd
Original Assignee
Chongqing Chuanyi Automation Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Chuanyi Automation Co Ltd filed Critical Chongqing Chuanyi Automation Co Ltd
Priority to CN202010435541.2A priority Critical patent/CN111711609A/en
Publication of CN111711609A publication Critical patent/CN111711609A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/03Protocol definition or specification 
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L1/00Arrangements for detecting or preventing errors in the information received
    • H04L1/12Arrangements for detecting or preventing errors in the information received by using return channel
    • H04L1/16Arrangements for detecting or preventing errors in the information received by using return channel in which the return channel carries supervisory signals, e.g. repetition request signals
    • H04L1/18Automatic repetition systems, e.g. Van Duuren systems
    • H04L1/1867Arrangements specially adapted for the transmitter end
    • H04L1/188Time-out mechanisms
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/06Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Communication Control (AREA)

Abstract

The invention provides a protocol design method in serial communication, which comprises the following steps: predefining a data frame structure, wherein the format of a frame head and a frame tail in the data frame structure is double bytes; at a data sending end, packaging data according to a predefined data frame structure, and sending the data; at a data receiving end, collecting data, judging each byte one by one, judging the received data as a frame header when two continuous bytes in the received data are matched with a predefined frame header, continuously receiving a subsequent data frame, judging whether the received data frame is the same as a predefined frame tail or not according to the last two bytes of the received data frame, and if the received data frame is the same as the predefined frame tail, confirming that the data frame is completely and correctly transmitted; the invention does not need to translate the bytes of the data packet, simplifies the translation link before data transmission and improves the efficiency of a receiver.

Description

Protocol design method in serial port communication
Technical Field
The invention relates to the field of communication, in particular to a protocol design method in serial communication.
Background
The serial communication technology is a communication method in which both communication parties perform bit-by-bit and follow a time sequence. The serial communication interface is used as the main interface between computer and single chip, and is widely used in various instruments and meters, industrial monitoring and automatic control fields. The communication protocol is an agreement which needs to be reached by two communication parties, and specifies the data format, error checking mode, control character definition and the like which must be complied with by the two communication parties. In instrument and meter products, a strict, reasonable and standard serial communication protocol needs to be designed to ensure the reliability of data transmission.
At present, in order to ensure the correctness of data transmission, the existing solution generally adopts a translation processing mode before data transmission, and the same bytes as the frame head and the frame tail are translated and then transmitted, but this mode can change the length of the whole data packet, and increases the analysis difficulty and the processing speed of the receiving party.
Disclosure of Invention
In view of the above drawbacks of the prior art, the present invention provides a protocol design method in serial communication to solve the above technical problems.
The protocol design method in serial communication provided by the invention comprises the following steps:
predefining a data frame structure, wherein the format of a frame head and a frame tail in the data frame structure is double bytes;
at a data sending end, packaging data according to a predefined data frame structure, and sending the data;
and at a data receiving end, acquiring data, judging each byte one by one, judging the received data as a frame header when two continuous bytes in the received data are matched with a predefined frame header, continuously receiving a subsequent data frame, judging whether the received data frame is the same as the predefined frame tail or not according to the last two bytes of the received data frame, and if the received data frame is the same as the predefined frame tail, confirming that the data frame is completely and correctly transmitted.
Optionally, a check frame is set in the data frame structure, and is used for performing data check on the received data.
Optionally, the check frame is disposed after the data packet and before the end of the frame.
Optionally, the data frame structure includes a frame header, a data length, a command code, a data packet, a check frame, and a frame tail, which are sequentially set.
Optionally, the data length is 1byte, the command code is 1byte, and the check frame is 2 bytes.
Optionally, after receiving the data, the data receiving end feeds back confirmation information to the data sending end, and if the data sending end does not receive the confirmation information fed back by the data receiving end within the preset time threshold range, the data receiving end resends the data.
Optionally, a time threshold for retransmitting data overtime is preset, and when the time of retransmitting data without being fed back by the data transmitting end reaches the time threshold, the system is restarted.
Optionally, the frame header is two bytes different from each other.
Optionally, the frame end is two bytes different from the frame head and different from each other.
Optionally, CRC data check is performed on the received data through the check frame.
The invention has the beneficial effects that: according to the protocol design method in serial communication, the 2Byte bytes are used as the frame head and frame tail, double bytes repeated with the frame head and frame tail in the data packet can be avoided, the bytes of the data packet do not need to be translated, the translation link before data sending is simplified, and the efficiency of a receiving party is improved.
On the other hand, the invention uses the retransmission mechanism to receive the other side confirmation information aiming at the data packet in the specified time after the data sender sends the data packet, thereby improving the protocol availability.
Drawings
Fig. 1 is a schematic flow chart of a protocol design method in serial communication according to an embodiment of the present invention.
Fig. 2 is a schematic flow chart of a fault tolerance mechanism of a protocol design method in serial communication according to an embodiment of the present invention.
Detailed Description
The embodiments of the present invention are described below with reference to specific embodiments, and other advantages and effects of the present invention will be easily understood by those skilled in the art from the disclosure of the present specification. The invention is capable of other and different embodiments and of being practiced or of being carried out in various ways, and its several details are capable of modification in various respects, all without departing from the spirit and scope of the present invention. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present invention, and the components related to the present invention are only shown in the drawings rather than drawn according to the number, shape and size of the components in actual implementation, and the type, quantity and proportion of the components in actual implementation may be changed freely, and the layout of the components may be more complicated.
In the following description, numerous details are set forth to provide a more thorough explanation of embodiments of the present invention, however, it will be apparent to one skilled in the art that embodiments of the present invention may be practiced without these specific details, and in other embodiments, well-known structures and devices are shown in block diagram form, rather than in detail, in order to avoid obscuring embodiments of the present invention.
As shown in fig. 1, the protocol design method in serial port communication in this embodiment includes:
predefining a data frame structure, wherein the format of a frame head and a frame tail in the data frame structure is double bytes;
at a data sending end, packaging data according to a predefined data frame structure, and sending the data;
and at a data receiving end, acquiring data, judging each byte one by one, judging the received data as a frame header when two continuous bytes in the received data are matched with a predefined frame header, continuously receiving a subsequent data frame, judging whether the received data frame is the same as the predefined frame tail or not according to the last two bytes of the received data frame, and if the received data frame is the same as the predefined frame tail, confirming that the data frame is completely and correctly transmitted.
As shown in fig. 1, in this embodiment, the protocol format uses double bytes as the frame header and the frame trailer of the protocol, the data length is 1byte, the command code is 1byte, and the data packet verifies 2byte according to the actual transmission length. For example, a double byte (0xFA, 0xF5) is used as a frame header, and a double byte (0xFB,0xF6) is used as a frame trailer, the data frame structure in this embodiment includes a frame header, a data length, a command code, a packet, a check frame, and a frame trailer, which are sequentially arranged, and the data frame structure is shown in table 1.
Figure BDA0002502097190000031
TABLE 1
In this embodiment, the 2Byte bytes are used as the header and trailer, so that double bytes repeated with the header and trailer in the data packet can be avoided, the bytes of the data packet do not need to be translated, the translation link before data transmission is simplified, and the efficiency of the data receiving end is improved.
In this embodiment, a check frame is set in the data frame structure for performing data check on the received data. After receiving the first byte as 0xFA, the data receiving end continuously determines that the second byte is 0xF5, and then it is considered as the frame header, and receives the third byte as the data length (in this embodiment, the data length is 12 bytes), and receives the fourth byte, and then receives the fourth byte to the 16 th byte according to the data length of the third byte, and then receives the 17 th and 18 th bytes as CRC check, and if it is correct, then receives the last two bytes, i.e., 19 and 20, and verifies whether it is 0xFB,0xF6, if it is the frame end, then it is considered that the frame is complete, then it is checked whether CRC is correct, if it is correct, then it is considered that the data frame is complete and transmission is correct.
As shown in fig. 2, in this embodiment, after receiving data, the data receiving end feeds back acknowledgment information to the data sending end, and if the data sending end does not receive the acknowledgment information fed back by the data receiving end within a preset time threshold range, the data sending end retransmits the data. And presetting a time-out retransmission data time threshold, and restarting the system when the time of retransmitting the data is not fed back by the data transmitting end in time-out reaches the time threshold. By the fault-tolerant mechanism, the phenomena of communication interference and data error can be avoided in the serial port communication process, and the phenomenon that a receiving party cannot correctly acquire and analyze data sent by a data sending party, so that communication abnormity can be caused and the protocol availability is influenced is avoided.
In the above-described embodiments, references in the specification to "the present embodiment" or "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least some embodiments, but not necessarily all embodiments. The various appearances of "the embodiment," "an embodiment," or "an embodiment" are not necessarily all referring to the same embodiment. The description describes that a component, feature, structure, or characteristic "may", "might", or "could" be included, that a particular component, feature, structure, or characteristic "may", "might", or "could" be included, that the particular component, feature, structure, or characteristic is not necessarily included.
The foregoing embodiments are merely illustrative of the principles and utilities of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or change the above-mentioned embodiments without departing from the spirit and scope of the present invention. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical spirit of the present invention be covered by the claims of the present invention.

Claims (10)

1. A protocol design method in serial communication is characterized by comprising the following steps:
predefining a data frame structure, wherein the format of a frame head and a frame tail in the data frame structure is double bytes;
at a data sending end, packaging data according to a predefined data frame structure, and sending the data;
and at a data receiving end, acquiring data, judging each byte one by one, judging the received data as a frame header when two continuous bytes in the received data are matched with a predefined frame header, continuously receiving a subsequent data frame, judging whether the received data frame is the same as the predefined frame tail or not according to the last two bytes of the received data frame, and if the received data frame is the same as the predefined frame tail, confirming that the data frame is completely and correctly transmitted.
2. The method for designing a protocol in serial port communication according to claim 1, wherein a check frame is set in the data frame structure for performing data check on the received data.
3. The method according to claim 2, wherein the check frame is disposed after the data packet and before an end of the data packet.
4. The method according to claim 1, wherein the data frame structure comprises a frame header, a data length, a command code, a data packet, a check frame, and a frame trailer, which are sequentially arranged.
5. The method according to claim 4, wherein the data length is 1byte, the command code is 1byte, and the check frame is 2 bytes.
6. The method for designing a protocol in serial port communication according to claim 1, wherein the data receiving end feeds back the acknowledgement information to the data transmitting end after receiving the data, and retransmits the data if the data transmitting end does not receive the acknowledgement information fed back by the data receiving end within a preset time threshold range.
7. The method according to claim 1, wherein a threshold value of the number of times of retransmission of data overtime is preset, and when the number of times of retransmission of data is not fed back at the time of the data transmission end reaches the threshold value of the number of times, the system is restarted.
8. The method according to claim 1, wherein the frame header comprises two bytes different from each other.
9. The method according to claim 1, wherein the frame end is two bytes different from the frame head and different from each other.
10. The method for designing a protocol in serial port communication according to claim 5, wherein CRC data check is performed on the received data through the check frame.
CN202010435541.2A 2020-05-21 2020-05-21 Protocol design method in serial port communication Pending CN111711609A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010435541.2A CN111711609A (en) 2020-05-21 2020-05-21 Protocol design method in serial port communication

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010435541.2A CN111711609A (en) 2020-05-21 2020-05-21 Protocol design method in serial port communication

Publications (1)

Publication Number Publication Date
CN111711609A true CN111711609A (en) 2020-09-25

Family

ID=72538086

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010435541.2A Pending CN111711609A (en) 2020-05-21 2020-05-21 Protocol design method in serial port communication

Country Status (1)

Country Link
CN (1) CN111711609A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113392060A (en) * 2021-06-16 2021-09-14 天津津航计算技术研究所 Universal serial port data receiving and processing method
CN113824731A (en) * 2021-09-30 2021-12-21 深圳市卓翼科技股份有限公司 Serial port protocol frame analysis method and device and computer readable storage medium
CN114201425A (en) * 2021-11-19 2022-03-18 广州地铁设计研究院股份有限公司 Communication method and system capable of compensating slow communication rate
CN114338828A (en) * 2020-09-30 2022-04-12 中国电子科技集团公司第五十四研究所 Communication method, communication equipment and computer storage medium
CN114629597A (en) * 2022-03-22 2022-06-14 广东工业大学 Reliable transmission method and system applied to serial port
CN114928431A (en) * 2022-06-30 2022-08-19 南斗六星系统集成有限公司 Method and system for preventing packet loss communication of Internet of vehicles terminal
CN115379020A (en) * 2022-08-08 2022-11-22 南京信息工程大学 Embedded-based multi-machine communication protocol design method

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102279835A (en) * 2011-06-29 2011-12-14 厦门雅迅网络股份有限公司 Serial bus communication method and dynamic recognition method of master equipment and slave equipment in embedded system
CN104935527A (en) * 2015-06-12 2015-09-23 福建新大陆电脑股份有限公司 Data packing method of audio communication
CN107135049A (en) * 2017-04-19 2017-09-05 北京航天自动控制研究所 A kind of reliable asynchronous communication means towards discrete data
CN107180006A (en) * 2016-03-10 2017-09-19 北京迪文科技有限公司 The system and serial port communication method of a kind of serial communication
CN110515881A (en) * 2019-08-23 2019-11-29 西安爱生技术集团公司 A kind of synchronization system and synchronization high performance method of serial communication frame
CN110704356A (en) * 2019-09-25 2020-01-17 天津津航计算技术研究所 Universal serial port data analyzing method
CN110830482A (en) * 2019-11-13 2020-02-21 哈尔滨工业大学 Universal driving system and method for component serial interface

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102279835A (en) * 2011-06-29 2011-12-14 厦门雅迅网络股份有限公司 Serial bus communication method and dynamic recognition method of master equipment and slave equipment in embedded system
CN104935527A (en) * 2015-06-12 2015-09-23 福建新大陆电脑股份有限公司 Data packing method of audio communication
CN107180006A (en) * 2016-03-10 2017-09-19 北京迪文科技有限公司 The system and serial port communication method of a kind of serial communication
CN107135049A (en) * 2017-04-19 2017-09-05 北京航天自动控制研究所 A kind of reliable asynchronous communication means towards discrete data
CN110515881A (en) * 2019-08-23 2019-11-29 西安爱生技术集团公司 A kind of synchronization system and synchronization high performance method of serial communication frame
CN110704356A (en) * 2019-09-25 2020-01-17 天津津航计算技术研究所 Universal serial port data analyzing method
CN110830482A (en) * 2019-11-13 2020-02-21 哈尔滨工业大学 Universal driving system and method for component serial interface

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114338828A (en) * 2020-09-30 2022-04-12 中国电子科技集团公司第五十四研究所 Communication method, communication equipment and computer storage medium
CN114338828B (en) * 2020-09-30 2024-05-24 中国电子科技集团公司第五十四研究所 Communication method, communication device and computer storage medium
CN113392060A (en) * 2021-06-16 2021-09-14 天津津航计算技术研究所 Universal serial port data receiving and processing method
CN113824731A (en) * 2021-09-30 2021-12-21 深圳市卓翼科技股份有限公司 Serial port protocol frame analysis method and device and computer readable storage medium
CN114201425A (en) * 2021-11-19 2022-03-18 广州地铁设计研究院股份有限公司 Communication method and system capable of compensating slow communication rate
CN114201425B (en) * 2021-11-19 2024-05-07 广州地铁设计研究院股份有限公司 Communication method and system capable of compensating slow communication rate
CN114629597A (en) * 2022-03-22 2022-06-14 广东工业大学 Reliable transmission method and system applied to serial port
CN114629597B (en) * 2022-03-22 2023-11-21 广东工业大学 Reliable transmission method and system applied to serial port
CN114928431A (en) * 2022-06-30 2022-08-19 南斗六星系统集成有限公司 Method and system for preventing packet loss communication of Internet of vehicles terminal
CN115379020A (en) * 2022-08-08 2022-11-22 南京信息工程大学 Embedded-based multi-machine communication protocol design method
CN115379020B (en) * 2022-08-08 2023-06-09 南京信息工程大学 Embedded multi-machine communication protocol design method

Similar Documents

Publication Publication Date Title
CN111711609A (en) Protocol design method in serial port communication
CN103248467B (en) Based on the RDMA communication means of sheet inner connection tube reason
CN108446243B (en) Bidirectional communication method and system based on serial peripheral interface
US6965571B2 (en) Precise error reporting
CN101809953A (en) Millimeter-wave communications for peripheral devices
CN112217599B (en) Data frame receiving method and device, and communication method and system
WO2018171455A1 (en) Method and device for sending feedback information
TWI526019B (en) Method and device for processing a packet in a wlan system
US8335958B2 (en) Method of communication, in particular with capability of frame abortion or retransmission indication, between a transmitter and a receiver based on frames and corresponding communication node
CN112910856A (en) Communication protocol design method based on serial port communication
CN104038316B (en) The highly reliable timeliness asynchronous serial communication method high of space camera
CN114244780B (en) Data transmission method, data transmission device and related equipment
CN113132063A (en) Physical layer retransmission control method
CN111752579A (en) Bluetooth terminal upgrading method and device, storage medium and electronic equipment
US7783964B2 (en) Redundant 3-wire communication system and method
US7701846B2 (en) Bad data packet capture device
CN103368689A (en) Data transmission method and system
CN106788916B (en) Data transmission method and data transmission device for bus
JP7210867B2 (en) Acknowledgment packet transmission method and communication device
US5740189A (en) Integrity check method and system for serial-based communication
CN107994975B (en) Radio frequency data transmission optimization method, radio frequency data transmission equipment and radio frequency receiving end
CN111061666B (en) Miniaturized hidden bus in-place protection device and working method thereof
CN111741013B (en) Data transmission method and device
US7529812B2 (en) Socket connections over a serial link
CN112328524A (en) CAN and UART protocol mutual conversion communication guarantee method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200925

RJ01 Rejection of invention patent application after publication