Serial Recieve - String Buffer

Discuss PC Developer and Web Developer projects and features here.
Post Reply
jay_dee
Posts: 215
http://meble-kuchenne.info.pl
Joined: Sun Dec 20, 2020 6:06 pm
Has thanked: 81 times
Been thanked: 56 times

Serial Recieve - String Buffer

Post by jay_dee »

I'm still working on a good method to recieved lots of diagnostic strings from a PIC.
My diagnosic message strings are under 40 characters long, with start (~) and end (;) marker characters.
The PIC sends 30 diagnostic message strings as a block of strings every second. There is with about 1ms space between each messge in the block and its sent via Serial @ 115.200 kbit
I did try to recieved them as individual messages but when processing the first string, I loose the later messages.

So I'm thinking about reading in the whole string. 40char * 30 = 1300 characters. Which should be no issue for a PC.
Then split these into seperate messages by looking for the start and end characters.
Maybe run this as an interrupt? I thik it would take about 500ms to recieve all of the data at 115Kbit.

Could this data be saves to a String Buffer? if so, is this something I would need to construct?

Then other parts of the program would read the messages from the buffer and decode them, displaying the data in the various cosoles and graphs.
Any ideas on how to ahcieve this? or a better way to recieve lots of fairly fast data and then break it into usable chunks?
Thanks, j.

mnfisher
Valued Contributor
Posts: 1512
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 138 times
Been thanked: 725 times

Re: Serial Recieve - String Buffer

Post by mnfisher »

You should be able to declare a two dimensional array and receive to that.
If you are receiving on a PC you need to use a timer interrupt to repeatedly receive data and on a MCU use a Rx interrupt.

It depends slightly on the data - is it up to 40 characters per string(with a terminator) or is it always exactly 40 characters?

If you have an array

Data[30][40]

And a receive position row (and possibly column) then on a PC you can receive to data[row]. If the data is variable length then receive to data [row] [column] and increase row if a terminator is received.

You

Processing - you could use the array of data as a large circular buffer so new data is added over the oldest string.
What processing is needed. Do you need to process all the strings at once or individually?

Martin

Post Reply