-
WaitCommEvent()????
Hi:
Here is to monitor the any character arrives in COM Port
Code:
while(TRUE)
{
if (!WaitCommEvent(COM1, &dwCommEvent, &osStatus))
{
if (GetLastError() != ERROR_IO_PENDING) // Wait not delayed!!
{
/*ERROR HANDLING HERE*/
}
else
// while(TRUE)
//{
deRes = WaitForSingleObject(osStatus.hEvent,3000);
switch(deRes)
{
case WAIT_OBJECT 0:
/*osStatus.hEvent gets signaled*/
break;
case WAIT_TIMEOUT:
MessageBox(0,"timeouts","ok",MB_OK);
break;
default:
............
break;
}
// }//end while(TRUE)
}
}
Here I hope those varaibles are cleared with the names.
The problem is that the GetLastError() is not pending after the first round WM_TIMEOUT,I just can't say the reason, but is there any way to avoid the error if I want to restart from WaitCommEvent() after every WM_TIMEOUT??
Thanx for the help!!!
-
Not gone thru your code fully. Just skimmed it but found an error.
Think you missed a brace { changing the meaning of the code.
Try
Code:
//I like to have a loop variable
int iLoop=TRUE;
while(iLoop)
{
if (!WaitCommEvent(COM1, &dwCommEvent, &osStatus))
{
if (GetLastError() != ERROR_IO_PENDING) // Wait not delayed!!
{
/*ERROR HANDLING HERE*/
}
else
{//this brace is missing
deRes = WaitForSingleObject(osStatus.hEvent,3000);
switch(deRes)
{
case WAIT_OBJECT 0:
/*osStatus.hEvent gets signaled*/
break;
case WAIT_TIMEOUT:
MessageBox(0,"timeouts","ok",MB_OK);
break;
default:
............
break;
}
}
}
else //is this where we should exit?
iLoop=FALSE;
}
-
Thanks, but what I should do if I don't want to quit while() loop? some problem occurs in WaitCommEvent() after the first timeouts.
Thanks alot
-
I'm not sure what you want to do so....
Code:
do//until we get the object signaled
{
deRes = WaitForSingleObject(osStatus.hEvent,3000);
if(deRes ==WAIT_OBJECT )
{
/*osStatus.hEvent gets signaled*/
//set main loop var here to exit?
}
else if(//error occurs)
//ect
}
while (deRes==WAIT_TIMEOUT)//three seconds passed without change