Hi All,
I am reading a serial port and putting output to a string.
But the string is blank, however if I stick a message box in, it causes enough of a gap to allow the text to appear in the string. I am using a delay based on the length of the expected reply.
The line of code that appears is
reply = rtbIncoming.text
rtbIncoming.Text has a string in it from the device. Is it because of seperate threads the reply in the text box appears on one thread, there is not enough of a delay for it to get from the comms thread to the UI thread? As I have had the following advice
So instead of a line like this:
rtbIncoming.Text = reply;
I'd try code like this:
this.Invoke(new MethodInvoker(delegate()
{
rtbIncoming.Text = reply;
}));
This would appear to use a delegate similar to the one I am using the Data Recieved Event.
private void port_DataReceived_1(object sender,SerialDataReceivedEventArgs e)
{
int valueWait = WaitForData(12, 10);
InputData = myComPort.ReadExisting();
if (InputData != String.Empty)
{
this.BeginInvoke(new SetTextCallback(SetText), new object[]
{InputData});
}
}
I think the previous answer I had over looked this as I now have two delegates to the same thread with no success! HELP!!
Glenn