I am using com.github.mik3y:usb-serial-for-android.
Only some packets reach correctly, some packets lose their length. Sometimes I get a full packet, but usually the response is truncated. And the very first package is correct.
private val readerReceiver = Runnable {
while (!_needStopThread) {
port.write("scn20 500000000 1500000000 5000000 200 20 10700000 8500 8\\r\\n".toByteArray(),200)
var data = ByteArray(4096)
val len = port.read(data, 200)
data = data.copyOf(len)
if (data.isNotEmpty()) {
callBack(String(data, 0, len))
}
}
_needStopThread = false
}
I tried using serial without a library, it didn't help. I tried to collect packages into one, but the essence does not change, it is part of the package that is cut off.