Method and system for data communication based on universal asynchronous transceiver

By using separators to split data packets, set check bits and escape commands in the communication between the Internet of Things wireless module and external devices, the problems of insecure transmission, limited resources and error transmission are solved, and efficient and reliable data transmission is achieved.

CN119697282APending Publication Date: 2025-03-25SHENZHEN SHENLIAN ZHIDA TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411692448.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

The communication between the Internet of Things wireless module and external devices has problems such as insecure data transmission, limited transmission resources, and incorrect transmission efficiency.

Method used

Use a separator to divide the data packets to be transmitted, set the check bit, escape the commands in the data packets to be set, and transmit the escaped data packets.

Benefits of technology

It improves transmission efficiency and data transmission security, avoids error transmission, and ensures communication reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119697282A_ABST
    Figure CN119697282A_ABST
Patent Text Reader

Abstract

The invention provides a method and a system for data communication based on a universal asynchronous transceiver. The method comprises the following steps of: segmenting a data packet to be transmitted by adopting a separator to obtain a segmented data packet; setting check bits for the segmented data packets; escaping the meaning of the command in the data packet with the check bit to obtain a data packet after the meaning of the command is escaped; and transmitting the data packet after the escape. According to the invention, the transmission efficiency and the security of data transmission are improved, and wrong transmission is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data transmission in the Internet of Things, and in particular to a method and system for data communication based on a universal asynchronous receiver / transmitter. Background Art

[0002] IoT sensors are usually deployed in large numbers and have the following characteristics:

[0003] 1. Energy is limited, and some battery-powered devices need to sleep;

[0004] 2. Limited hardware resources, using low-cost microcontrollers;

[0005] 3. The communication frequency is low, usually from once per minute to once per hour;

[0006] 4. Low data volume, usually 4 to 64 bytes per communication, sometimes more;

[0007] 5. Packet address communication, each communication consists of multiple data and communication target address information;

[0008] 6. Equipment that is unattended or difficult to maintain.

[0009] The IoT wireless module is one of the components of the IoT sensor. Usually, the IoT wireless module is responsible for realizing the wireless communication function, and the data load of its communication is passed from the external device to the IoT wireless module.

[0010] There are occasional errors in serial communication, and the error probability is related to system design. In conventional communication methods, if an error occurs at the length position, the receiver will misjudge the length of the target data, resulting in a packet break error. In this case, if the receiver confirms the wrong packet length, it will definitely start receiving the next packet at the wrong position, which will cause the data of the next packet to also be wrong. This situation is called error transmission. The obvious feature of error transmission is that the correct data packet following the error data packet cannot be received correctly. When sending certain specific data, error transmission will cause continuous communication interruption. This situation is often considered to be a "node crash" and can be repaired by resetting. However, for IoT nodes that have been deployed, they are usually deployed in locations that cannot be reached by personnel, and the reset operation is usually difficult. Since the probability of this problem is very low and it will only occur in a few days or even dozens of days, traditional solutions pay little attention to it.

[0011] The traditional packet segmentation mechanism requires complex judgment after receiving the packet header, such as the three common solutions mentioned below:

[0012] 1) For example, in order to avoid erroneous transmission, additional redundant bits are required at the packet header and packet length, and separate checks are required.

[0013] 2) When using the header length, the length is usually defined as the amount of data received by the serial port. If this is done, the length of the data collected by the serial port will be difficult to define, and because of the existence of escape, the actual data length and the length received by the serial port are not one-to-one corresponding.

[0014] 3) If there are special commands, additional processing is required for the special commands within the interrupt.

[0015] The above poor design will increase the number of exceptions in the microcontroller's transmission and reception process. For example, judging the packet header and length is an exception. Exceptions will increase the conditional transfer statements in the interrupt, thereby slowing down the response speed. The redundant bits and separate checks for judging the packet header and packet length in the interrupt will cause the interrupt function to execute too long, which will lead to real-time problems.

[0016] When sending time-sensitive commands (such as buffer full, packet confirmation received), the traditional method sends the command like regular data. If data is being communicated at the same time as the command, the command will usually be arranged after the data, causing program errors.

[0017] In summary, in the prior art, the communication between the IoT wireless module and the external device has problems such as insecure data transmission, low transmission efficiency due to limited transmission resources, and error transmission. Summary of the invention

[0018] In order to solve the problems of insecure data transmission, low transmission efficiency caused by limited transmission resources, and error transmission in the communication between the IoT wireless module and the external device in the prior art, the present invention proposes a method for data communication based on a universal asynchronous receiver and transmitter, comprising:

[0019] The data packets to be transmitted are segmented by using a delimiter to obtain segmented data packets;

[0020] Set the check bit for the segmented data packets;

[0021] Escape the command in the data packet for setting the check bit to obtain a data packet after command escape;

[0022] The escaped data packet is transmitted.

[0023] Preferably, the step of using a delimiter to segment the data packet to be transmitted to obtain the segmented data packets includes:

[0024] Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

[0025] Preferably, setting a check bit for the segmented data packets comprises:

[0026] Determine whether a delimiter appears in the check digit. If a delimiter appears in the check digit, escape the check digit and set the escaped check digit at the end of the segmented data packet. Otherwise, do not escape the check digit and directly set the check digit at the end of the segmented data packet.

[0027] Preferably, escaping the command in the data packet with the check bit set to obtain the command-escaped data packet includes:

[0028] The command in the data packet for setting the check bit is represented according to predefined characters to obtain a data packet after command escape.

[0029] Preferably, after transmitting the escaped data packet, the method further comprises:

[0030] The communication is confirmed by serial number.

[0031] Preferably, the using of a serial number to confirm the communication includes:

[0032] Set a serial number for the escaped data packet to be transmitted, incrementing by 1 each time it is sent, from 0 to 127 and then back to 0;

[0033] Confirmation is done through an escape command that the recipient replies with.

[0034] On the other hand, the present invention also discloses a system for data communication based on a universal asynchronous receiver / transmitter, comprising:

[0035] The data packet segmentation module is used to segment the data packets to be transmitted using a delimiter to obtain segmented data packets;

[0036] A check module, used for setting a check bit for the segmented data packets;

[0037] The escape module is used to escape the command in the data packet with the check bit set to obtain the data packet after the command is escaped;

[0038] A transmission module is used to transmit the escaped data packet.

[0039] Preferably, the data packet segmentation module is specifically used for:

[0040] Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted, and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

[0041] Optionally, the verification module is specifically used to:

[0042] Determine whether a delimiter appears in the check digit. If a delimiter appears in the check digit, escape the check digit and set the escaped check digit at the end of the segmented data packet. Otherwise, do not escape the check digit and directly set the check digit at the end of the segmented data packet.

[0043] Optionally, the escape module is specifically used for:

[0044] The command in the data packet for setting the check bit is represented according to predefined characters to obtain a data packet after command escape.

[0045] Optionally, it also includes: a confirmation module;

[0046] The confirmation module is used to: set a serial number for the escaped data packet to be transmitted, which increases by 1 each time it is sent, from 0 to 127 and then returns to 0; and confirm through the escape command replied by the recipient.

[0047] In another aspect, the present application further provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus;

[0048] The memory is used to store one or more programs;

[0049] When the one or more programs are executed by the at least one processor, the method for performing data communication based on a universal asynchronous receiver and transmitter as described above is implemented.

[0050] On the other hand, the present application further provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed, the method for performing data communication based on a universal asynchronous receiver and transmitter as described above is implemented.

[0051] Compared with the prior art, the present invention has the following beneficial effects:

[0052] The present invention provides a method for data communication based on a universal asynchronous receiver / transmitter, comprising: using a separator to segment a data packet to be transmitted to obtain segmented data packets; setting a check bit for the segmented data packets; escaping a command in the data packet with the check bit set to obtain a command-escaped data packet; and transmitting the escaped data packet. The present invention improves transmission efficiency and data transmission security, and avoids erroneous transmission. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 A flow chart of a method for data communication based on a universal asynchronous receiver / transmitter of the present invention;

[0054] Figure 2 A schematic diagram of using a serial number to confirm communication according to the present invention;

[0055] Figure 3 The figure is a schematic diagram of the structure of an electronic device of the present invention. DETAILED DESCRIPTION

[0056] The present invention proposes a method for data communication based on a universal asynchronous receiver and transmitter, which is optimized for the application scenario of "communication between an Internet of Things wireless module and an external device", achieves a balance in terms of stability, speed and programming strategy, and has excellent practical value.

[0057] In order to better understand the present invention, the content of the present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0058] Embodiment 1:

[0059] A method for data communication based on a universal asynchronous receiver and transmitter, such as Figure 1 As shown, including:

[0060] Step S1: using a delimiter to segment the data packet to be transmitted to obtain segmented data packets;

[0061] Step S2: setting a check bit for the segmented data packets;

[0062] Step S3: escaping the command in the data packet with the check bit set to obtain a data packet after command escaping;

[0063] Step S4: Transmitting the escaped data packet.

[0064] The steps of the present invention are described in detail below:

[0065] Step S1: using a delimiter to segment the data packet to be transmitted to obtain segmented data packets, including:

[0066] Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted, and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

[0067] Step S1 specifically includes:

[0068] Use 9D to split the packet.

[0069] Design principle: In IoT communication scenarios, 9D is a relatively rare communication data:

[0070] (1) In character communication, 9D does not belong to the ASCII and GB2312 character sets.

[0071] (2) When transmitting commands, commands are usually encoded from 0 in the forward direction, and error reporting is usually encoded from -1 (0xff) in the reverse direction.

[0072] 9D will usually only appear in situations where numbers are reported in binary.

[0073] So use 9D as the delimiter.

[0074] For example, if [01 02 03 04] is sent, the actual transmitted data is: ...9D 01 02 03 04 9D...

[0075] If multiple packets are transmitted, for example [01 02 03 04] and [06 07 08], the transmitted data is:

[0076] ……9D 01 02 03 04 9D 06 07 08 9D…….

[0077] When a packet is sent, 9D needs to be sent as a sign of the end of the packet.

[0078] Design principle: The delimiter can perfectly split the packet while minimizing the bus load.

[0079] If the packet length and other information are used as the basis for judgment: 1) The receiving processing logic needs to save additional variables and make judgments. In the field of microcontrollers, reception usually occurs in interrupts. The judgment should be simplified as much as possible to reduce the number of shared variables between threads. This solution requires the interrupt to store the data in a queue and make a judgment. If the received data is 9D, this notifies the application to process it. 2) If an exception occurs and the number of bits sent and received is inconsistent, it will affect the length of the next packet received, causing the transmission to be affected (the previous communication was abnormal, causing the next communication that was originally normal to be abnormal);

[0080] If the bus is idle for segmentation: 1) The response is slow, and the transmission is completed only when the bus is idle; 2) The programming is complex, and the bus must be judged to be idle to avoid accidental interruptions during transmission, or complex logic is required to judge interruptions and subpackets.

[0081] Using 9-Byte communication: The bus load increases by about 10%.

[0082] If other methods are used, such as using AA BB as the packet header, AA BB still needs to be processed when encountered in data communication (usually AA BB in the data is converted to AA AA BB). The communication data volume of each packet will increase, and the data processing logic will be more complicated.

[0083] In this way, if 9D exists in the data communication, it will cause misunderstanding to the receiver. It is necessary to cooperate with escape to ensure that 9D does not appear in the data packet. The escape operation will be required.

[0084] During the communication process, if there is data that happens to be 9D, it will cause misunderstanding, and the receiver will mistakenly think that a new packet has been received. In order to avoid misunderstandings and ensure that 9D does not appear during the communication process, escape characters are used to expand the communication character set. Escape characters refer to using a character to indicate that the next character to appear represents another character: the sender uses 9E FE to represent 9D and 9E FF to represent 9E.

[0085] For example, if you need to send [01 02 9D 9E], the actual data sent is: ...9D 01 02 9E FE 9EFF9D......

[0086] The design principle of this escape is:

[0087] The receiving logic will handle 9D (delimiter) and 9E specially. When 9E is encountered, no data is recorded, but the escape status count is incremented. In the escape state, when the next character is received, it is handled specially and the escape status count is decremented.

[0088] Use FE to map 9D and FF to map 9E. Because FE-9D=FF-9E=61 (HEX), if the escaped data is greater than FD, you can directly subtract 61 to get the original data.

[0089] The escape operation can usually be completed in the receiving interrupt, and the reverse escaped data is directly stored in the buffer. Cost: Increased bandwidth usage. Assuming that the probability of any data appearing in the data is equal, the channel occupancy increases to: 2 / 256+1=100.78125%.

[0090] When sending, check whether escape is required when sending any byte. If necessary, send the escaped characters continuously.

[0091] When no data is transmitted for a long time, the bus may be disturbed occasionally, causing the receiver to receive non-existent data. The longer the idle time, the higher the probability of this happening. Such interference will be received as part of the next packet, so the delimiter is used to eliminate the above interference before actual communication. It is necessary to send 1 more byte, but when there is no communication for a long time, the data is usually not high, and the additional load can be received.

[0092] If there is a long interval between two packets, each packet starts and ends with 9D, for example, [0102 03 04] and [06 07 08], and the transmitted data is:

[0093] ……9D 01 02 03 04 9D……9D 06 07 08 9D……

[0094] The receiver should be able to handle multiple consecutive 9Ds and regard it as normal.

[0095] Step S2: Setting a check bit for the segmented data packets, including:

[0096] Determine whether a delimiter appears in the check digit. If a delimiter appears in the check digit, escape the check digit and set the escaped check digit at the end of the segmented data packet. Otherwise, do not escape the check digit and directly set the check digit at the end of the segmented data packet.

[0097] Step S2 specifically includes:

[0098] Use CRC8 as the check bit. The check bit follows the end of the data communication. For example, when sending [20 30 56 3412], the actual data sent is: ...9D 20 30 56 34 12C0 9D..., where C0 is calculated by CRC check based on 2030 56 34 12. If the check bit appears as 9D or 9E, it also needs to be escaped.

[0099] Design principle: In this application scenario, the bit error rate of the short-distance UART is very low. It can even be said that most of the erroneous data comes from plugging and unplugging, microcontroller reset or occasional software errors. In order to avoid packets caused by such errors being received as normal packets, the most basic check needs to be added.

[0100] The strength of the check is controlled in principle by the number of check bits. Here, the minimum CRC8 is used as the check.

[0101] Cost: Increased bandwidth usage, 1 byte per packet.

[0102] Alternatives:

[0103] 1. Due to the above reasons, after using the split packet, there is no need to use the length to control the packet reception. Therefore, the data length can also be used as a check. In the old microcontroller, the data length is used instead of CRC for check, which can avoid the use of CRC algorithm.

[0104] 2. In situations where security requirements are extremely high, CRC32 can also be used as a check.

[0105] Step S3: escape the command in the data packet with the check bit set to obtain a command escaped data packet, including:

[0106] The command in the data packet for setting the check bit is represented according to predefined characters to obtain a data packet after command escape.

[0107] Step S3 specifically includes:

[0108] If the data following the escape character 9E is not FE or FF, it is regarded as an escape command.

[0109] During communication, 9E XX is used to indicate specific instructions.

[0110] For example, E0 means the machine has been awakened, and the sender usually receives a wake-up signal (from another channel)

[0111] After completing the wake-up (usually takes several milliseconds), the serial port sends: ...9E E0...

[0112] Escape commands can also occur in regular communications. For example, the E1 command indicates that the receiving buffer of the local machine is full and busy, but the local machine is sending [01 02 9D 9E]. The data actually sent will be:

[0113] ……9D 01 9E E1 02 9E FE 9E FF 9D……

[0114] or

[0115] ……9D 01 02 9E 9E E1 FE 9E FF 9D……

[0116] As you can see, the escape command can be embedded in normal packet communication. After receiving 9E, the receiver needs to increment the escape flag by 1, and when receiving non-9E data later, treat it as a special case and decrement the escape flag by 1.

[0117] Design principle: The escape command can handle urgent but low-data-volume command transactions, and can respond quickly due to its "queue-jumpable" nature.

[0118] For the sender, if a send queue is used, the data to be sent can be inserted at the head of the queue without additional judgment. (Specifically, when a circular queue is used for sending, there is an out-queue pointer. During the interrupt, each time a byte is sent, the pointer moves forward and circulates in the queue. At this time, the "queue head insertion" operation is to move the out-queue pointer backward after turning off the interrupt, and put the data to be sent here.)

[0119] When the send queue is not used, the flag bit can be checked when sending and the command can be inserted according to the flag bit status.

[0120] For the receiver, according to the aforementioned logic, the data received in the escaped state can be regarded as a command.

[0121] This design can greatly simplify the program overhead for both senders and receivers.

[0122] The escape commands are:

[0123] In communications with serial numbers, use a 7-digit serial number and use an escape command plus the serial number to report successful reception.

[0124] Other cases indicate specific communication commands and reports:

[0125] E0: wake-up completed, data can be received

[0126] E1: Receiving is busy, data has been lost

[0127] E2: Receive alarm, buffer is already 80% occupied

[0128] E3: Communication test, please reply to the escape command E4

[0129] E4: Communication test response.

[0130] E5: Channel test, used to observe the eye diagram.

[0131] E6: Our serial number is reset to zero. (Usually, the serial number is 0 after reset. If the serial number of the previous packet is exactly 0, the first packet after reset will be misunderstood. Use this command to avoid this situation.)

[0132] It should be noted that the escape command does not include 9D and 9E. In addition to these two bytes, other escape commands can be defined according to the application scenario.

[0133] Step S4: after transmitting the escaped data packet, the method further comprises:

[0134] The communication is confirmed by serial number.

[0135] Preferably, the communication is confirmed by using a serial number, such as Figure 2 As shown, including:

[0136] Set a serial number for the escaped data packet to be transmitted, incrementing by 1 each time it is sent, from 0 to 127 and then back to 0;

[0137] Confirmation is done through an escape command that the recipient replies with.

[0138] The specific steps for confirming communication using serial numbers are as follows:

[0139] In situations where reliability is extremely high, serial numbers can be used to confirm communications: for example, [01 020304] and [06 07 08], the transmitted data is:

[0140] ……9D 01 01 02 03 04CE 9D……9D 02 06 07 08CE 9D……

[0141] CE is the CRC check value. No calculation is performed here, and CE is used for demonstration.

[0142] 01 02 is the serial number of the packet, which increases by 1 each time it is sent, from 0 to 127 and then returns to 0.

[0143] When the receiver receives the correct packet, it replies with the escape command:

[0144] ...9E 01...9E 02...

[0145] If the receiver does not respond, it means that the packet was not received and needs to be retransmitted.

[0146] After receiving the data, the receiver will automatically remove the data with duplicate serial numbers.

[0147] In order to avoid errors caused by duplicate serial numbers, the sender needs to send a serial number reset command after reset:

[0148] ……9E E6……

[0149] Instruct our serial number to restart counting.

[0150] The features applicable to the present invention are:

[0151] 1) Using a serial port or universal asynchronous receiver / transmitter (UART);

[0152] 2) Two-way communication;

[0153] 3) Packet data communication is required; (the data packet contains the address, and each communication consists of multiple data and the communication target address information)

[0154] 4) Use a general-purpose microcontroller (because the microcontroller directly operates interrupts and receives in bytes. If both parties in communication are computers and other devices, it cannot reflect the advantages. When one party is a microcontroller, it is usually the computer with strong computing power that takes care of the microcontroller with weak computing power. Therefore, this protocol is also suitable);

[0155] The present invention is designed for the scene characteristics of the IoT communication module communicating with external devices, and can ensure the reliability of communication to a great extent in the scene without occupying additional bandwidth. The present invention can balance the algorithm of the microcontroller, ensure that no complex calculations are performed in the interrupt, and both the receiver and the sender can use simple logic to complete the communication.

[0156] The protocol claimed by the present invention uses a delimiter priority mechanism, which can completely avoid erroneous transmission and consumes almost no additional bandwidth.

[0157] The protocol advocated by the present invention is optimized for microcontroller processing of both reception and transmission, so that both transmission and reception programs can use the interrupt system and minimize the transfer statements in the interrupt function.

[0158] The protocol claimed by the present invention allows for inserting burst commands into the internal part of the transmitted data packet, and designs an algorithm for parsing such commands by a microcontroller, thereby realizing this function with almost no additional code. This function also makes it possible to establish a confirmation mechanism in reliable transmission, so that the sender can detect data loss (usually because the other party is sleeping or there is occasional interference), thereby ensuring reliable transmission.

[0159] The protocol advocated by the present invention is targeted at specific scenarios, comprehensively considers multiple factors, balances pros and cons, and achieves design optimization, especially in reducing redundant loads, algorithms for microcontrollers and reliable transmission, which has a very good effect compared with traditional protocols. The specific scenarios here are energy-limited, low communication frequency and other scenarios.

[0160] Example 2

[0161] The present invention based on the same inventive concept also provides a system for data communication based on a universal asynchronous receiver / transmitter, comprising:

[0162] The data packet segmentation module is used to segment the data packets to be transmitted using a delimiter to obtain segmented data packets;

[0163] A check module, used for setting a check bit for the segmented data packets;

[0164] The escape module is used to escape the command in the data packet with the check bit set to obtain the data packet after the command is escaped;

[0165] A transmission module is used to transmit the escaped data packet.

[0166] Preferably, the data packet segmentation module is specifically used for:

[0167] Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted, and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

[0168] Optionally, the verification module is specifically used to:

[0169] Determine whether a delimiter appears in the check digit. If a delimiter appears in the check digit, escape the check digit and set the escaped check digit at the end of the segmented data packet. Otherwise, do not escape the check digit and directly set the check digit at the end of the segmented data packet.

[0170] Optionally, the escape module is specifically used for:

[0171] The command in the data packet for setting the check bit is represented according to predefined characters to obtain a data packet after command escape.

[0172] Optionally, it also includes: a confirmation module;

[0173] The confirmation module is used to: set a serial number for the escaped data packet to be transmitted, which increases by 1 each time it is sent, from 0 to 127 and then returns to 0; and confirm through the escape command replied by the recipient.

[0174] Example 3

[0175] like Figure 3 As shown, the present invention also provides an electronic device, which may be a computer device, a single-chip device, an intelligent mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, the processor, and the transceiver component are connected via a bus; the memory may be used to store an execution program, and an exemplary execution program may include instructions; the processor is used to execute the instructions stored in the memory. The memory may also be used to store data, which may be called and / or modified when the instructions are executed.

[0176] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, which is suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in a storage medium to implement the corresponding method flow or corresponding functions, so as to implement the steps of a method for data communication based on a universal asynchronous receiver and transmitter in the above-mentioned embodiment.

[0177] Example 4

[0178] Based on the same inventive concept, the present invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory), which is a memory device in the electronic device for storing programs and data. It can be understood that the storage medium here can include both the built-in storage medium in the electronic device and the extended storage medium supported by the electronic device. The storage medium provides a storage space, which stores the operating system of the terminal. In addition, one or more instructions suitable for being loaded and executed by the processor are also stored in the storage space, and these instructions can be one or more execution programs (including program codes). It should be noted that the storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory. The processor loads and executes one or more instructions stored in the storage medium, which can implement the steps of a method for data communication based on a universal asynchronous receiver and transmitter in the above embodiment.

[0179] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0180] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0181] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1A function specified in one or more boxes.

[0182] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0183] The above are merely embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention are included in the scope of the claims of the present invention to be approved.

Claims

1. A method for data communication based on a universal asynchronous receiver / transmitter, characterized in that: include: The data packets to be transmitted are segmented by using a delimiter to obtain segmented data packets; Set the check bit for the segmented data packets; Escape the command in the data packet for setting the check bit to obtain a data packet after command escape; The escaped data packet is transmitted.

2. The method according to claim 1, characterized in that The method of using a delimiter to segment the data packet to be transmitted to obtain the segmented data packet includes: Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

3. The method according to claim 1, characterized in that The step of setting a check bit for the divided data packets comprises: Determine whether a delimiter appears in the check digit. If a delimiter appears in the check digit, escape the check digit and set the escaped check digit at the end of the segmented data packet. Otherwise, do not escape the check digit and directly set the check digit at the end of the segmented data packet.

4. The method according to claim 1, characterized in that The step of escaping the command in the data packet for setting the check bit to obtain the data packet after command escaping includes: The command in the data packet for setting the check bit is represented according to predefined characters to obtain a data packet after command escape.

5. The method according to claim 1, characterized in that After transmitting the escaped data packet, the method further comprises: The communication is confirmed by serial number.

6. The method according to claim 5, characterized in that The use of a serial number to confirm the communication includes: Set a serial number for the escaped data packet to be transmitted, incrementing by 1 each time it is sent, from 0 to 127 and then back to 0; Confirmation is done through an escape command that the recipient replies with.

7. A system for data communication based on a universal asynchronous receiver / transmitter, characterized in that: include: The data packet segmentation module is used to segment the data packets to be transmitted using a delimiter to obtain segmented data packets; A check module, used for setting a check bit for the segmented data packets; The escape module is used to escape the command in the data packet with the check bit set to obtain the data packet after the command is escaped; A transmission module is used to transmit the escaped data packet.

8. The system according to claim 7, characterized in that The data packet segmentation module is specifically used for: Determine whether there is data identical to the delimiter in the data packet to be transmitted. If so, escape the data packet to be transmitted, and use the delimiter to split the escaped data packet to obtain the split data packet. Otherwise, use the delimiter to split the data packet to be transmitted to obtain the split data packet.

9. An electronic device, characterized in that: include: at least one processor and memory; The memory and the processor are connected via a bus; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, a method for performing data communication based on a universal asynchronous receiver and transmitter as claimed in any one of claims 1 to 6 is implemented.

10. A readable storage medium, characterized in that: An execution program is stored thereon, and when the execution program is executed, a method for data communication based on a universal asynchronous receiver and transmitter as claimed in any one of claims 1 to 6 is implemented.