Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

obtain data from char string

Status
Not open for further replies.

gehan_s

Member level 3
Member level 3
Joined
Aug 31, 2012
Messages
62
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Sri Lanka
Visit site
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:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top