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

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 19 Dec 2015, 16:34 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 19 Dec 2015, 16:42 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 19 Dec 2015, 16:51 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 19 Dec 2015, 17:34
        1
        • M michelson
          19 Dec 2015, 16:51

          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 19 Dec 2015, 17:34 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?

          M 1 Reply Last reply 19 Dec 2015, 17:59
          0
          • W Wuzi
            19 Dec 2015, 17:34

            @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?

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 19 Dec 2015, 17:59 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 20 Dec 2015, 20:35
            0
            • M mrjj
              19 Dec 2015, 17:59

              @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 20 Dec 2015, 20:35 last edited by
              #6

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

              M 1 Reply Last reply 20 Dec 2015, 20:46
              0
              • W Wuzi
                20 Dec 2015, 20:35

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

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 20 Dec 2015, 20:46 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 20 Dec 2015, 21:23 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?

                  M 1 Reply Last reply 20 Dec 2015, 21:33
                  0
                  • W Wuzi
                    20 Dec 2015, 21:23

                    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?

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 20 Dec 2015, 21:33 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

                    2/9

                    19 Dec 2015, 16:42

                    7 unread
                    • Login

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