Answer the question
In order to leave comments, you need to log in
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
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 ?
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 questionAsk a Question
731 491 924 answers to any question