private void stepWrite() throws IOException, InterruptedException {
        // Handle outgoing data.
        byte[] buffer = null;
        synchronized (mWriteBufferLock) {
            int len = mWriteBuffer.position();
            if (len > 0) {
                buffer = new byte[len];
                mWriteBuffer.rewind();
                mWriteBuffer.get(buffer, 0, len);
                mWriteBuffer.clear();
                mWriteBufferLock.notifyAll(); // Notify writeAsync that there is space in the buffer
            } else {
                mWriteBufferLock.wait();
            }
        }
        if (buffer != null) {
            if (DEBUG) {
                Log.d(TAG, "Writing data len=" + buffer.length);
            }
            mSerialPort.write(buffer, mWriteTimeout);
        }
    }
Continuously services the write buffers until {@link #stop()} is called, or until a driver exception is
raised.
usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/util/SerialInputOutputManager.java