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. [SOLVED] Receiving data from serialport in fragments
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Receiving data from serialport in fragments

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.7k 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.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    Hi!

    I use QSerialPort to communicate with a hardware via serial connection. I'm sending datapackets in a format like this:

    @DataPac = STX + Command + DataLength + Data + EOT@

    For example:
    @DataPac = 02 60 2 20 00 04@

    After i send the message i get an answer. The answer-packet looks similar to the send datapacket but with different data. This answer is not a complete answer and is interrupted in 2 or more times received-event. This means i get one packet in 2 or 3 or 4 pieces (2,3 or 4 receive-events). But it should be in one message and in one receive-event. Any ideas on how to get one packet? My current solution is to append the received bytes to a QByteArray and clear it after i send a new packet.

    Thank you very much!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      Buffering the received data in your readyRead() handler until you have a complete message is the way to get a whole message. If a received packet completes a message then remove the message from the buffer and process it (leaving any excess bytes in the buffer).

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

        Hi!

        Thank you ChrisW67. I found it, too...there's no other solution. I have to check for STX and EOT to figure out if my packet is complete. I wrote this to another thread: "Thread":http://qt-project.org/forums/viewthread/39778/#167029

        I will mark this as SOLVED.

        Thanks for your time :-)

        1 Reply Last reply
        0
        • jensen82J Offline
          jensen82J Offline
          jensen82
          wrote on last edited by
          #4

          Solved in "This Thread":http://qt-project.org/forums/viewthread/39778/#167029

          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