TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Glenn Patton
NA
308
83.1k
Non obstructive wait
Feb 15 2012 7:42 AM
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. NbDataToWait is a bit vague I would prefer to wait for '>' come back but can't seem to think of a way to do it quickly!
public int WaitForData(int NbDataToWait, int Timeout)
{
int timeWaited = 0;
int timeToWait = 1; // 1 ms
// && there is no > in reply
while (timeWaited < Timeout && myComPort.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;
}
*/
UPDATE:: I believe I need to wait for a >
Reply
Answers (
14
)
Open and Edit Script SQL with C#
Reading password protected excel file