obtain data from char string

Status
Not open for further replies.

gehan_s

Member level 3
Joined
Aug 31, 2012
Messages
62
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Sri Lanka
Activity points
1,799
Hi all,

I am sending data from a GUI (designed using C#) to a PIC microcontroller. Each data is separated by a "," and each data string is terminated by a "\n". This is how I am doing it.
Code:
send_s = "#DCMC#" + "," + kp + "," + ki + "," + kd + "," + v + "," + i + "," + t + "," + s + "," + "\n";

if (!serialPort1.IsOpen)
return;

buff = send_s.ToCharArray();
serialPort1.Write(buff, 0, buff.Length);

The values kp, ki, kd, v, i, t, s are integers converted into characters. The phrase #DCMC# acts as an identifier so if the incoming string starts with "#DCMC#" then accept the string.

How do I obtain the integer data from this string? (I am using mikroC PRO for PIC)

Regards
 

Are kp, ki, kd, v, i, t, s are strings or single characters?

Like this?

"#DCMC#" + "," + "234.5" + "," + "234.5" + "," + "234.5" + "," + "234.5" + "," + "234.5"+ "," + "234.5" + "," + "234.5" + "," + "\n";


Receive the whole string into an array if #DCMC# is received.

Now loop the array for 1st comma.
Read the data into variable till another comma is encountered.
Do this to get all parameters into different variables (arrays)

Convert the string value to float value or integer.
 
Last edited:

Or try using the 'strtok' command with a comma as the search parameter. Each call to it will return the next comma delimited item in the string.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…