From 1b1ed1d1fd3c1f64ee2b1e4cb086226f4f061a12 Mon Sep 17 00:00:00 2001 From: kai-morich Date: Wed, 22 Jan 2020 20:33:23 +0100 Subject: [PATCH] Updated Troubleshooting (markdown) --- Troubleshooting.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Troubleshooting.md b/Troubleshooting.md index ae2a0af..d9d8311 100644 --- a/Troubleshooting.md +++ b/Troubleshooting.md @@ -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?