A
A
AlexSer2019-11-12 18:43:14
Qt
AlexSer, 2019-11-12 18:43:14

How to check that serial received a full data packet?

I wrote the code for receiving data through the computer port, everything works, the lines are read and inserted into the database.
But in order for everything to be correct, you need to check for the complete reception of the packet ... And I’m still 0 in this.
Can someone explain, or an example or articles ... it seems like you need to compare the number of bytes received, but I don’t understand this well

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zolg, 2019-11-12
@AlexSer

the serial port does not transmit packets. the serial port transmits a stream of bytes (actually a bit, but the reception of whole bytes is already implemented before you by the lower levels of abstraction)
'packetization' is the task of a higher level protocol (which you probably need to implement).
if your 'package' is a string, then the end of the package is marked with a newline character, isn't it ?

I
ittakir, 2019-11-12
@ittakir

The answer depends on who sends you data to the COM port, in what format.
For good, you need to somehow mark the end of the data packet. This is either to transfer the amount of data first, then the data itself. Or send a special end-of-packet character, such as "\n\n". Or simply by timeout, when the data flows in a continuous stream, and if there was no data for more than 1 second, then we consider that the packet is completed.
Most likely, the last option will suit you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question