Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerial Problems
QtWS25 Last Chance

QSerial Problems

Scheduled Pinned Locked Moved Unsolved General and Desktop
qserialserialreceiving messa
9 Posts 3 Posters 3.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.
  • W Offline
    W Offline
    Wuzi
    wrote on last edited by Wuzi
    #1

    Hello,

    I used QSerial to make a connection between a computer and a µC. The µC sends every time data. Then my routine is connected to readyRead(). So I get every byte. But the readyRead() function will called two times even I send only one Byte. So when I add the byte to a listwidget it adds me one time the char and an empty line. Why thats do that? The controller send also a '\0' char but for this I don't get a call of readyRead(). Does anyone know how I can do it right?

    Martin

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi if you do
      void MainWindow::handleReadyRead() {
      m_readData.append( m_serialPort->readAll() );
      then m_readData.size() == 2 even if u send one 1 char?

      (m_readData is bytearray)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        michelson
        wrote on last edited by
        #3

        I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)

        disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
        connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
        
        W 1 Reply Last reply
        1
        • M michelson

          I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)

          disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
          connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
          
          W Offline
          W Offline
          Wuzi
          wrote on last edited by
          #4

          @michelson said:

          I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)

          disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
          connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
          

          This cleared all empty lines out. But the '\0' will not handled why?

          mrjjM 1 Reply Last reply
          0
          • W Wuzi

            @michelson said:

            I would start with disconnecting readyRead with suitable slot and than connecting it again just to make sure you dont have double connection (which can couse function to be called twice)

            disconnect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
            connect(serial,SIGNAL(readyRead()), reciver , SLOT(on_readyRead()));
            

            This cleared all empty lines out. But the '\0' will not handled why?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Wuzi
            Are you sure you send it ?
            if you are using \0 as string on UC side it might not send anything.

            W 1 Reply Last reply
            0
            • mrjjM mrjj

              @Wuzi
              Are you sure you send it ?
              if you are using \0 as string on UC side it might not send anything.

              W Offline
              W Offline
              Wuzi
              wrote on last edited by
              #6

              Yes I'm sure because I see it on the logic analyzer

              mrjjM 1 Reply Last reply
              0
              • W Wuzi

                Yes I'm sure because I see it on the logic analyzer

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Wuzi
                Ok. on win 7. mingw
                I can send \0 and it will trigger readyRead()

                send:
                QByteArray t;
                t.append('\0');
                serial->write(t);
                read:
                mainWindow::handleReadyRead() {
                QByteArray buf = m_serialPort->readAll();
                 m_readData.append( buf);
                

                Strange it won't trigger in your case. What platform are you on?

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  Wuzi
                  wrote on last edited by
                  #8

                  I'm on Antergos (Arch based). I see that Qt creator does not show the \0 in a string is that right? And when I convert a string to QBytearray there is no extra byte for the '\0'. Why?

                  mrjjM 1 Reply Last reply
                  0
                  • W Wuzi

                    I'm on Antergos (Arch based). I see that Qt creator does not show the \0 in a string is that right? And when I convert a string to QBytearray there is no extra byte for the '\0'. Why?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Wuzi said:
                    QStrings do not use \0 as end of string marker , as far as i know
                    but will put one there when converted to std string etc.
                    QbyteArray can also include the \0
                    please see
                    http://doc.qt.io/qt-5/qbytearray.html#data

                    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