whmeade10
Joined: 27 Jan 2004 Posts: 12
|
Parsing a never ending RS-232 input string. |
Posted: Fri Jan 20, 2006 1:24 pm |
|
|
I have a RS-232 string of data that I need to receive and then place it on a 4 x 20 LCD. The string of data is constantly being transmitted over and over.
Example:
Code: |
0DPC07
1TOTAL 3.15DC
2RATE 0.009C
3S- 0 T1- 3.159C
4 -3.25 MENU BE
0DPC07
1TOTAL 3.15DC
2RATE 0.009C
3S- 0 T1- 3.159C
4 -3.25 MENU BE
0DPC07
1TOTAL 3.15DC
2RATE 0.009C
3S- 0 T1- 3.159C
4 -3.25 MENU BE
|
What I need to take out of this and display is:
Code: |
TOTAL 3.15
RATE 0.009
S- 0 T1- 3.159
-3.25 MENU
|
I imagine that I would look for a constant that is always transmitted like TOTAL, RATE or MENU then start putting the string in a buffer and break it into 4 different strings to be sent to the LCD.
I have been searching the forum for about an hour or so and haven't found how to search for a word in a string.
If I use INT_rda, will it alwasy stay active since the string is constantly being sent? I will only need to update the LCD about every second or so. So I guess I would receive a string, turn off the interrupt, process the string, send it to the LCD, and then turn it back on again.
If any of this makes sense to you, please point me in the right direction.
I actually have this working in PBP (basic, very limited) but we have switched to PICC and I have to learn and convert.
Many thanks in advance..... |
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jan 20, 2006 3:56 pm |
|
|
There are lots of ways to do this. This has been talk Ad nauseam.
http://en.wikipedia.org/wiki/Argumentum_ad_nauseam
I would look for 'MENU' over and over again.
Code: | xxxxxxMENUxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMENUxxxxx
___________________________________________
|
pull out that data and sub_process on that string.
Normally the RX_BUF will have a IN and a OUT pointer.
IN is where the next RX byte is stored. OUT is moved when you have processed the data.
make a RX_BUF[256] and a int8 IN,OUT;
1. at the start look for menu. point OUT there. this is a starting point for the state machine.
2.now from that OUT position look for another MENU.
3.copy data from OUT position up to (and including) the MENU position
4.change OUT to that spot.
goto 2.
With the string you copied you then are looking for all other items.
btw CCS has all/most of the standard string functions. ie strcmp |
|