mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.
MIT License
4.9k stars 1.59k forks source link

Is there a way to get the number of available bytes in the read buffer without actually reading? #405

Closed SparkyTD closed 2 years ago

SparkyTD commented 2 years ago

Some other serial libraries use an internal buffer, and they expose an API for the user to peek at the number of available bytes in this buffer. (e.g. SerialPort.BytesToRead in C#, SerialPort.bytesAvailable() in jSerialComm). Is something like this possible with this library? I can't see any relevant methods in the UsbSerialDevice class other than read and write, but maybe I'm missing something.

kai-morich commented 2 years ago

There is no buffering in this library. It's also not possible to peek into USB transfers. If you do not want to allocate to much memory, you can do partial read with a buffer of size port.getReadEndpoint().getMaxPacketSize() as mentioned in FAQ