I’m developing a piece of software, which reads data sent through the COM port and display the value in a live graph and in a textbox (for debugging). It reads fine at first, but then suddenly one of the numbers is divided into two pieces. Like this:
63 – 64 – 65 – 66 – 67 – 6 – 8 – 69 – 70 – 80
It should say 68. This makes the graph all wrong!
What is the cause of this?
My code is as follows:
private void DisplayText(object sender, EventArgs e)
{
textBox1.AppendText(RxString);
textBox1.AppendText(" - ");
}
private void comPort_DataReceived_1(object sender, SerialDataReceivedEventArgs e)
{
RxString = comPort.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
newRead = Convert.ToDouble(RxString);
AddDataToGraph(zedGraph, howfar, newRead);
howfar++;
}
Thanks in advance.
There’s no guarantee in what size chunks you will get the data….
it could get them character at a time, or several characters at a time.
Generally, never depend on timing to work out the difference between logical “chunks” ( in your case, numbers). Instead create a protocol that you can interpret.
in your case if you have a VERY simple protocol where you send a number [space] number [space] number then you can parse out
eg…
and if you were using 123,123,234,123,343\n