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

how to extract serial data

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



Joined: 01 Jun 2016
Posts: 4

View user's profile Send private message

how to extract serial data
PostPosted: Wed Jun 01, 2016 11:09 pm     Reply with quote

how to extract serial data
$ Temp:37.88;PH:2.16;DO:10.88;CO:12.45 %
i need to extract the value and store the value like
p1=37.88
p2=2.16
p3=10.88
p4=12.45

Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Jun 01, 2016 11:27 pm     Reply with quote

Assuming you have this as a string.
Search for ':' (use strchr). Then use atof, to read the number at this location.
Then look forward for the next ':', and use atof again for the next number. etc. etc..

Have a look in the code library, where there is example code for reading values from a GPS, which uses similar techniques.
nithinkrishnanrs



Joined: 01 Jun 2016
Posts: 4

View user's profile Send private message

PostPosted: Wed Jun 01, 2016 11:37 pm     Reply with quote

thank you for your valuable information.
nithinkrishnanrs



Joined: 01 Jun 2016
Posts: 4

View user's profile Send private message

code
PostPosted: Thu Jun 02, 2016 1:11 am     Reply with quote

can you show an example
nithinkrishnanrs



Joined: 01 Jun 2016
Posts: 4

View user's profile Send private message

working code
PostPosted: Thu Jun 02, 2016 11:13 pm     Reply with quote

Code:
void str1()
{

strcpy(string,"$ Temp:37.88;PH:2.16;DO:10.88;CO:12.45; %");
//strcpy(string,"one,two,three;");

strcpy(term,":;");

i=0;

ptr = strtok(string, term);

while(ptr!=0) {
if (i==1)
{
   puts(ptr);
}

if (i==3)
{
   puts(ptr);
}

if (i==5)
{
   puts(ptr);
}

if (i==7)
{
  puts(ptr);
}

ptr = strtok(0, term);
i++;
}

prints
>> 37.88
>>2.16
>>10.88
>>12.45
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