mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to return complete data while read a message ?

HarizahSyawal opened this issue · comments

Hello, i have do some integration for vending machine using mdb protocol and i'm using this library to communicated with. My issue here is whenever i read response from vending machine, it return line by line and the message not completed read in one line.
WhatsApp Image 2023-11-27 at 23 29 33_c91f6b8f

it supposed to be like this :
WhatsApp Image 2023-11-28 at 11 34 34_63489c40

Here is my code :

` private void receivedMessage(ArrayDeque<byte[]> datas) {

    char STX = '\u0002'; // Start of Text
    char ETX = '\u0003'; // End of Text
    SpannableStringBuilder spn = new SpannableStringBuilder();

    for (byte[] data : datas) {
        String msg = new String(data);
        String messageWithoutSTXETX = msg.replace(STX, ' ').replace(ETX, ' ');
        spn.append(messageWithoutSTXETX);
    }
    mTvReceiveText.append(TextUtil.newline_crlf+spn);
    Log.d(TAG,"FINAL MESSAGE "+spn);

    if (String.valueOf(spn).contains("1300") || String.valueOf(spn).startsWith("1300")) {
        handleReceivedMessage(String.valueOf(spn).trim());
    }
    else {
        Log.d(TAG, "not indicate a Vend Request : ");
    }
}`

just now i have try your suggestion based on wiki that you share. The issue is whenever i put breakpoint, let say on the loop while read a messages it return completely but when i run without debug or get breakpoint the messages come out separately.

with debugging you change timing and therefore buffering behavior. Better use logcat output for analysis