Your browser does not allow scripts
Please click here to view a static table of contents without scripts
FT_W32_WaitCommEvent
Return to Introduction  Previous page  Next page
This function waits for an event to occur.

BOOL
FT_W32_WaitCommEvent
(FT_HANDLE ftHandle, LPDWORD lpdwEvent, LPOVERLAPPED lpOverlapped)




Parameters
ftHandle
Handle of the device.
lpdwEvent
Pointer to a location that receives a mask that contains the events that occurred.
lpOverlapped
Pointer to an overlapped structure.




Return Value
If the function is successful, the return value is nonzero.
If the function is unsuccessful, the return value is zero.



Remarks
This function supports both non-overlapped and overlapped I/O, except under Windows CE and Linux where only non-overlapped IO is supported.

Non-overlapped I/O

The parameter,
lpOverlapped, must be NULL for non-overlapped I/O.

This function does not return until an event that has been specified in a call to
FT_W32_SetCommMask has occurred. The events that occurred and resulted in this function returning are stored in lpdwEvent.



Overlapped I/O
When the device has been opened for overlapped I/O, an application can issue a request and perform some additional work while the request is pending. This contrasts with the case of non-overlapped I/O in which the application issues a request and receives control again only after the request has been completed.

The parameter,
lpOverlapped, must point to an initialized OVERLAPPED structure.

This function does not return until an event that has been specified in a call to
FT_W32_SetCommMask has occurred.

If an event has already occurred, the request completes immediately, and the return code is non-zero. The events that occurred are stored in
lpdwEvent.

If an event has not yet occurred, the request completes immediately, and the return code is zero, signifying an error. An application should call
FT_W32_GetLastError to get the cause of the error. If the error code is ERROR_IO_PENDING, the overlapped operation is still in progress, and the application can perform other processing. Eventually, the application checks the result of the overlapped request by calling FT_W32_GetOverlappedResult. The events that occurred and resulted in this function returning are stored in lpdwEvent.



Example

This example shows how to write 128 bytes to the device using non-overlapped I/O.

FT_HANDLE ftHandle; // setup by FT_W32_CreateFile for non-overlapped i/o
DWORD dwEvents;

if (FT_W32_WaitCommEvent(ftHandle, &dwEvents, NULL))
  ; // FT_W32_WaitCommEvents OK
else
  ; // FT_W32_WaitCommEvents failed



This example shows how to write 128 bytes to the device using overlapped I/O.

FT_HANDLE ftHandle; // setup by FT_W32_CreateFile for overlapped i/o
DWORD dwEvents;
DWORD dwRes;
OVERLAPPED osWait = { 0 };

if (!FT_W32_WaitCommEvent(ftHandle, &dwEvents, &osWait)) {
  if (FT_W32_GetLastError(ftHandle == ERROR_IO_PENDING) {
    // wait is delayed so do some other stuff until ...
    if (!FT_W32_GetOverlappedResult(ftHandle, &osWait, &dwRes, FALSE))
      ; // error
    else
      ; // FT_W32_WaitCommEvent OK
        // Events that occurred are stored in dwEvents
  }
}
else {
  // FT_W32_WaitCommEvent OK
  // Events that occurred are stored in dwEvents
}