Hi All,
I am writing a bit of C# code to upload some dummy values to a board.
I have the code that spits out the relavent string in the Event handler I have
private void ProcessBuffer()
{
byte[] bytes = new byte[buffer.Count];
buffer.CopyTo(0, bytes, 0, buffer.Count);
buffer.RemoveRange(0, buffer.Count);
string data;
rtbIncoming.Clear();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
data = enc.GetString(bytes);
this.BeginInvoke(new MethodInvoker(delegate() { rtbIncoming.Text += data; }));// @@@ JG change
// MessageBox.Show(data);
//need to check for an OK coming back
}
private void myComPort_DataRecieved(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
byte[] data = new byte[myComPort.BytesToRead];
myComPort.Read(data, 0, data.Length);
if ((data.Length > 1) && (data[data.Length - 1] == 13))
{
Array.Resize(ref data, data.Length);
}
buffer.AddRange(data);
ProcessBuffer();
}
This was the standard Event handler I have been using for a age but I need to change it to wait for an OK opions please, would I be better off waiting in a timer for the OK or not?
Glenn