Hi All,
I am trying to perfect a bit of test code for a device we have updated (amongst other thing replaced a 9 Way with USB) I want to a method of waiting for a command to come back,the routine waits while there are no bytes in the buffer and the time is less the value passed to it.
The version in red is the version that is in use now is this recommended as it uses a Thread Sleep and it is important not to lock the machine up
Glenn
public int WaitForData(int NbDataToWait, int Timeout)
{
int timeWaited = 0;
int timeToWait = 1; // 1 ms
// && there is no > in reply
while (timeWaited < Timeout && BytesToRead < NbDataToWait)// && myComPort.BytesToRead(">"))
{
timeWaited += timeToWait;
lblwhere.Text += ".";
System.Threading.Thread.Sleep(timeToWait );
}
return timeWaited;
}
/* public int WaitForDataOK(int NbDataToWait, int Timeout)
{
int timeWaited = 0;
int timeToWait = 1; // 1 ms
// && there is no > in reply
while (timeWaited < Timeout && myComPort.BytesToRead > 0)
{
timeWaited += timeToWait;
lblwhere.Text += ".";
System.Threading.Thread.Sleep(timeToWait);
}
return timeWaited;
}
*/