Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read buffer QSerialPort
Qt 6.12 LTS is out! See what's new in the release blog

Read buffer QSerialPort

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 4.5k 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.
  • E Offline
    E Offline
    erytcg
    wrote on last edited by erytcg
    #1

    Hello I have some questions.

    1. I want read buffer from device and send command every 1ms.
      Buffer it looks like this: AAAABBBBCCCCDDDDEEEEFFFFGGHHIIJJ
      I want read only A,B,C,F. How to get only specific bytes numbers.

    Shoud I check currect amount of bytes?
    And later save to:

    QByteArray data
    

    Access to A,B,C,F only with for loop and QByteArray.append?

    1. After some time I want save this data in Excel file, where keep large amounts of data?
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Will it be fixed amount of each ?
      like 4 AAAA, 4 BBBB up to f ?

      • After some time I want save this data in Excel file, where keep large amounts of data?
        What do you mean ? And excel sheet is not good for large amounts of data.
      1 Reply Last reply
      0
      • E Offline
        E Offline
        erytcg
        wrote on last edited by
        #3

        Yes always 4A , 4B etc.
        Maybe .csv file.

        mrjjM 1 Reply Last reply
        0
        • E erytcg

          Yes always 4A , 4B etc.
          Maybe .csv file.

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

          @erytcg
          well then you can just add to the read buffer
          when size is 4 x 5, you should have all data.
          Then you can process the buffer save save to file or what you need.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            erytcg
            wrote on last edited by
            #5
            QByteArray data = serialPort->readAll();
                   QByteArray aaaa;
                   for (int i = 0; i <= 3 i++)
                   {
                       aaaa.append(data[i]);
                   }
            

            it's ok?

            mrjjM 1 Reply Last reply
            0
            • E erytcg
              QByteArray data = serialPort->readAll();
                     QByteArray aaaa;
                     for (int i = 0; i <= 3 i++)
                     {
                         aaaa.append(data[i]);
                     }
              

              it's ok?

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

              @erytcg
              Nope, that would crash pretty fast if you receive less than 3 chars first read.

              QByteArray data; // move to member of class.

              then in read do
              data += serialPort->readAll(); // add them up. they might come in blocks.
              if (data.size() > 19 ) { // now we got at 20 minimum
              ... do what u need.
              data.clear(); // clear read buffer
              }

              1 Reply Last reply
              1
              • E Offline
                E Offline
                erytcg
                wrote on last edited by erytcg
                #7

                Is there method to read QByteArray some byte?

                mrjjM 1 Reply Last reply
                0
                • E erytcg

                  Is there method to read QByteArray some byte?

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

                  @erytcg
                  Not that i saw, but you can use
                  QString AString( data );
                  then use
                  http://doc.qt.io/qt-5/qstring.html#mid
                  to grab only a substring from it

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi,

                    No need to change classes: QByteArray::mid.

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

                    mrjjM 1 Reply Last reply
                    1
                    • SGaistS SGaist

                      Hi,

                      No need to change classes: QByteArray::mid.

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

                      @SGaist
                      Oh, how could it miss that :)

                      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
                      • Unsolved