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

Data being received sliced in two parts

rdelvillara opened this issue · comments

Hello guys,

I have an Android application that receives serial data from a physical device. To simulate the device we are using Docklight. For some unknown reason, the data being sent by Docklight is being received in two parts. First I received one byte, then the rest of the byte array, meaning the listener function onNewData is being called twice for every sequence sent from Docklight.

It is important to note that the Android app has previously been tested as we also use another cable with a different chipset, for that we use a different usb-serial library, and everything works fine.

This is the code we are using to configure the serial port.

    override fun startSerialConnection(device: UsbDevice, connection: UsbDeviceConnection) {
        val driver = usbDefaultProber.probeDevice(device)
        usbSerialPort = driver.ports[0]

        try{
            usbSerialPort!!.open(connection)
            usbSerialPort!!.setParameters(
                BaudRate.BPS19200.value,
                UsbSerialPort.DATABITS_7,
                UsbSerialPort.STOPBITS_1,
                UsbSerialPort.PARITY_EVEN
            )
            usbSerialPort!!.rts = false
            usbSerialPort!!.dtr = false

            usbIoManager = SerialInputOutputManager(usbSerialPort, this)
            usbIoManager!!.readTimeout = READ_WAIT_MILLIS
            usbIoManager!!.start()
        } catch (e: IOException){
            sendSignal(Constants.ACTION_USB_NOT_SUPPORTED)
        }

        
        USBSerial.serialPortConnected = true
        Log.d(TAG, "USB READY")
        sendSignal(Constants.ACTION_USB_READY)
    }

Am I missing anything?