Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. qextserial port in qt5.7.0
Forum Updated to NodeBB v4.3 + New Features

qextserial port in qt5.7.0

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
16 Posts 4 Posters 2.7k Views 2 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.
  • V vivekyuvan

    Hi@SGaist I have a problem while installing the qtserial port library here i pasted the error message

    nu/qt5/QtCore -I.moc -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o .obj/qserialport.o qserialport.cpp
    In file included from qserialport.cpp:47:0:
    qserialport_p.h:58:33: fatal error: private/qiodevice_p.h: No such file or directory
    compilation terminated.
    Makefile:402: recipe for target '.obj/qserialport.o' failed
    make[2]: *** [.obj/qserialport.o] Error 1
    make[2]: Leaving directory '/home/vivek/qtserialport/src/serialport'
    Makefile:42: recipe for target 'sub-serialport-make_first' failed
    make[1]: *** [sub-serialport-make_first] Error 2
    make[1]: Leaving directory '/home/vivek/qtserialport/src'
    Makefile:44: recipe for target 'sub-src-make_first' failed
    make: *** [sub-src-make_first] Error 2
    vivek@vivek-Veriton-Series:~/qtserialport$ 
    
    
    
    [0_1532751720829_gg](Uploading 100%)
    aha_1980A Offline
    aha_1980A Offline
    aha_1980
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Hi @vivekyuvan,

    why do you need to build QtSerialPort yourself? It is already included in Qt since 5.1.

    How did you install Qt 5.7? With the package manager or with the online installer?

    BTW: You should better use Qt 5.9 LTS or 5.11 for new development.

    Regards

    Qt has to stay free or it will die.

    1 Reply Last reply
    1
    • V Offline
      V Offline
      vivekyuvan
      wrote on last edited by vivekyuvan
      #7

      hi@aha_1980 Yes indeed qtserial is already exists in qt5

      But here I face an issue while calling the QSerial Header files with QT Creator Editor . My QT creator Doesn't includes the QSerial Header files

      so that's why I did install qtserial port library manually. but now i got the header files in qt creator Editor with installing this command in terminal
      $ sudo apt-get install libqt5serialport5-dev

      is that ok correct me if i am wrong

      Thanks & Regards
      vivekyuvan

      aha_1980A 1 Reply Last reply
      0
      • V vivekyuvan

        hi@aha_1980 Yes indeed qtserial is already exists in qt5

        But here I face an issue while calling the QSerial Header files with QT Creator Editor . My QT creator Doesn't includes the QSerial Header files

        so that's why I did install qtserial port library manually. but now i got the header files in qt creator Editor with installing this command in terminal
        $ sudo apt-get install libqt5serialport5-dev

        is that ok correct me if i am wrong

        Thanks & Regards
        vivekyuvan

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #8

        @vivekyuvan

        $ sudo apt-get install libqt5serialport5-dev

        that looks good, and should work.

        Afterwards, you need to add QT += serialport in your .pro file, as stated in the documentation

        Qt has to stay free or it will die.

        V 1 Reply Last reply
        1
        • V Offline
          V Offline
          vivekyuvan
          wrote on last edited by
          #9

          @aha_1980 Thanks Now i am going to build my application hope it will build successfully.

          1 Reply Last reply
          1
          • aha_1980A aha_1980

            @vivekyuvan

            $ sudo apt-get install libqt5serialport5-dev

            that looks good, and should work.

            Afterwards, you need to add QT += serialport in your .pro file, as stated in the documentation

            V Offline
            V Offline
            vivekyuvan
            wrote on last edited by vivekyuvan
            #10

            @aha_1980 My code build and compiled successfully but my com port /dev/ttyUSB0 open was unsuccessful

            Here is code snippet

            void MainWindow::SerialPortInit()
            {
            
            
                DataAcquisitionPort = new QserialPort();
                DataAcquisitionPort->setPortName("/dev/ttyUSB0");
                DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
                DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl);                                     
                DataAcquisitionPort->setDataBits(QSerialPort::Data8);
                DataAcquisitionPort->setParity(QSerialPort::NoParity);
                DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
                qDebug() << "PORT Initialize completed";
            bool res = false;
                res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);  
                connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));         
                if(res)
               {
                    qDebug() << "TRYING TO OPEN PORT"
                }
                else
                {
                   qDebug("PROTOCOL PORT OPEN FAILED");
                }
            }
            

            this code cant open my port it always "protocol port open failed "

            Help me out to resolve this issue

            Thanks

            aha_1980A 1 Reply Last reply
            0
            • V vivekyuvan

              @aha_1980 My code build and compiled successfully but my com port /dev/ttyUSB0 open was unsuccessful

              Here is code snippet

              void MainWindow::SerialPortInit()
              {
              
              
                  DataAcquisitionPort = new QserialPort();
                  DataAcquisitionPort->setPortName("/dev/ttyUSB0");
                  DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
                  DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl);                                     
                  DataAcquisitionPort->setDataBits(QSerialPort::Data8);
                  DataAcquisitionPort->setParity(QSerialPort::NoParity);
                  DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
                  qDebug() << "PORT Initialize completed";
              bool res = false;
                  res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);  
                  connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));         
                  if(res)
                 {
                      qDebug() << "TRYING TO OPEN PORT"
                  }
                  else
                  {
                     qDebug("PROTOCOL PORT OPEN FAILED");
                  }
              }
              

              this code cant open my port it always "protocol port open failed "

              Help me out to resolve this issue

              Thanks

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #11

              @vivekyuvan said in qextserial port in qt5.7.0:

              Hi, your code looks good so far, however this line:

              bool res = false;
              res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);

              should be simplified to: bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);

              I think open fails because you don't have the needed access rights.

              Please send the output of ls -l /dev/ttyUSB0 to verify.

              Usually the solution is to add your username to the group dialout

              Regards.

              PS: It does not hurt to write "Please help me to solve this issue" ;)

              Qt has to stay free or it will die.

              1 Reply Last reply
              2
              • V Offline
                V Offline
                vivekyuvan
                wrote on last edited by vivekyuvan
                #12

                @aha_1980 I have changed the line as like your simplified line. and again i got same error

                vivek@vivek-Veriton-Series:~$ ls -l /dev/ttyUSB0
                crw-rw---- 1 root dialout 188, 0 Jul 28 13:25 /dev/ttyUSB0

                I have verified ttyUSB0 in terminal its looking fine

                and i didn't understand the line " Usually the solution is to add your username to the group dialout

                "

                can you please show me how to add username to group dialout ?

                aha_1980A 1 Reply Last reply
                0
                • V vivekyuvan

                  @aha_1980 I have changed the line as like your simplified line. and again i got same error

                  vivek@vivek-Veriton-Series:~$ ls -l /dev/ttyUSB0
                  crw-rw---- 1 root dialout 188, 0 Jul 28 13:25 /dev/ttyUSB0

                  I have verified ttyUSB0 in terminal its looking fine

                  and i didn't understand the line " Usually the solution is to add your username to the group dialout

                  "

                  can you please show me how to add username to group dialout ?

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  @vivekyuvan

                  Usually the solution is to add your username to the group dialout

                  In the terminal, input the following command:

                  sudo adduser vivek dialout

                  After that log out and in again or reboot the computer. Then it should work.

                  Regards

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  2
                  • V Offline
                    V Offline
                    vivekyuvan
                    wrote on last edited by vivekyuvan
                    #14

                    hi@aha_1980 thanks for reply. I have an another issue in my code that is " I can't get UART RAW data continuously " My code compiled successfully and when I run application it throws an error

                    ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
                    The program has unexpectedly finished.
                    

                    Serial port Initialize function

                    void MainWindow::SerialPortInit()
                    { 
                        DataAcquisitionPort = new QSerialPort();
                        DataAcquisitionPort->setPortName("/dev/ttyUSB0");
                        DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
                        DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl);                                     // To set the flow control to none
                        DataAcquisitionPort->setDataBits(QSerialPort::Data8);
                        DataAcquisitionPort->setParity(QSerialPort::NoParity);
                        DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
                        qDebug() << "PORT Initialize completed";
                       // bool res = false;
                       // res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);  // To open the DataAcquisitionPort
                         bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
                        connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));         
                        if(res)
                        {
                            qDebug() << "TRYING TO OPEN PORT";
                            const char data[] = "PROTOCOL PORT OPEN SUCCESS";
                            qDebug() << data;
                            DataAcquisitionPort->write(data, sizeof(data));
                            const char Protocol_init_data_1[] = { 0x80};
                            const char Protocol_init_data_2[] = { 0x04 };
                            const char Protocol_init_data_3[] = { 0x00 };
                            const char Protocol_init_data_4[] = { 0x80 };
                            const char Protocol_init_data_5[] = { 0x02 };
                            const char Protocol_init_data_6[] = { 0x00 };
                            DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
                           // Sleeper::msleep(100);
                            QThread::msleep(100);
                            DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
                           // Sleeper::msleep(100);
                            QThread::msleep(100);
                            DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
                            //Sleeper::msleep(100);
                            QThread::msleep(100);
                            DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
                            //Sleeper::msleep(100);
                            QThread::msleep(100);
                            DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
                            //Sleeper::msleep(100);
                            QThread::msleep(100);
                            DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
                            qDebug() << "PROTOCOL OPEN SUCCESS";
                        }
                        else
                        {
                           qDebug("PROTOCOL PORT OPEN FAILED");
                        }
                    }
                    

                    this function for protocol raw data frame

                    void MainWindow::Get_Data_from_Serial_port()
                    {
                        QByteArray Protocol_Raw_Data;
                        Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
                            qDebug() << Protocol_Raw_Data;
                        if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03")))  // To check for the Complete Frame
                        {
                            P1.append(Protocol_Raw_Data);
                            Protocol_Data_Organize(P1);
                            P1.clear();
                        }
                        else
                        {
                            P1.append(Protocol_Raw_Data);                       // If the frame is not completed, then append the data to Pi array
                        }
                    }
                    

                    And this function for split the raw data and separate the into single frame

                    void MainWindow::Protocol_Data_Organize(QByteArray Data)
                    {
                        QList <QByteArray> Data_Frame;
                        for(int pos = 0; pos < Data.size(); pos++)
                        {
                            if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
                            {
                                Data.insert((pos+1), ';');          // Inserting a Splitter between the individual data frames
                            }
                        }
                        Data_Frame << Data.split(';');              // Splits the Whole data frame into separate individual data frame and stores it in the List
                        Protocol_Data_split(Data_Frame);
                    }
                    

                    0_1532928899888_M1.png

                    In my previous version QT4.8.7 with qextserial library my application runs without issue but here i am facing this issue "The program has unexpectedly finished." and i cant get continuous UART Data . I don know what am missing please help me to resolve this issue

                    Thanks and Regard
                    vivekyuvan

                    aha_1980A 1 Reply Last reply
                    0
                    • V vivekyuvan

                      hi@aha_1980 thanks for reply. I have an another issue in my code that is " I can't get UART RAW data continuously " My code compiled successfully and when I run application it throws an error

                      ASSERT: "uint(i) < uint(size())" in file /usr/include/x86_64-linux-gnu/qt5/QtCore/qbytearray.h, line 464
                      The program has unexpectedly finished.
                      

                      Serial port Initialize function

                      void MainWindow::SerialPortInit()
                      { 
                          DataAcquisitionPort = new QSerialPort();
                          DataAcquisitionPort->setPortName("/dev/ttyUSB0");
                          DataAcquisitionPort->setBaudRate(QSerialPort::Baud115200);
                          DataAcquisitionPort->setFlowControl(QSerialPort::NoFlowControl);                                     // To set the flow control to none
                          DataAcquisitionPort->setDataBits(QSerialPort::Data8);
                          DataAcquisitionPort->setParity(QSerialPort::NoParity);
                          DataAcquisitionPort->setStopBits(QSerialPort::OneStop);
                          qDebug() << "PORT Initialize completed";
                         // bool res = false;
                         // res = DataAcquisitionPort->open(QIODevice::ReadWrite | QIODevice::Unbuffered | QIODevice::Append | QIODevice::Text);  // To open the DataAcquisitionPort
                           bool res = DataAcquisitionPort->open(QIODevice::ReadWrite);
                          connect(DataAcquisitionPort, SIGNAL(readyRead()), this, SLOT(Get_Data_from_Serial_port()));         
                          if(res)
                          {
                              qDebug() << "TRYING TO OPEN PORT";
                              const char data[] = "PROTOCOL PORT OPEN SUCCESS";
                              qDebug() << data;
                              DataAcquisitionPort->write(data, sizeof(data));
                              const char Protocol_init_data_1[] = { 0x80};
                              const char Protocol_init_data_2[] = { 0x04 };
                              const char Protocol_init_data_3[] = { 0x00 };
                              const char Protocol_init_data_4[] = { 0x80 };
                              const char Protocol_init_data_5[] = { 0x02 };
                              const char Protocol_init_data_6[] = { 0x00 };
                              DataAcquisitionPort->write(Protocol_init_data_1, sizeof(Protocol_init_data_1));
                             // Sleeper::msleep(100);
                              QThread::msleep(100);
                              DataAcquisitionPort->write(Protocol_init_data_2, sizeof(Protocol_init_data_2));
                             // Sleeper::msleep(100);
                              QThread::msleep(100);
                              DataAcquisitionPort->write(Protocol_init_data_3, sizeof(Protocol_init_data_3));
                              //Sleeper::msleep(100);
                              QThread::msleep(100);
                              DataAcquisitionPort->write(Protocol_init_data_4, sizeof(Protocol_init_data_4));
                              //Sleeper::msleep(100);
                              QThread::msleep(100);
                              DataAcquisitionPort->write(Protocol_init_data_5, sizeof(Protocol_init_data_5));
                              //Sleeper::msleep(100);
                              QThread::msleep(100);
                              DataAcquisitionPort->write(Protocol_init_data_6, sizeof(Protocol_init_data_6));
                              qDebug() << "PROTOCOL OPEN SUCCESS";
                          }
                          else
                          {
                             qDebug("PROTOCOL PORT OPEN FAILED");
                          }
                      }
                      

                      this function for protocol raw data frame

                      void MainWindow::Get_Data_from_Serial_port()
                      {
                          QByteArray Protocol_Raw_Data;
                          Protocol_Raw_Data = DataAcquisitionPort->readAll().toHex(); // Get the data and convert it to Hex fornat
                              qDebug() << Protocol_Raw_Data;
                          if((Protocol_Raw_Data.startsWith("02")) && (Protocol_Raw_Data.endsWith("03")))  // To check for the Complete Frame
                          {
                              P1.append(Protocol_Raw_Data);
                              Protocol_Data_Organize(P1);
                              P1.clear();
                          }
                          else
                          {
                              P1.append(Protocol_Raw_Data);                       // If the frame is not completed, then append the data to Pi array
                          }
                      }
                      

                      And this function for split the raw data and separate the into single frame

                      void MainWindow::Protocol_Data_Organize(QByteArray Data)
                      {
                          QList <QByteArray> Data_Frame;
                          for(int pos = 0; pos < Data.size(); pos++)
                          {
                              if( (Data.at(pos-1) == '0' && Data.at(pos) == '3' && Data.at(pos+1) == '0' && Data.at(pos+2) == '2') || ((Data.at(pos) == '3') && pos == (Data.size()-1)) )
                              {
                                  Data.insert((pos+1), ';');          // Inserting a Splitter between the individual data frames
                              }
                          }
                          Data_Frame << Data.split(';');              // Splits the Whole data frame into separate individual data frame and stores it in the List
                          Protocol_Data_split(Data_Frame);
                      }
                      

                      0_1532928899888_M1.png

                      In my previous version QT4.8.7 with qextserial library my application runs without issue but here i am facing this issue "The program has unexpectedly finished." and i cant get continuous UART Data . I don know what am missing please help me to resolve this issue

                      Thanks and Regard
                      vivekyuvan

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #15

                      Hi @vivekyuvan said in qextserial port in qt5.7.0:

                      "The program has unexpectedly finished."

                      A typical case for using the debugger. Start a debugging session, on the crash you get a stack trace. Then inspect the different functions in the stack trace until you find the guilty one.

                      if( (Data.at(pos-1) == '0'

                      This already looks like a candidate when pos == 0.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      2
                      • aha_1980A Offline
                        aha_1980A Offline
                        aha_1980
                        Lifetime Qt Champion
                        wrote on last edited by
                        #16

                        Another thing I noticed: You are using signals&slots together with sleeping functions.

                        That is wrong - stop doing it, you putting yourself into trouble.

                        Qt has to stay free or it will die.

                        1 Reply Last reply
                        2

                        • Login

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