Android-SerialPort-API icon indicating copy to clipboard operation
Android-SerialPort-API copied to clipboard

一次性传输数据限制

Open yedashen opened this issue 2 years ago • 1 comments

为啥我从serialPort.getInputStream() 拿到的数据最多只能拿到32个字节 while (!isInterrupted()) { try { if (mInputStream == null) { return; } int available = mInputStream.available(); byte[] buffer = new byte[available]; int size = mInputStream.read(buffer); if (size > 0) { if (null != callback) { callback.callback(buffer); } } } catch (IOException e) { e.printStackTrace(); return; } }

我这里如果改成比32大的byte[] ,32位之后的数据全是0

yedashen avatar Nov 18 '22 02:11 yedashen

不要期待一次性就能把串口传输的数据读全的,我试过对接一个波特率只有4800的项目,每次read只能读到1个有效字节,解决方法是把读到的数据全缓存到一个大数组里面,然后按照具体协议进行分包。

licheedev avatar Nov 22 '22 01:11 licheedev