Re: WaitCommEvent problem
From: Olivier (olivier.vigliengo_at_tma.no_spam.fr)
Date: 08/05/04
- Next message: Pretolesi Riccardo: "SetTextColor problem"
- Previous message: Claus Henning: "Re: sscanf problem. Please help"
- In reply to: marabo82: "WaitCommEvent problem"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 05 Aug 2004 09:05:32 +0200
Hi,
It is normal that that works such as you describe it :
1) Don't use WaitForSingleObject with an event which is never signaled
(SetEvent, PulseEvent). If the event you are waiting is never signaled,
the WaitForSingleObject function is returning when the Timeout (of
WaitForSingleObject) occurs.
2) WaitCommEvent trigger when a Communication event occurs, according to
the SetCommMask parameters (RXCHAR, TXEMPTY, ...) , but don't trigger
when timeout occurs.
3) The ReadFile function returns when nNumberOfBytesToRead are received
*OR* when timeout occurs according to the SetCommTimeouts parameters.
Comparing of nNumberOfBytesToRead and NumberOfByteRead allow you to know
if timeout is occured or if all of the bytes are received.
In conclusion, if you want to work with reception timeouts, directly use
ReadFile function instead of WaitCommEvent function.
I hope this helps you.
Regards.
Olivier.
PseudoCode :
CreateFile(...); // Open the Comm Port
SetCommState(...); // Configuring the Port (Baudrate, parity, ...)
SetCommTimeouts(...); // Set the Read and Write timeouts
ReadFile(hCom,
lpBuffer,
nNumberOfBytesToRead,
&dwNumberOfBytesRead,
NULL);
// Timeout ?
if(nNumberOfBytesToRead != dwNumberOfBytesRead)
{
// Timeout occurs
}
else // No timeout !
{
// Treatment of bytes
}
- Next message: Pretolesi Riccardo: "SetTextColor problem"
- Previous message: Claus Henning: "Re: sscanf problem. Please help"
- In reply to: marabo82: "WaitCommEvent problem"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|