The thing you will need to be mindful of when you read the data in a separate thread is to ensure that you correctly synchronize access to shared data.
Please do not point me to docs, the amount of time ive spend there i practically memorized all the pages.
How do i read when the data is received in the thread?
do i just receive all the time?
with a thread.sleep?
without a thread.sleep?
how do i know when all data is received?
when do i consume the data? upon when DataReceived is fired?
i need some sample code how to receive full data (not in chunks) so i can finally properly do with data what i want and add functionality to my app, and not invent low level boilerplate for UART
do not point me to docs, what i need is not in the docs, or samples, or drivers, or demo apps, ive looked at them all, thoroughly
Why would it be?! UART is a stream of data. You may get one byte in the first read, 453 in the second and 28 in the third. You will never get the exact count of data in every read. What you need is a marker in the stream to tell you where each chunk starts and where it ends.
It is working according to documentation. You are the problem.
You are expecting the entire message to be received with one read. This is a false assumption. You have to receive the data from the UART and assemble each message. The number of reads or events necessary for each message is unknown. It can vary from one to the number of bytes in message.
Treat the data stream from a UART the same as a data stream from a TCP socket.
@Mike, yes i know how it functions, as we discussed earlier in the post, datareceived fires maximum 50 times at 20ms cycles, i know that. I just don’t know how to properly assemble the data
@Gus, of course its not the same byte array what would be the point if its the same?
I need it to come in like this:
AA-55-1A-01-00-00-00-00-00-32 - receive 1 -> process data
AA-55-1B-01-00-00-00-00-00-32 - receive 2 -> process data
AA-55-1C-01-00-00-00-00-00-32 - receive 3 -> process data
AA-55-1D-01-00-00-00-00-00-32 - receive 4 -> process data
AA-55-1E-01-00-00-00-00-00-32 - receive 5 -> process data
AA-55-1F-01-00-00-00-00-00-32 - receive 6 -> process data
AA-55-20-01-00-00-00-00-00-32 - receive N -> process data
the other data 00-00-00-00-00 also changes all the time, its just not shown here, what is constant is first byte AA