androidthings / sample-uartloopback

Echo received characters over a UART with Android Things
Apache License 2.0
78 stars 39 forks source link

UART divides message when writing it #4

Closed mahermeg17 closed 6 years ago

mahermeg17 commented 6 years ago

Hi, I'm using this sample code with a PICO PI IMX6UL. The problem is when I send a String like "abcdefghijklmno". I receive it on the other side divided, it means not as a single string, like "abc" then "de" then "fghijk" then "lmno". And messages are received into random way, not the same number of parts, and not the same length of each part. My UART config is as following: BAUD_RATE = 115200; DATA_BITS = 8; STOP_BITS = 1; CHUNK_SIZE = 256; and PARITY_NONE

On the other side, I use UsbSerial library on an android phone (https://github.com/felHR85/UsbSerial)

No problem when reading data. I need to read data in one piece. Any help please! Thanks.

Fleker commented 6 years ago

This might be a bug in the UsbSerial library.

But in general, you should expect UART data to come in intermittently. Although it may stream continually, the interrupts may be fired at any point. You should buffer the data and determine the stop point on your own, then process it.

Generally, embedded engineers will do several different steps to properly segment the data:

mahermeg17 commented 6 years ago

Thank you for the reply. it seems to be caused by the UsbSerial lib. I found a similar bug on the project issues https://github.com/felHR85/UsbSerial/issues/92

Bests,