CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Retrieve data from a string via RS232 (PIC to PIC)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
khalis



Joined: 12 Feb 2009
Posts: 54

View user's profile Send private message

Retrieve data from a string via RS232 (PIC to PIC)
PostPosted: Wed Mar 25, 2009 11:05 pm     Reply with quote

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... Smile
n-squared



Joined: 03 Oct 2006
Posts: 99

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Mar 25, 2009 11:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 26, 2009 12:43 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 26, 2009 3:15 am     Reply with quote

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... Very Happy
khalis



Joined: 12 Feb 2009
Posts: 54

View user's profile Send private message

PostPosted: Wed Apr 01, 2009 8:55 pm     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Apr 02, 2009 1:00 am     Reply with quote

khalis,
Code:

int8 dest[20]

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group