Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一次性传输数据限制 #48

Open
yedashen opened this issue Nov 18, 2022 · 1 comment
Open

一次性传输数据限制 #48

yedashen opened this issue Nov 18, 2022 · 1 comment

Comments

@yedashen
Copy link

为啥我从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

@licheedev
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants