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. Buffer and parse management for data from serial
Forum Updated to NodeBB v4.3 + New Features

Buffer and parse management for data from serial

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 715 Views 1 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.
  • K Offline
    K Offline
    KARMA
    wrote on 21 Dec 2021, 14:28 last edited by
    #1

    I am reading data from serial port in qt.
    1 package size is a minimum of 7 and a maximum of 16.
    And these incoming data can come not only as 1 packet, but also 2-3 packets on top of each other.
    so i decided to use buffer in my code.
    I'm reading all the data until the 512-byte buffer is full. then I find the package head in a for loop to parse this buffer and start the processes. but in the meantime, my software is getting stuck because the data is still coming in.

    What are your suggestions for such a problem?

    J 1 Reply Last reply 21 Dec 2021, 15:33
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 21 Dec 2021, 14:29 last edited by
      #2

      I don't think that parsing 512bytes take so long that it will stuck your application. Fix your parsing :)

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

      K 1 Reply Last reply 21 Dec 2021, 14:38
      0
      • C Christian Ehrlicher
        21 Dec 2021, 14:29

        I don't think that parsing 512bytes take so long that it will stuck your application. Fix your parsing :)

        K Offline
        K Offline
        KARMA
        wrote on 21 Dec 2021, 14:38 last edited by
        #3

        @Christian-Ehrlicher When the serial is ReadyRead, I take the data from the running function and transfer it to the buffer. Again when the buffer is full I parse the data in the same function. Is that why I'm in trouble?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrdebug
          wrote on 21 Dec 2021, 15:12 last edited by
          #4

          Hi, the buffer should be greater than a serial packet, depends on the protocol you are implementing. When something is come from the serial port you should search in you buffer if the byte that rapresent the end of the packet is come. It should be 0x03, \n, depend on your protocol. If you have, you can check you buffer to extract the packet.

          Need programmers to hire?
          www.labcsp.com
          www.denisgottardello.it
          GMT+1
          Skype: mrdebug

          1 Reply Last reply
          1
          • K KARMA
            21 Dec 2021, 14:28

            I am reading data from serial port in qt.
            1 package size is a minimum of 7 and a maximum of 16.
            And these incoming data can come not only as 1 packet, but also 2-3 packets on top of each other.
            so i decided to use buffer in my code.
            I'm reading all the data until the 512-byte buffer is full. then I find the package head in a for loop to parse this buffer and start the processes. but in the meantime, my software is getting stuck because the data is still coming in.

            What are your suggestions for such a problem?

            J Offline
            J Offline
            JonB
            wrote on 21 Dec 2021, 15:33 last edited by
            #5

            @KARMA
            Not sure why you have selected a 512-byte buffer, or indeed any particular limited size, since you can just e.g. allow a QByteArray to grow with append. Nothing should "get stuck" in any case.

            If you do your parsing --- and more particularly whatever you do with the result of the parsing --- from the readyRead signal's slot then your code would "get stuck" if your parsing gets stuck or what you do with it takes forever. readyReads should not "lose" data because you don't read that data fro a while. But you might pick up the next 7/16 bytes from the buffer and raise your own "complete packet received" signal which the outside world connects to.

            1 Reply Last reply
            2

            4/5

            21 Dec 2021, 15:12

            • Login

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