Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Read Serial Data In QByteArray

    General and Desktop
    5
    6
    484
    Loading More Posts
    • 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.
    • M
      Marco Flad last edited by

      every Time Serial Triggered Receive This Message 000011110000111100001111& but i receive it Like that in debug alt text
      when i Do qDebug() << inBuffer ; out side of ReadyRead(); i got only Last byte "&"
      so how to got all Message in QByte array like that "000011110000111100001111&"
      My code :

      void Widget::updateReceivedData()
      {
          
         inBuffer = arduino->readAll();
         qDebug() << inBuffer ;
      
          //inBuffer = arduino->readLine();
      
          //QByteArray datalog(arduino->readAll());
      
         //QByteArray data ;
        // data.append(arduino->readAll());
       
        //while (arduino->waitForReadyRead(10))
        //inBuffer += arduino->readAll();
      
          }
      
      
      aha_1980 1 Reply Last reply Reply Quote 0
      • aha_1980
        aha_1980 Lifetime Qt Champion @Marco Flad last edited by

        @Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.

        So you have to append the new data to your existing buffer until all data is received.

        Regards

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 3
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          Are you receiving null chars in your message ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 2
          • V
            vikas dhumal last edited by

            use readyRead() SIGNAL at the time of serial->open(QIODevice::ReadWrite)
            connect(serial, SIGNAL(readyRead()),this,SLOT(readSerialData()),Qt::UniqueConnection);
            where serial is an object QSerialPort *serial;
            readSerialData() is user defined slot function make it in header file like
            private slots:
            void readSerialData();
            and finally in readSerialData() function
            static QString readResponseReply = "";
            readResponseReply.append(serial->readAll());
            qDebug()<<"readResponseReply";
            try it in your source code

            Christian Ehrlicher 1 Reply Last reply Reply Quote -1
            • Christian Ehrlicher
              Christian Ehrlicher Lifetime Qt Champion @vikas dhumal last edited by

              @vikas-dhumal Sorry but converting some binary data into a QString is completely wrong here. What @SGaist asked is correct - when there is a null byte in there, qDebug() will not print what you expect. Therefore I would use inBuffer.toHex() to output the data for debugging.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply Reply Quote 4
              • aha_1980
                aha_1980 Lifetime Qt Champion @Marco Flad last edited by

                @Marco-Flad your serial data arrives in chunks of one or several bytes, but seldom the whole answer in one block.

                So you have to append the new data to your existing buffer until all data is received.

                Regards

                Qt has to stay free or it will die.

                1 Reply Last reply Reply Quote 3
                • V
                  vikas dhumal last edited by

                  ok so instead of QString read it in QByteArray

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post