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. QSerialPort bytesAvailable() and read() delayed, QextSerialPort works

QSerialPort bytesAvailable() and read() delayed, QextSerialPort works

Scheduled Pinned Locked Moved Mobile and Embedded
21 Posts 7 Posters 15.4k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jack249
    wrote on last edited by
    #7

    my solution:
    call QCoreApplication::processEvents(); after write() then bytesAvailable() will be updated

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KeepGoing
      wrote on last edited by
      #8

      [quote author="mr_wallyit" date="1410691263"]Hello,

      Have you tried the simple project ("terminal") in Qt5?
      In Qt 5.3.1 we have ready serial port, I tried with Android, Windows XP, 7, 8 correctly.

      PS
      With Android I have done a workarround.[/quote]

      Hello mr_wallyit
      You said that you were able to use the Serial port with android in Qt5, could you please share with me, how this was done? I would appreciate your response. Thank you in advance.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KeepGoing
        wrote on last edited by
        #9

        [quote author="mr_wallyit" date="1410691263"]Hello,

        Have you tried the simple project ("terminal") in Qt5?
        In Qt 5.3.1 we have ready serial port, I tried with Android, Windows XP, 7, 8 correctly.

        PS
        With Android I have done a workarround.[/quote]

        Hello mr_wallyit
        You said that you were able to use the Serial port with android in Qt5, could you please share with me, how this was done? I would appreciate your response. Thank you in advance.

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

          Hello,
          First, serial Port on Android works if the Kernel is builded with this module.

          Second,file System of Android is not standard,there are not standard folders for the
          serial port, so I changed the driver with a few line of code.

          I changed the method serialPortLockFilePath in the fileqserialport_unix_p.cpp

          @

          QString serialPortLockFilePath(const QString &portName)
          {

          qDebug() << __LINE__ << __FILE__;
          static const QStringList lockDirectoryPaths = QStringList()
          

          //#ifdef Q_OS_ANDROID
          #ifdef ANDROID

              << QStringLiteral("/sdcard/data/lock")
              << QStringLiteral("/sdcard/data/locks")
              << QStringLiteral("/sdcard/data/spool/locks")
              << QStringLiteral("/sdcard/data/spool/uucp")
              << QStringLiteral("/sdcard/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");
              qDebug() << __LINE__ << __FILE__;
          

          #endif

          @

          Third,

          You need to create these directories:

            << QStringLiteral("/sdcard/data/lock")
              << QStringLiteral("/sdcard/data/locks")
              << QStringLiteral("/sdcard/data/spool/locks")
              << QStringLiteral("/sdcard/data/spool/uucp")
              << QStringLiteral("/sdcard/data/tmp")
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            mr_wallyit
            wrote on last edited by
            #11

            Hello,
            First, serial Port on Android works if the Kernel is builded with this module.

            Second,file System of Android is not standard,there are not standard folders for the
            serial port, so I changed the driver with a few line of code.

            I changed the method serialPortLockFilePath in the fileqserialport_unix_p.cpp

            @

            QString serialPortLockFilePath(const QString &portName)
            {

            qDebug() << __LINE__ << __FILE__;
            static const QStringList lockDirectoryPaths = QStringList()
            

            //#ifdef Q_OS_ANDROID
            #ifdef ANDROID

                << QStringLiteral("/sdcard/data/lock")
                << QStringLiteral("/sdcard/data/locks")
                << QStringLiteral("/sdcard/data/spool/locks")
                << QStringLiteral("/sdcard/data/spool/uucp")
                << QStringLiteral("/sdcard/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");
                qDebug() << __LINE__ << __FILE__;
            

            #endif

            @

            Third,

            You need to create these directories:

              << QStringLiteral("/sdcard/data/lock")
                << QStringLiteral("/sdcard/data/locks")
                << QStringLiteral("/sdcard/data/spool/locks")
                << QStringLiteral("/sdcard/data/spool/uucp")
                << QStringLiteral("/sdcard/data/tmp")
            
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mr_wallyit
              wrote on last edited by
              #12

              Sorry I have deleted a duplicate message

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

                Sorry I have deleted a duplicate message

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  KeepGoing
                  wrote on last edited by
                  #14

                  Hello Mr_Wallyit
                  Thank you for your reply.
                  My target is android. Is it the same with Android as well?

                  Thank you in advance.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    KeepGoing
                    wrote on last edited by
                    #15

                    Hello Mr_Wallyit
                    Thank you for your reply.
                    My target is android. Is it the same with Android as well?

                    Thank you in advance.

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

                      Hello,

                      yes of course, I use Point of sale Industrial with Android, with workarround we can use serial port.

                      Best Regards

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

                        Hello,

                        yes of course, I use Point of sale Industrial with Android, with workarround we can use serial port.

                        Best Regards

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Abin
                          wrote on last edited by
                          #18

                          Hi Mr_Wallyit,

                          Thanks for sharing the details.

                          I have an android device which has serial port attached to it. The manufacturer has a sample application with it which uses the serial port. The port name is "/dev/ttyS6".

                          As you mentioned I tried to create folder in my device. My device file explorer shows files structure as "/mnt/sdcard". So I created folders as below:
                          "/mnt/sdcard/data/lock"
                          "/mnt/sdcard/data/locks"
                          "/mnt/sdcard/data/spool/locks"
                          "/mnt/sdcard/data/spool/uucp"
                          "/mnt/sdcard/data/tmp"

                          But, the folder "/mnt/data/local/tmp" is unable to create as my file explorer doesn't allow to create folder.

                          I kept my code as @QString serialPortLockFilePath(const QString &portName)
                          {
                          static const QStringList lockDirectoryPaths = QStringList()

                          #ifdef Q_OS_ANDROID
                          << QStringLiteral("/mnt/sdcard/data/lock")
                          << QStringLiteral("/mnt/sdcard/data/locks")
                          << QStringLiteral("/mnt/sdcard/data/spool/locks")
                          << QStringLiteral("/mnt/sdcard/data/spool/uucp")
                          << QStringLiteral("/mnt/sdcard/data/tmp");
                          #else
                          << QStringLiteral("/var/lock")
                          << QStringLiteral("/etc/locks")
                          << QStringLiteral("/var/spool/locks")
                          << QStringLiteral("/var/spool/uucp")
                          << QStringLiteral("/tmp");
                          #endif@

                          And I have a second device whose files structure as "/sdcard". So I created folders as below:
                          "/sdcard/data/lock"
                          "/sdcard/data/locks"
                          "/sdcard/data/spool/locks"
                          "/sdcard/data/spool/uucp"
                          "/sdcard/data/tmp"

                          But, the folder "/data/local/tmp" is unable to create as my file explorer crashes on creating folder "/data/locaal" (need to retry with different file explorer application).

                          @QString serialPortLockFilePath(const QString &portName)
                          {
                          static const QStringList lockDirectoryPaths = QStringList()

                          #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");
                          #else
                          << QStringLiteral("/var/lock")
                          << QStringLiteral("/etc/locks")
                          << QStringLiteral("/var/spool/locks")
                          << QStringLiteral("/var/spool/uucp")
                          << QStringLiteral("/tmp");
                          #endif@

                          and created a sample application which tries to access the serial port. I set the port name as @setPortName("/dev/ttyS6");@
                          But when running the application I get the error "Permission denied".

                          Could you help me to figure out where I am going wrong.

                          Thanks in advance.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            Abin
                            wrote on last edited by
                            #19

                            Hi Mr_Wallyit,

                            Thanks for sharing the details.

                            I have an android device which has serial port attached to it. The manufacturer has a sample application with it which uses the serial port. The port name is "/dev/ttyS6".

                            As you mentioned I tried to create folder in my device. My device file explorer shows files structure as "/mnt/sdcard". So I created folders as below:
                            "/mnt/sdcard/data/lock"
                            "/mnt/sdcard/data/locks"
                            "/mnt/sdcard/data/spool/locks"
                            "/mnt/sdcard/data/spool/uucp"
                            "/mnt/sdcard/data/tmp"

                            But, the folder "/mnt/data/local/tmp" is unable to create as my file explorer doesn't allow to create folder.

                            I kept my code as @QString serialPortLockFilePath(const QString &portName)
                            {
                            static const QStringList lockDirectoryPaths = QStringList()

                            #ifdef Q_OS_ANDROID
                            << QStringLiteral("/mnt/sdcard/data/lock")
                            << QStringLiteral("/mnt/sdcard/data/locks")
                            << QStringLiteral("/mnt/sdcard/data/spool/locks")
                            << QStringLiteral("/mnt/sdcard/data/spool/uucp")
                            << QStringLiteral("/mnt/sdcard/data/tmp");
                            #else
                            << QStringLiteral("/var/lock")
                            << QStringLiteral("/etc/locks")
                            << QStringLiteral("/var/spool/locks")
                            << QStringLiteral("/var/spool/uucp")
                            << QStringLiteral("/tmp");
                            #endif@

                            And I have a second device whose files structure as "/sdcard". So I created folders as below:
                            "/sdcard/data/lock"
                            "/sdcard/data/locks"
                            "/sdcard/data/spool/locks"
                            "/sdcard/data/spool/uucp"
                            "/sdcard/data/tmp"

                            But, the folder "/data/local/tmp" is unable to create as my file explorer crashes on creating folder "/data/locaal" (need to retry with different file explorer application).

                            @QString serialPortLockFilePath(const QString &portName)
                            {
                            static const QStringList lockDirectoryPaths = QStringList()

                            #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");
                            #else
                            << QStringLiteral("/var/lock")
                            << QStringLiteral("/etc/locks")
                            << QStringLiteral("/var/spool/locks")
                            << QStringLiteral("/var/spool/uucp")
                            << QStringLiteral("/tmp");
                            #endif@

                            and created a sample application which tries to access the serial port. I set the port name as @setPortName("/dev/ttyS6");@
                            But when running the application I get the error "Permission denied".

                            Could you help me to figure out where I am going wrong.

                            Thanks in advance.

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

                              Hello,

                              this is my source code, I think who is wrong “/mnt/sdcard/data/lock”.

                              @

                              bool s = true;
                              QStringList pathList;
                              

                              #ifdef ANDROID
                              pathList << "/sdcard/data";
                              pathList << "/sdcard/data/lock";
                              pathList << "/sdcard/data/locks";
                              pathList << "/sdcard/data/spool";
                              pathList << "/sdcard/data/spool/locks";
                              pathList << "/sdcard/data/spool/uucp";
                              pathList << "/sdcard/data/tmp";
                              pathList << "/sdcard/data/local";
                              pathList << "/sdcard/data/local/tmp";
                              #endif

                              QDir d;
                              foreach (const QString s, pathList) {
                                  d.setPath(s);
                                  if (!d.exists()){
                                      if(d.mkpath(d.absolutePath()))
                                          qCCritical() << "error create directory " << d.absolutePath();
                                  }
                              }
                              

                              @

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

                                Hello,

                                this is my source code, I think who is wrong “/mnt/sdcard/data/lock”.

                                @

                                bool s = true;
                                QStringList pathList;
                                

                                #ifdef ANDROID
                                pathList << "/sdcard/data";
                                pathList << "/sdcard/data/lock";
                                pathList << "/sdcard/data/locks";
                                pathList << "/sdcard/data/spool";
                                pathList << "/sdcard/data/spool/locks";
                                pathList << "/sdcard/data/spool/uucp";
                                pathList << "/sdcard/data/tmp";
                                pathList << "/sdcard/data/local";
                                pathList << "/sdcard/data/local/tmp";
                                #endif

                                QDir d;
                                foreach (const QString s, pathList) {
                                    d.setPath(s);
                                    if (!d.exists()){
                                        if(d.mkpath(d.absolutePath()))
                                            qCCritical() << "error create directory " << d.absolutePath();
                                    }
                                }
                                

                                @

                                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