[SOLVED] Receiving data from serialport in fragments
-
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!
-
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).
-
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 :-)
-
Solved in "This Thread":http://qt-project.org/forums/viewthread/39778/#167029