blah blah blah is here! blah blah » Close

up0down
link

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;
}
region of the the recieved protion of the code. I think that this is due to the DUT being slow (300 baud) and some times not being able to reply which leads me to think that either the DUT has not replied in a set time frame (which I havent set, I am using the device will ALWAYS reply) or it crashes (both are not good!) can anybody throw a little more light on to whats going wrong? my thinking was to use timers to allow the ports to be polled, 'Windows Timers DON'T Work' was the reason I am now in this hole trying to get out! Also would this method tie up Windows to the state where it crashes?

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);



}

last answered 5 months ago

1 answers

up1down
link

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.

GlennP
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

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.

GlennP
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

Feedback