Hi,
The below code shows the way I am being told to Serial Comms (I think that polling to see if an event has happened would be better but....). Then problem I have is that the program appears to get stuck at the point
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
if (Reply_ATE.Substring(0, 3) != "DOK")
{
MessageBox.Show("Error #D#");
}
where Write_ATE is:
private string Write_ATE(string Data_To_ATE)
{
string Data_From_ATE = "";
Reply_Status = (int)REPLY.NO_REPLY;
ATEComPort.Write(Data_To_ATE);
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
NoDataAtPort.Enabled = false;
if (Reply_Status == (int)REPLY.TIMEOUT_REPLY)
{
Reply_Status = (int)REPLY.NO_REPLY;
ATEComPort.Write(Data_To_ATE);
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
NoDataAtPort.Enabled = false;
if (Reply_Status == (int)REPLY.TIMEOUT_REPLY)
{
Data_From_ATE = "TIMEOUT";
return (Data_From_ATE);
}
else if (Reply_Status == (int)REPLY.YES_REPLY)
{
Data_From_ATE = ATEComPort.ReadTo(">");
if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
{
return (Data_From_ATE);
}
else if ((Data_From_ATE.Substring(0, 1)) == "E")
{
return (Data_From_ATE);
}
}
else
{
//MessageBox.Show("ERROR");
Data_From_ATE = "SERIOUS_ERROR";
return (Data_From_ATE);
}
}
else if (Reply_Status == (int)REPLY.YES_REPLY)
{
Data_From_ATE = ATEComPort.ReadTo(">");
if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
{
return (Data_From_ATE);
}
else if ((Data_From_ATE.Substring(0, 1)) == "E")
{
Reply_Status = (int)REPLY.NO_REPLY;
ATEComPort.Write(Data_To_ATE);
while (Reply_Status == (int)REPLY.NO_REPLY)
{
NoDataAtPort.Enabled = true;
}
NoDataAtPort.Enabled = false;
if (Reply_Status == (int)REPLY.TIMEOUT_REPLY)
{
Data_From_ATE = "TIMEOUT";
return (Data_From_ATE);
}
else if (Reply_Status == (int)REPLY.YES_REPLY)
{
Data_From_ATE = ATEComPort.ReadTo(">");
if ((Data_From_ATE.Substring(0, 1)) == (Data_To_ATE.Substring(1, 1)))
{
return (Data_From_ATE);
}
else if ((Data_From_ATE.Substring(0, 1)) == "E")
{
return (Data_From_ATE);
}
}
else
{
//MessageBox.Show("ERROR");
Data_From_ATE = "SERIOUS_ERROR";
return (Data_From_ATE);
}
}
}
else
{
//MessageBox.Show("ERROR");
Data_From_ATE = "SERIOUS_ERROR";
return (Data_From_ATE);
}
return (Data_From_ATE);
}

1 answers
If I understood, you need to know if port recivies data. If I'm correct, the best way is to use the DataRecieved event of the port and capture the buffer and apply other actions.
answered 5 months ago by:
15
296
Yup thats correct I need to if the data is recieved and any reply back from it. I have a feeling that the way is was being told to use was not as bomb proof as the guy though it was. being told not to use timers as "they are s*** & don't work!". My idea was to poll the port recieved event using a timer but that doesn't work I'm told! Glenn
15
Problem with timer is that it tries between intervals and you may miss buffer stream. I had a hard time with timers for port reading.
296
I'm not really expecting a huge ammount of Data just the occasional reply #RG=23.3 etc. If I start the timer when I send data I am expecting the board to answer back as soon as it gets its CR and stop it when the device answer back (sounds good but I bet theres a reason why it wont work!) Glenn