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

onNewData Callback Incomplete data #451

Closed wjgso closed 1 year ago

wjgso commented 1 year ago

Hello!As the title,When I use this “onNewData” to receive data, I often receive incomplete data, and the missing data will enter “onNewData” again.

for example: I will always receive data, but the data will be like this. data = "10089"
first receive ---> "10089" second receive ---> "1008" third receive ---> "910089" Sometimes it is lost, sometimes it is normal

My current processing method is splicing. I would like to ask whether this is a problem with the USB or the library. Looking forward to your reply

wjgso commented 1 year ago

My version is com.github.mik3y:usb-serial-for-android:3.3.0

kai-morich commented 1 year ago

This is normal, see https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#When_reading_a_message_why_dont_all_bytes_arrive_at_the_same_time

guilhermejsrsantos commented 1 year ago

@kai-morich Do you have any examples on how to implement any of the approaches you've described with event driven data (onNewData)? My application is supposed to receive data at random points in time from a microcontroller and handle it accordingly but I just can't figure out how to implement this behavior with your library. Thanks.

wjgso commented 1 year ago

这是正常的,请参阅 https://github.com/mik3y/usb-serial-for-android/wiki/FAQ#When_reading_a_message_why_dont_all_bytes_arrive_at_the_same_time

Thank you for your reply.