View previous topic :: View next topic |
Author |
Message |
khalis
Joined: 12 Feb 2009 Posts: 54
|
Retrieve data from a string via RS232 (PIC to PIC) |
Posted: Wed Mar 25, 2009 11:05 pm |
|
|
Hi,
I'm working with PIC18F252 and try to retrieve data from the same type of pic via RS232. During the testing, the second pic managed to retrieve the data transmitted from the first pic. And now, I'm lack of an idea to retrieve some characters from the data string and save to the pic memory. Let say the first send "TODAY IS HOT" and the second receives it and save "IS" into the memory. How am i going to do that?..I already read an example, ex_str.c but still blurr...
I hope someone can give me some ideas to start..
Thanks... |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Wed Mar 25, 2009 11:37 pm |
|
|
Hi,
Are you asking how to find the "IS" or how to extract it?
Finding it can be done using strstr() function.
Extracting it can be done one character at a time, in a loop, using char pointers.
Code: |
int8 source[] = { "TODAY IS HOT" };
int8 dest[20];
int8 *sp, *dp;
void extract(void)
{
sp = &source[6];
dp = dest;
while (*sp != ' ')
*dp++ = *sp++; // copy one char and advance pointers
*dp = 0; // terminate destination string
}
|
Good luck _________________ Every solution has a problem. |
|
|
sliders_alpha
Joined: 03 Mar 2008 Posts: 55
|
|
Posted: Thu Mar 26, 2009 12:43 am |
|
|
why using pointer (i'm not familiar with them)
can't you just use strncmp and one counter to look in it?
sommething like :
Code: |
counter = 0;
while( strncmp(scanner+counter, "IS", 2) != 0)
{
counter++
}
//here, counter = position of "IS"
|
note that i never used it like this, a long time ago i was doing that, i don't know why tho, the exemple above look like better :
Code: |
while( strncmp(scanner+0, "IS", 2) != 0)
{
slide the whole string 1 char to the left
}
//here, the start of the string is equal to "IS"
|
this one work for sure _________________ yup, i know, i don't speak english very well
CCS V4.057 |
|
|
khalis
Joined: 12 Feb 2009 Posts: 54
|
|
Posted: Thu Mar 26, 2009 3:15 am |
|
|
Thanks for your response especially n_squared and sliders_alpha..
After this, I'll try the hint you gave it to me and see the result... |
|
|
khalis
Joined: 12 Feb 2009 Posts: 54
|
|
Posted: Wed Apr 01, 2009 8:55 pm |
|
|
I'm just start to learn about the coding that you gave me before. There are several terms that I need to be sure first:
- the function of " * "
- the meaning of value inside the bracket ex [20]
Before this, I already read the other examples and they have some sort like symbol that I mentioned above.
Thanks |
|
|
n-squared
Joined: 03 Oct 2006 Posts: 99
|
|
Posted: Thu Apr 02, 2009 1:00 am |
|
|
khalis,
means array of 20 characters.
The * is a pointer.
I think that you need to read a little more about the basics of C language.
There are probably hundreds if not thousands of books on the subject.
The classic is the original by Kernighan and Ritchie. _________________ Every solution has a problem. |
|
|
|