Android - serial port related (2. Out-of-order, garbled, and missing data problems during serial port debugging)

I went through a lot of pits in the process of development and debugging, and found a lot of articles. In conclusion, I hope that I can remember it when I encounter it again in the future.

It refers to the relevant answer of the big guy: the link of the big guy


When using Google's serial debugging tools, sometimes there will be disorder, garbled characters and lack of data.

The out-of-order problem has the following possibilities:

1. Multiple serial ports are configured when configuring related serial ports
Cause: Multiple serial ports are opened at the same time, and resources are preempted between serial ports and information cannot be received in time.
Solution: Confirm that several serial ports are configured, and the serial ports cannot be opened cyclically.

2. There is no unified baud rate when configuring the relevant baud rate
Reason: The baud rate is not unified, and it is impossible to receive information accurately.
Solution: Confirm whether the baud rate of the connected device is the same.

3. The previous serial port is not closed when calling the next serial port
Cause: Two or more serial ports are opened at the same time, and resources will be preempted between the serial ports, resulting in that the serial port that you want to use cannot receive data in time.
Solution: Make sure to close the previous serial port when opening the next serial port.

4. The wrong underlying code is used, resulting in an error when receiving data.
Cause: Unknown
Solution: Change the underlying file SerialPort.c (directly change a code)

Replaced files at the bottom of the link


The garbled phenomenon is mainly caused by the following aspects:
1. The baud rate set by the device and the program is different,
Reason: When the baud rate difference is too large, the program cannot parse the transmission data
Solution: Uniform baud rate

2. The device transmits data using a type that cannot be resolved by the program
Reason: Since they are all transmitted through byte streams, the program needs to be converted into the corresponding type.
Solution: Uniform Type

The lack of data is more embarrassing:

The lack of data is mainly caused by the unstable connection between the serial port and the device, mainly because the connection cable is loose.
If there is a problem of lack of data, first make sure that the connection cable is firm.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324449478&siteId=291194637