mik3y / usb-serial-for-android

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

UsbSerialPort.read return bad data but .write works fine. #447

Closed BenoitAlterealities closed 2 years ago

BenoitAlterealities commented 2 years ago

Hello, so I have connected an HTC Focus 3 to a CP2104, I punctualy call UsbSerialPort.write() it works juste fine. Ideally I would like to read the bytes of the buffer 1 by 1 with a buffer of size 1, but when I do that, all that I can read is 0. But maybe I'm juste doing it wrong cause I'm kinda new to this. Here is my read code section :

byte[] readBuffer = new byte[1];
return port.read(readBuffer, 1000);

I'll appreciate any tips, and I'll comment my solution when I find one maybe it would help other newbie like me XD.

kai-morich commented 2 years ago

You typically cannot read single bytes, please check https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#How_to_size_the_codereadcode_buffer

BenoitAlterealities commented 2 years ago

Thank you.