UsbSerial icon indicating copy to clipboard operation
UsbSerial copied to clipboard

Response have cut bytes result and repeated

Open JudeBautista opened this issue 8 years ago • 1 comments

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 ?

JudeBautista avatar Oct 09 '18 06:10 JudeBautista

Some Usb to serial adapters split data. Two possible solutions:

  • Implement your own buffer and append data there.
  • Use SerialInputStream

felHR85 avatar Dec 26 '18 12:12 felHR85