Need some help with serial port on Android



  • Hello, everybody!

    I am writing application for Android on Qt. It must communicate with device which is connected to tablet's USB via FTDI usb-uart chip.

    Firstly i've tried to build QtSerialPort module using android qt toolchain and i've found that it doesn't work.
    Than i've tried to build QtSerialPort from here https://codereview.qt-project.org/#/c/84338/ and it looks like it doesn't work too. Here is a piece of java-code which used in QSerialPortInfo::availableDevices:

    @////////////////////////////////////////////////////////////////////////////////////////////////
    //
    // Constructor. Only used once to create the initial instance for the static functions.
    //
    ////////////////////////////////////////////////////////////////////////////////////////////////
    public UsbDeviceJNI()
    {
    m_instance = this;
    m_openedDevices = new HashMap<Integer, UsbSerialDriver>();
    m_userData = new HashMap<Integer, Integer>();
    m_ioManager = new HashMap<Integer, UsbIoManager>();
    }

    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    //  Find all current devices that match the device filter described in the androidmanifest.xml and the
    //  device_filter.xml
    //
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    private static boolean getCurrentDevices()
    {
        if (m_instance == null)
            return false;
        
    
        if (m_manager == null)
            m_manager = (UsbManager)m_instance.getSystemService(Context.USB_SERVICE);
    
        if (m_devices != null)
            m_devices.clear();
    
        m_devices = UsbSerialProber.findAllDevices(m_manager);
    
        return true;
    }
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    //  List all available devices that are not already open.  It returns the serial port info
    //  in a : separated string array.  Each string entry consists of the following:
    //
    //  DeviceName:Company:ProductId:VendorId
    //
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static String[] availableDevicesInfo()
    {
    
    
        //  GET THE LIST OF CURRENT DEVICES
        if (!getCurrentDevices())
            return null;
    
        //  MAKE SURE WE HAVE ENTRIES
        if (m_devices.size() <= 0)
            return null;
    
        if (m_openedDevices == null)
            return null;
    
        int countL = 0;
        int iL;
    
        //  CHECK FOR ALREADY OPENED DEVICES AND DON"T INCLUDE THEM IN THE COUNT
        for (iL=0; iL<m_devices.size(); iL++)
        {
            if (m_openedDevices.get(m_devices.get(iL).getDevice().getDeviceId()) != null)
            {
                countL++;
                break;
            }
        }
    
        if (m_devices.size() - countL <= 0)
            return null;
    
        String[] listL = new String[m_devices.size() - countL];
        UsbSerialDriver driverL;
        String tempL;
    
        //  GET THE DATA ON THE INDIVIDUAL DEVICES SKIPPING THE ONES THAT ARE ALREADY OPEN
        countL = 0;
        for (iL=0; iL<m_devices.size(); iL++)
        {
            driverL = m_devices.get(iL);
            if (m_openedDevices.get(driverL.getDevice().getDeviceId()) == null)
            {
                UsbDevice deviceL = driverL.getDevice();
                tempL = deviceL.getDeviceName() + ":";
    
                if (driverL instanceof FtdiSerialDriver)
                    tempL = tempL + "FTDI:";
                else if (driverL instanceof CdcAcmSerialDriver)
                    tempL = tempL + "Cdc Acm:";
                else if (driverL instanceof Cp2102SerialDriver)
                    tempL = tempL + "Cp2102:";
                else if (driverL instanceof ProlificSerialDriver)
                    tempL = tempL + "Prolific:";
                else
                    tempL = tempL + "Unknown:";
    
                tempL = tempL + Integer.toString(deviceL.getProductId()) + ":";
                tempL = tempL + Integer.toString(deviceL.getVendorId()) + ":";
                listL[countL] = tempL;
                countL++;
            }
        }
    
        return listL;
    }@
    

    UsbDeviceJNI::availableDevicesInfo method always returns null, and QSerialPortInfo::availableDevices is always empty. It happens because getCurrentDevices() calls from static method and m_instance is null. Actualy i have no idea of how to fix it.

    So maybe someone could help me?
    Or maybe there is another more simple way to implement data exchange between Android tablet and FTDI usb-uart chip?

    P.S. Sorry for my english.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.