Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. SerialCommunication on QtAndroid
Qt 6.11 is out! See what's new in the release blog

SerialCommunication on QtAndroid

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 2 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • carles.sole.grauC Offline
    carles.sole.grauC Offline
    carles.sole.grau
    wrote on last edited by
    #1

    Hello,
    I'm trying to exchange date between and Arduino board and a Qt App on an Android Device.
    Once my Arduino board is connected to my Smartphone with an OTG cable and running my app, using the QSerialPortInfo class I can get all the information about the port (vendorIdentifier, productiIdentifier....).
    The problem is that when I try to connect to the port using QSerialPort class (open()) is like Android has no permissions to access to the port:

            arduino->setPortName(portToOpen);       
            arduino->setBaudRate(QSerialPort::Baud9600);
            arduino->setDataBits(QSerialPort::Data8);
            arduino->setFlowControl(QSerialPort::NoFlowControl);
            arduino->setParity(QSerialPort::NoParity);
            arduino->setStopBits(QSerialPort::OneStop);        
            if(arduino->open(QIODevice::ReadWrite))
                setIsConnected(true);
            else
                qInfo() << arduino->errorString();
    

    When I check if the port is open, it always return an error message saying that the file is locked and the port is not opened:

     qInfo() << arduino->errorString();
    

    The error message is:

    Permission error while creating lock file
    

    So, what it can be done to solve this situation?
    Any help will be very appreciated,
    Thank you

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by kuzulis
      #2

      So, what it can be done to solve this situation?

      It is impossible if your smartphone is not rooted (as I know). You can try following (if you have a root access):

      • startup your application as root (but I don't know how to do it)

      or

      • write special "initialisation" file or script on your Android FS to change permissions of serial port (as I remember, there is possible to do something like this).

      UPD:

      Permission error while creating lock file

      Ah, seems, that "/data/local/tmp" directory has not read/write access for you. Maybe we need fix it to replace with QStandardPaths::writableLocation(QStandardPaths::TempLocation). You can try to replace it (or just comments out creation of a lock file) from source code and re-build library).

      Anyway, I suspect, that next error will be "permission error", related to the serial port itself (about I wrote before) :)

      carles.sole.grauC 1 Reply Last reply
      1
      • K kuzulis

        So, what it can be done to solve this situation?

        It is impossible if your smartphone is not rooted (as I know). You can try following (if you have a root access):

        • startup your application as root (but I don't know how to do it)

        or

        • write special "initialisation" file or script on your Android FS to change permissions of serial port (as I remember, there is possible to do something like this).

        UPD:

        Permission error while creating lock file

        Ah, seems, that "/data/local/tmp" directory has not read/write access for you. Maybe we need fix it to replace with QStandardPaths::writableLocation(QStandardPaths::TempLocation). You can try to replace it (or just comments out creation of a lock file) from source code and re-build library).

        Anyway, I suspect, that next error will be "permission error", related to the serial port itself (about I wrote before) :)

        carles.sole.grauC Offline
        carles.sole.grauC Offline
        carles.sole.grau
        wrote on last edited by carles.sole.grau
        #3

        @kuzulis
        Hi, first of all, thank you very much.
        Then, I don't understand exactly what I have to do:
        Maybe we need fix it to replace with QStandardPaths::writableLocation(QStandardPaths::TempLocation). You can try to replace it (or just comments out creation of a lock file) from source code and re-build library).
        I just add in my main file this code:

        int main(int argc, char *argv[])
        {
            QApplication a(argc, argv);
            QStandardPaths::writableLocation(QStandardPaths::TempLocation);
            MainWindow w;
            w.show();
            return a.exec();
        }
        

        But the same error is shown: Permission error while creating lock file

        On the debug console it also can be seen this info:

        W libterminal.so: (null):0 ((null)): The following directories are not readable or writable for detaling with lock files
        06-05 00:42:29.161 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/var/lock
        06-05 00:42:29.162 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/etc/locks
        06-05 00:42:29.162 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/var/spool/locks
        06-05 00:42:29.162 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/var/spool/uucp
        06-05 00:42:29.162 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/tmp
        06-05 00:42:29.162 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/var/tmp
        06-05 00:42:29.163 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/var/lock/lockdev
        06-05 00:42:29.163 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/run/lock
        06-05 00:42:29.163 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): 	/data/local/tmp
        06-05 00:42:29.163 17410 17437 W libterminal.so:
        W libterminal.so: (null):0 ((null)): Failed to create a lock file for opening the device
        

        Thank you very much.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kuzulis
          Qt Champions 2020
          wrote on last edited by kuzulis
          #4

          I just add in my main file this code:

          You should modify a source code of QtSerialPort module, rebuild and reinstall it. Please, take a look on this code. You should try to replace QStringLiteral("/data/local/tmp") with QStandardPaths::writableLocation(QStandardPaths::TempLocation) (or just to append QStandardPaths::writableLocation(QStandardPaths::TempLocation) after QStringLiteral("/data/local/tmp") ).

          carles.sole.grauC 1 Reply Last reply
          2
          • K kuzulis

            I just add in my main file this code:

            You should modify a source code of QtSerialPort module, rebuild and reinstall it. Please, take a look on this code. You should try to replace QStringLiteral("/data/local/tmp") with QStandardPaths::writableLocation(QStandardPaths::TempLocation) (or just to append QStandardPaths::writableLocation(QStandardPaths::TempLocation) after QStringLiteral("/data/local/tmp") ).

            carles.sole.grauC Offline
            carles.sole.grauC Offline
            carles.sole.grau
            wrote on last edited by
            #5

            @kuzulis
            Excuse me for my ignorance, but I don't know how to rebuild and reinstall the module. Once I try to build the module (but I don't know if I' doing it properly) this error appears:

            Cannot find application binary /home/carles/Qt/5.9/Src/build-qtserialport-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_0_for_Android_armv7-Release/tests/auto/qserialport/libtst_qserialport.so.
            23:05:21: The process "/home/carles/Qt/5.9/android_armv7/bin/androiddeployqt" exited with code 2.
            Error while building/deploying project qtserialport (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.9.0 for Android armv7))
            

            Thank you.

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kuzulis
              Qt Champions 2020
              wrote on last edited by
              #6

              https://wiki.qt.io/Qt_Serial_Port#Build_and_install_from_QtCreator

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt
              • Unsolved