Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Qserialport in QT 5.3 running in Android !!!!

[SOLVED] Qserialport in QT 5.3 running in Android !!!!

Scheduled Pinned Locked Moved Mobile and Embedded
25 Posts 3 Posters 22.4k 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.
  • K Offline
    K Offline
    kuzulis
    Qt Champions 2020
    wrote on last edited by
    #2

    During opening of QtSerialPort tries to create lock-files in directories /var/lock, /etc/locks... /data/local/tmp.

    On linux, some of these directories have the rights for writing from the usual user... so, no problem. But on Android, seems that these directories available only for root user, so, probably this is a problem for your application.

    You can comment out lines in the qserialport_unix.cpp file, responsible for lock-file, to disable it creation. See:

    @
    bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
    {
    ...
    }
    @

    But I am not sure that it will help because anyway for port opening (for a call of ::open (...) syscall) be required the rights of the superuser.

    So, your Android should be rooted, and your application should be running from superuser.. Thus, the current support of Android is the partial and the experimental.

    But you can try to other decision, based on java wrappers, which do not required a superuser rights:

    https://codereview.qt-project.org/83480
    https://codereview.qt-project.org/84338

    this still has an "progress" status and I not sure that it will be completed.. Because our team have no active and sensible Android developers. :)

    1 Reply Last reply
    0
    • P Offline
      P Offline
      projetoslinux
      wrote on last edited by
      #3

      Hi kuzulis !!!
      thanks i'm testing..

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mr_wallyit
        wrote on last edited by
        #4

        Hello,

        i have a Pos (point of sale ) with Android. I have checked the file system with adb shell with access superuser

        /var/lock not exits
        /etc/locks The etc folder is mounted only read
        /var/spool/locks not exist
        /var/spool/uucp not exist
        /tmp not exist
        /data/local/tmp not exist

        I have rebuilded the driver with a little change so the serial port work.

        #ifdef Q_OS_ANDROID

            << QStringLiteral("/data/lock")
            << QStringLiteral("/data/locks")
            << QStringLiteral("/data/spool/locks")
            << QStringLiteral("/data/spool/uucp")
            << QStringLiteral("/data/tmp")
            << QStringLiteral("/data/local/tmp");
            qDebug() << __LINE__ << __FILE__;
        

        #else
        << QStringLiteral("/var/lock")
        << QStringLiteral("/etc/locks")
        << QStringLiteral("/var/spool/locks")
        << QStringLiteral("/var/spool/uucp")
        << QStringLiteral("/tmp")
        #endif

        With access superuser i can create the folder "var", so have changed the the directory

        the structures was Originally :

        #ifdef Q_OS_ANDROID

            << QStringLiteral("/data/local/tmp");
        

        #else
        << QStringLiteral("/var/lock")
        << QStringLiteral("/etc/locks")
        << QStringLiteral("/var/spool/locks")
        << QStringLiteral("/var/spool/uucp")
        << QStringLiteral("/tmp")
        #endif

        What do you think?
        See you later

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

          mr_wallyit,

          please add your suggestion/bug to the Qt bug-report (by selecting of the SerialPort component).

          If this directories:

          [code]
          << QStringLiteral(”/data/lock”)
          << QStringLiteral(”/data/locks”)
          << QStringLiteral(”/data/spool/locks”)
          << QStringLiteral(”/data/spool/uucp”)
          << QStringLiteral(”/data/tmp”)
          [/code]

          are exists in really on your Android device, then I think that it is a good idea to add it into Q_OS_ANDROID, seems.

          But in any case please to create an appropriate bug in bug-tracker.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mr_wallyit
            wrote on last edited by
            #6

            Hello,

            this are the directory for default.
            << QStringLiteral("/var/lock")
            << QStringLiteral("/etc/locks")
            << QStringLiteral("/var/spool/locks")
            << QStringLiteral("/var/spool/uucp")
            << QStringLiteral("/tmp");

            The file system of Android is not standard, we can't write or create /var/, /tmp o write the folder looks in "/etc/locks.

            In the folder /data/ we can write because is the folder where we install the apps. In the the last build 5.3.0 of qserialport i see :
            #ifdef Q_OS_ANDROID
            << QStringLiteral("/data/local/tmp");
            #else

            So, i have tried to move the directory under /data/.
            But this it is big workaround because I have create manually the folders.
            Tomorrow i write the ticket

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

              Hmm.. then maybe Android has something other directory to contain an temporary files? This directory(es) are present on Android? Do you know?

              Because I'm not an Android expert..

              Maybe we can just to use an /data directory directly, and to write a lock file there, that not to create additional directories manually.?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                projetoslinux
                wrote on last edited by
                #8

                Hi mr_wallyt

                do you have sucess to serial port???
                work for you, for me not,...
                if possible send for my mail your code ???

                thanks for this.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  projetoslinux
                  wrote on last edited by
                  #9

                  hi ,
                  to create this folders, second mr_wallyt
                  //in host with usb cable
                  adb shell
                  cd ..
                  cd ..
                  su
                  #mount -o remount,rw /
                  #mkdir -p /var/lock
                  #mkdir -p /var/spool/locks
                  #mkdir -p /var/spool/uucp
                  #mkdir -p /tmp
                  #mkdir -p /data/local/tmp
                  #mount -o remount,rw /system
                  #mkdir -p /etc/locks

                  i have sucess to create folders in android, but not testing serial port...

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mr_wallyit
                    wrote on last edited by
                    #10

                    Hello,

                    I have created the folder on /data because the user "system " can read and write.
                    Sorry but i can't know how upload an image of file system. When driver send byte on the serial port use the folder how semaphore. Have you checked the permission?

                    This is a tentative to create the folder automatically in startup. It work correctly when i create the folder on /sdcard/ but don't work with /data/

                    @
                    QString program = "command";
                    QStringList arguments;
                    arguments << "mkdir"<< "/sdcard/test"

                    QProcess *myProcess = new QProcess;
                    myProcess->start(program, arguments);
                    myProcess->waitForFinished();;
                    @

                    I can send source code.
                    This code in my Android don't work.
                    #mount -o remount,rw /

                    @kuzulis
                    Maybe we can just to use an /data directory directly, and to write a lock file there, that not to create additional directories manually.?

                    We can try.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      projetoslinux
                      wrote on last edited by
                      #11

                      Hi mr_wallyt

                      thanks for send-me
                      I have sucess to compile and install your qserialport
                      for armv7

                      i compile and testing but not work
                      i write sudo chmod 777 for all folders and testing
                      $touch a /data/lock etc..
                      i have permission
                      and when running
                      have this message

                      Starting remote process.E/SELinux (21549): Function: selinux_android_load_priority [0], There is no sepolicy file
                      E/SELinux (21549):
                      E/SELinux (21549): Function: selinux_android_load_priority , loading version is VE=SEPF_SM-N900_4.3_F023
                      E/SELinux (21549):
                      E/SELinux (21549):
                      E/SELinux (21549): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts

                      D/OpenGLRenderer(21549): Enabling debug mode 0
                      W/Qt (21549): qtudev_p.h:114 (bool resolveSymbols(QLibrary*)): Failed to load the library: udev, supported version(s): 1 and 0
                      D/mali_winsys(21549): new_window_surface returns 0x3000
                      W/Qt (21549): kernel/qplatformwindow.cpp:380 (virtual bool QPlatformWindow::setKeyboardGrabEnabled(bool)): This plugin does not support grabbing the keyboard
                      D/Qt (21549): qserialport_unix.cpp:69 (QString serialPortLockFilePath(const QString&)): 69 qserialport_unix.cpp
                      D/Qt (21549): qserialport_unix.cpp:80 (QString serialPortLockFilePath(const QString&)): 80 qserialport_unix.cpp
                      W/Qt (21549): qserialport_unix.cpp:103 (QString serialPortLockFilePath(const QString&)): The following directories are not readable or writable for detaling with lock files
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/lock
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/locks
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/spool/locks
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/spool/uucp
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/tmp
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:105 (QString serialPortLockFilePath(const QString&)): /data/local/tmp
                      W/Qt (21549):
                      W/Qt (21549): qserialport_unix.cpp:206 (bool QSerialPortPrivate::open(QIODevice::OpenMode)): Failed to create a lock file for opening the device

                      when i connect terminal...

                      return for me a android message permission danied OK

                      testing to connect ttyGS... ttyS.. ttySAC..
                      and use terminal serial port code of tq 5.3

                      if possible send for dropbox your complete code to test ???

                      message failed to load lib UDEV error, do you have this message ??

                      you add permissions in android manifest ???

                      your /dev/device use is ttyGS0 ?

                      my phone is note3 rooted !!! i have permissions for sudo !!

                      Sorry for all questions and thanks for this.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mr_wallyit
                        wrote on last edited by
                        #12

                        Hello,

                        i thinks that we are the user "system" when the app run. I don't like create the folder manual, so i have thinks to use the path /sdcard/.

                        Please check the directory with ls -l
                        @
                        QDir dl("/sdcard/Android/data/lock") ;
                        if (!dl.exists()){
                        dl.mkpath(dl.absolutePath());
                        qDebug() << LINE << FUNCTION<< dl.absolutePath();
                        }
                        @

                        If we can create the folder, the driver run correctly. If this work, i can rebuild the driver serial port with this path and add the check on directory.

                        Second:
                        Download this app, and try if you can open the serial port correctly.

                        https://code.google.com/p/android-serialport-api/downloads/list

                        My port is different because i use a Point of sales.

                        Third
                        W/Qt (21549): qtudev_p.h:114 (bool resolveSymbols(QLibrary*)): Failed to load the library: udev, supported version(s): 1 and 0
                        I have this warning but work.

                        The app "terminal" work and i have changed nothing.

                        In the Android manifest i have added this permission:
                        android.permission.WRITE_EXTERNAL_STORAGE

                        Do you have downloaded this code ?
                        https://codereview.qt-project.org/83480

                        I tried but the git don't download the class java

                        @
                        git clone https://codereview.qt-project.org/p/qt/qtserialport refs/changes/80/83480/4 && git checkout FETCH_HEAD
                        @

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

                          2 mr_wallyit,

                          [quote]
                          W/Qt (21549): qtudev_p.h:114 (bool resolveSymbols(QLibrary*)): Failed to load the library: udev, supported version(s): 1 and 0
                          [/quote]

                          It is normal. The QtSerialPortInfo trying to use the udev library as main feature. In case the udev library is not present (e.g. can not to resolve it), then do fallback to the SysFs usage. In case the SysFs is not present (e.g. has no rights to read of the /sys/class/tty directory, or when no such this directory when the SysFs is disabled in Linux kernel), then do fallback to the enumeration of devices in /dev directory.

                          Usually, the Android has no udev, so all ok.

                          [quote]
                          Do you have downloaded this code ?
                          https://codereview.qt-project.org/83480
                          [/quote]

                          This code works only with the USB/Serial devices, so, no any ttyGS… ttyS.. ttySAC.., unfortunately. Has been used the directly I/O with the USB interface (read/write from the USB endpoints and so on), by analogy with the "libusb" on Linux. So, this solution it is an workaround, and can not be go to main QtSerialPort trunk.

                          This code also has a continuation in here: https://codereview.qt-project.org/#change,84338

                          Please read there are comments, maybe you will have other ideas how to re-implement it..

                          You can download this code like:

                          @
                          git clone git://gitorious.org/qt/qtserialport.git
                          cd qtserialport
                          git fetch https://codereview.qt-project.org/p/qt/qtserialport refs/changes/38/84338/2 && git checkout FETCH_HEAD
                          @

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            projetoslinux
                            wrote on last edited by
                            #14

                            Hi
                            thank you for all
                            thank you mr_wallit and kuzulis

                            i have partial sucess !!

                            testing with terminal example in qt3.0 to recieve serial data in usb

                            for this i create in /sdcard/folders and change in source code and compile this directories in qserial_port_unix
                            its possible create this in execution mode !!

                            #ifdef Q_OS_ANDROID

                                << QStringLiteral("/sdcard/data/lock")
                                << QStringLiteral("/sdcard/data/locks")
                                << QStringLiteral("/sdcard/data/spool/locks")
                                << QStringLiteral("/sdcard/data/spool/uucp")
                                << QStringLiteral("/sdcard/data/tmp")
                                << QStringLiteral("/sdcard/data/local/tmp");
                                qDebug() << __LINE__ << __FILE__;
                            

                            #else

                            no more message not LOCK

                            but when i open serial port show message

                            error permission denied OK

                            in debug lines have

                            Debugging starts
                            E/SELinux (15962): Function: selinux_android_load_priority [0], There is no sepolicy file
                            E/SELinux (15962):
                            E/SELinux (15962): Function: selinux_android_load_priority , loading version is VE=SEPF_SM-N900_4.3_F023
                            E/SELinux (15962):
                            E/SELinux (15962):
                            E/SELinux (15962): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
                            D/dalvikvm(15962): Late-enabling CheckJNI
                            D/dalvikvm(15962): GC_FOR_ALLOC freed 187K, 19% free 15034K/18436K, paused 14ms, total 14ms
                            I/dalvikvm-heap(15962): Grow heap (frag case) to 20.069MB for 2359312-byte allocation
                            D/dalvikvm(15962): GC_FOR_ALLOC freed <1K, 17% free 17338K/20744K, paused 18ms, total 18ms
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/lib/libgnustl_shared.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/lib/libgnustl_shared.so 0x42969fa0
                            D/dalvikvm(15962): No JNI_OnLoad found in /data/data/org.qtproject.example.serialMaster/lib/libgnustl_shared.so 0x42969fa0, skipping init
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Core.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Core.so 0x42969fa0
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Gui.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Gui.so 0x42969fa0
                            D/dalvikvm(15962): No JNI_OnLoad found in /data/data/org.qtproject.example.serialMaster/lib/libQt5Gui.so 0x42969fa0, skipping init
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Widgets.so 0x42969fa0
                            D/dalvikvm(15962): GC_CONCURRENT freed 11K, 17% free 17336K/20744K, paused 5ms+9ms, total 31ms
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/lib/libQt5Widgets.so 0x42969fa0
                            D/dalvikvm(15962): No JNI_OnLoad found in /data/data/org.qtproject.example.serialMaster/lib/libQt5Widgets.so 0x42969fa0, skipping init
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/lib/libQt5SerialPort.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/lib/libQt5SerialPort.so 0x42969fa0
                            D/dalvikvm(15962): No JNI_OnLoad found in /data/data/org.qtproject.example.serialMaster/lib/libQt5SerialPort.so 0x42969fa0, skipping init
                            D/dalvikvm(15962): Trying to load lib /data/data/org.qtproject.example.serialMaster/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/data/org.qtproject.example.serialMaster/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x42969fa0
                            I/Qt (15962): qt start
                            D/dalvikvm(15962): Trying to load lib /data/app-lib/org.qtproject.example.serialMaster-1/libserialMaster.so 0x42969fa0
                            D/dalvikvm(15962): Added shared lib /data/app-lib/org.qtproject.example.serialMaster-1/libserialMaster.so 0x42969fa0
                            D/dalvikvm(15962): No JNI_OnLoad found in /data/app-lib/org.qtproject.example.serialMaster-1/libserialMaster.so 0x42969fa0, skipping init

                            1- No JNI_OnLoad found in
                            its normal ???

                            2-my phone is rooted and add manifest.xml to write sdcard.
                            how to execute in sudo ?

                            3- other git examples not work for me !!!

                            thanks..for this

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              projetoslinux
                              wrote on last edited by
                              #15

                              3- other git examples not work for me !!!

                              change permission in host machine
                              sudo chmod 777 -R /libs/armeabi-v7a/

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mr_wallyit
                                wrote on last edited by
                                #16

                                Hello,
                                " JNI_OnLoad found" i see the warning in the my project.
                                If you receive the bytes you can open the serial port,
                                Are you sure, that are you sending the commands correctly?
                                Because all device have the specific syntax, i thinks that if you can receive you can send

                                I don't know how you we open the app with permission "sudo", but i have found how open by shell.

                                @
                                adb shell am start -n org.qtproject.example/org.qtproject.qt5.android.bindings.QtActivity

                                @

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  projetoslinux
                                  wrote on last edited by
                                  #17

                                  ok thanks
                                  mr_wallyit

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

                                    In addition, seems, there are "way":https://groups.google.com/forum/#!topic/pico-sam9g45/dNt1FJCX6ik to open the serial port with the user permissions.

                                    Need to setup permissions to desired serial port, e.g. do it in "init.rc" file, e.g.:

                                    @chmod 0666 /dev/ttyS0@

                                    Of course, to changing of this file required the root rights, unfortunately. But it can be done once for all non-USB serial ports "integrated" on Your device and do no worry in future.

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mr_wallyit
                                      wrote on last edited by
                                      #19

                                      Hi kuzulis,

                                      good research.

                                      Thanks

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        projetoslinux
                                        wrote on last edited by
                                        #20

                                        After several weeks I found out why qtserialport not run on any android

                                        1 - Root is necessary
                                        2 - Android Kernell should be compiled with the option enabled serial port, as well as some needed to install libusb and having to recompile the source code Kernell!!

                                        Much work!!
                                        Anyone know another method??

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mr_wallyit
                                          wrote on last edited by
                                          #21

                                          Hello,

                                          I have tried qserialport on industrial pos (point of sales),so i thinks the kernel has enabled serial port and libusb, because i can use the serial port.

                                          In the Qt 5.3 we have bluetooth,
                                          Why Don't we use bluetooth?

                                          @
                                          http://www.brainboxes.com/product/bl-830/bluetooth-to-rs232-serial-adapter-1-port-female
                                          @

                                          I don't have tried, but i thinks that work because android uses protocol bluetooth with adapter than it convert the signal in rs232.

                                          What do you thinks?

                                          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 Extensions
                                          • Unsolved