UsbSerial
UsbSerial copied to clipboard
Response have cut bytes result and repeated
Hello,
I successful, implement your method, however, when i read a bytes given response from terminal, I received a multiple response, and cutted and repeated bytes. sometimes long and sometimes short, and sometimes gives me wrong arrangement of bytes,
So what i did is like this
private UsbSerialInterface.UsbReadCallback deviceRespond = new UsbSerialInterface.UsbReadCallback() {
@Override
public void onReceivedData(final byte[] arg0) {
if (arg0 != null) {
mContext.runOnUiThread(new Runnable() {
@Override
public void run() {
List<String> response = new ArrayList<>();
for (byte b : arg0) {
if (String.valueOf(b).length() != 1) {
response.add(String.valueOf(b));
} else
response.add("0" + String.valueOf(b));
}
mCallback.onDeviceResponse(id, response, arg0);
}
});
}
}
};
is there any reason why i got wrong in this thing ?
Some Usb to serial adapters split data. Two possible solutions:
- Implement your own buffer and append data there.
- Use SerialInputStream