|
|
View previous topic :: View next topic |
Author |
Message |
ferkar
Joined: 14 Jul 2007 Posts: 38
|
sending string and decoding |
Posted: Mon Jan 04, 2010 3:57 pm |
|
|
hi everyone,
I am sending serial data to PIC via rs232 port using Visual Basic.
The data is like this "f123k456h789".
I get these data to 18f452 by using gets().
How can I separate this data to:
f,123k,456,h,789
Then I am going to use it in PIC code.
thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ferkar
Joined: 14 Jul 2007 Posts: 38
|
|
Posted: Mon Jan 04, 2010 4:11 pm |
|
|
Thanks for help. However it is not the answer I want I think. I need to find a command or something like that is used for splitting the string and get the characters that I want. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 04, 2010 4:17 pm |
|
|
Sorry. I put in the wrong link. I have corrected it now. |
|
|
mbradley
Joined: 11 Jul 2009 Posts: 118 Location: California, USA
|
|
Posted: Tue Jan 05, 2010 12:12 am |
|
|
Just out of curiosity, why don't you send the data with the ',' commas in the string?
At that point, loop through all chrs, building a new string, and when you encounter "," process what you have thus far, then continue.
Or do you have a string when each field is separated by ',' and thus not data items? ie: 'username,phone,cell_phone' type of thing?
If the latter is the case, I usually make an array of strings, and parse the string into the array, such as GPS data, then I know which field has the data I want. _________________ Michael Bradley
www.mculabs.com
Open Drivers and Projects |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
Re: sending string and decoding |
Posted: Tue Jan 05, 2010 3:24 am |
|
|
ferkar wrote: | hi everyone,
I am sending serial data to PIC via rs232 port using Visual Basic.
The data is like this "f123k456h789".
I get these data to 18f452 by using gets().
How can I separate this data to:
f,123k,456,h,789
Then I am going to use it in PIC code.
thanks |
This can be very easy or quite complicated, it all depends.
Is each section a fixed length e.g 1 char, 4 chars, 3 chars, 1 char, 3 chars (numbers will have leading 0's 056) ?
Are the numbers to be translated into values (456, 789) ?
Does the k (123k) represent 1024 or 1000 and can there be an m, g ?
Can they be uppercase and do they mean the same thing. ?
The simple solution is to do something like
Code: |
char a, b[5], c[4], d, e[4]; // need space for the null terminating for the strings
char s[] = "f123k456h789";
a = s[0];
strncpy(b, s[1], 4; // Will put a null on the end
strncpy(c, s[5], 3);
d = s[8];
strncpy(e, s[9], 3);
|
|
|
|
|
|
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
|