obtain data from char string

Thread Starter

gehan_s

Joined Sep 17, 2012
38
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.

Rich (BB 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
 

Art

Joined Sep 10, 2007
806
Because you have control of the program that is sending, it should be easy to receive.

Any numeric character's hex representation, is just it's decimal value + 0x30h
Subtract that from any digit you receive, and that's the decimal digit value restored.

If a single number has multiple digits, you have delimited them with commas,
so any digit place to the left of the last digit gets multiplied by 10, 100, 1000, etc.
and added to the last digit.
There's a C function for that, I've always done it myself.
 
Top