1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-14 19:36:11 +00:00

Updated Troubleshooting (markdown)

kai-morich 2020-01-22 20:33:23 +01:00
parent 396c5088f4
commit 1b1ed1d1fd

@ -40,7 +40,7 @@ You don't. `/dev/tty*` is the Linux kernel's driver interface to various serial
## When reading a message, why don't all bytes arrive at the same time?
The protocol layer does not guarantee all bytes will arrive in a single message. In fact the protocol layer doesn't have any knowledge of what your "message" is — it is just an interface for sending a serial stream of bytes.
The protocol layer does not guarantee that all bytes will arrive in a single message. In fact the protocol layer doesn't have any knowledge of what your "message" is — it is just an interface for sending a serial stream of bytes.
For example, to receive a 100 byte string, you might read 64 bytes, then 36 bytes, instead of a single message of 100 bytes.
@ -50,6 +50,19 @@ You need to account for this problem when designing your protocol. Some common t
* Length-prefixed messages: Prefix every message with a fixed-length `size` value; your message is complete after you've read `size` more bytes.
* Newline-terminated messages: Read until you see a `\n` (or any other "terminal" character).
## Is `write` synchronous?
It's typically not.
Write consists of 2 phases:
1) from android to usb device
2) from usb device to serial port
If the send buffer on the usb device is not full, the write call returns after phase 1. If the buffer is full, e.g. your write is larger or older data is still to be send, the write call returns when enough data has been send over the serial port and the rest is in the buffer.
Waiting for write completion is typically done with application specific protocols, like request-response pattern.
## How to set timeout in `read`/`write` methods?