hello all,,
I'am a student (i'am sorry if my english very bad)
I have a little problem with the GUI and microcontroller project that I created,
I will send two sample data from the microcontroller to the computer using serialports, I sent from the microcontroller using the C language printf ("@% 02d% 04d \ r", temp, count);
i sent using serialports setting on CodeVisionAVR compiler software:
/ / USART initialization
/ / Communication Parameters: 8 Data, 1 Stop, No Parity
/ / USART Receiver: On
/ / USART Transmitter: On
/ / USART Mode: Asynchronous
/ / USART Baud Rate: 9600
when the GUI is run the data received and displayed on a RichTextBox looks so perfect, the data are shown like with the transfer by the microcontroller.
but when data is received and i split it with two variables temp and count, I found the problem there.
I want to get the data to ( double or integer variabel) clean and precise. Can you help me??,, i'am very happy for that
thank you.
tihis script on my GUI visual C#
private string RxString;
private void serialPort1_DataReceived
(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
RxString = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
private string data_all,head,data1,data2;
private double data1a,data2a;
private void DisplayText(object sender, EventArgs e)
{
richTextBox1.AppendText(RxString);
if(RxString.Length >= 8)
{
head =RxString. Substring(0, 1);
if(head == '@')
{
data2 = RxString.Substring(1, 2);
data1 = RxString.Substring(3, 4);
data1a = Convert.ToDouble (data1);
data2a = Convert.ToDouble(data2);
this.segmentGauge1.Value = data2a;
this.segmentGauge2.Value = data1a;
}
}
}