1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-08 16:36:10 +00:00

Updated Troubleshooting (markdown)

kai-morich 2020-04-29 22:19:05 +02:00
parent b1f009aebd
commit 49a85d229a

@ -37,9 +37,9 @@ You don't. `/dev/tty*` is the Linux kernel's driver interface to various serial
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. 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. To reduce the number of USB requests, devices usually buffer data until some size or idle time is reached. Therefore request sizes heavily depend on the device type and actual data transfer pattern.
You need to account for this problem when designing your protocol. Some common techniques: For example, to receive a 100 byte string, you might read 64 bytes, then 36 bytes, instead of a single message of 100 bytes. You need to account for this problem when designing your protocol. Some common techniques:
* Fixed length messages: If you a message is always going to be 100 bytes, just keep reading until you have all 100. * Fixed length messages: If you a message is always going to be 100 bytes, just keep reading until you have all 100.
* Length-prefixed messages: Prefix every message with a fixed-length `size` value; your message is complete after you've read `size` more bytes. * Length-prefixed messages: Prefix every message with a fixed-length `size` value; your message is complete after you've read `size` more bytes.