Qt Forum

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

    Forum Updated on Feb 6th

    Unsolved Read buffer QSerialPort

    General and Desktop
    3
    10
    2324
    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.
    • E
      erytcg last edited by erytcg

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • E
          erytcg last edited by

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

          mrjj 1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @erytcg last edited by

            @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 Reply Quote 0
            • E
              erytcg last edited by

              QByteArray data = serialPort->readAll();
                     QByteArray aaaa;
                     for (int i = 0; i <= 3 i++)
                     {
                         aaaa.append(data[i]);
                     }
              

              it's ok?

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @erytcg last edited by

                @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 Reply Quote 1
                • E
                  erytcg last edited by erytcg

                  Is there method to read QByteArray some byte?

                  mrjj 1 Reply Last reply Reply Quote 0
                  • mrjj
                    mrjj Lifetime Qt Champion @erytcg last edited by mrjj

                    @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 Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      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

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

                        @SGaist
                        Oh, how could it miss that :)

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