Your browser does not allow scripts
Please click here to view a static table of contents without scripts
FT_SetEventNotification
Return to Introduction  Previous page  Next page
Sets conditions for event notification.

FT_STATUS
FT_SetEventNotification
(FT_HANDLE ftHandle, DWORD dwEventMask, PVOID pvArg)




Parameters
ftHandle
Handle of the device.
dwEventMask
Conditions that cause the event to be set.
pvArg
Interpreted as the handle of an event.




Return Value
FT_OK if successful, otherwise the return value is an FT error code.



Remarks
An application can use this function to setup conditions which allow a thread to block until one of the conditions is met. Typically, an application will create an event, call this function, then block on the event. When the conditions are met, the event is set, and the application thread unblocked.

dwEventMask is a bit-map that describes the events the application is interested in. pvArg is interpreted as the handle of an event which has been created by the application. If one of the event conditions is met, the event is set.

If
FT_EVENT_RXCHAR is set in dwEventMask, the event will be set when a character has been received by the device. If FT_EVENT_MODEM_STATUS is set in dwEventMask, the event will be set when a change in the modem signals has been detected by the device.



Windows and Windows CE Example
This example shows how to wait for a character to be received or a change in modem status.

First, create the event and call
FT_SetEventNotification.

FT_HANDLE ftHandle; // handle of an open device
FT_STATUS ftStatus;
HANDLE hEvent;
DWORD EventMask;

hEvent = CreateEvent(
                     NULL,
                     false, // auto-reset event
                     false, // non-signalled state
                     ""
                     );
EventMask = FT_EVENT_RXCHAR | FT_EVENT_MODEM_STATUS;
ftStatus = FT_SetEventNotification(ftHandle,EventMask,hEvent);



Sometime later, block the application thread by waiting on the event, then when the event has occurred, determine the condition that caused the event, and process it accordingly.

WaitForSingleObject(hEvent,INFINITE);

DWORD EventDWord;
DWORD RxBytes;
DWORD TxBytes;

FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
if (EventDWord & FT_EVENT_MODEM_STATUS) {
    // modem status event detected, so get current modem status
    FT_GetModemStatus(ftHandle,&Status);
    if (Status & 0x00000010) {
          // CTS is high
    }
    else {
          // CTS is low
    }
    if (Status & 0x00000020) {
          // DSR is high
    }
    else {
          // DSR is low
    }
}
if (RxBytes > 0) {
    // call FT_Read() to get received data from device
}

Linux Example
This example shows how to wait for a character to be received or a change in modem status.

First, create the event and call
FT_SetEventNotification.

FT_HANDLE ftHandle; 
FT_STATUS ftStatus;
EVENT_HANDLE eh;
DWORD EventMask;

ftStatus = FT_Open(0, &ftHandle);
if(ftStatus != FT_OK) {
   // FT_Open failed
   return;
}

pthread_mutex_init(&eh.eMutex, NULL);
pthread_cond_init(&eh.eCondVar, NULL);

EventMask = FT_EVENT_RXCHAR | FT_EVENT_MODEM_STATUS;
ftStatus = FT_SetEventNotification(ftHandle, EventMask, (PVOID)&eh);

Sometime later, block the application thread by waiting on the event, then when the event has occurred, determine the condition that caused the event, and process it accordingly.

pthread_mutex_lock(&eh.eMutex);
pthread_cond_wait(&eh.eCondVar, &eh.eMutex);
pthread_mutex_unlock(&eh.eMutex);

DWORD EventDWord;
DWORD RxBytes;
DWORD TxBytes;
DWORD Status;
FT_GetStatus(ftHandle,&RxBytes,&TxBytes,&EventDWord);
if (EventDWord & FT_EVENT_MODEM_STATUS) {
    // modem status event detected, so get current modem status
    FT_GetModemStatus(ftHandle,&Status);
    if (Status & 0x00000010) {
          // CTS is high
    }
    else {
          // CTS is low
    }
    if (Status & 0x00000020) {
          // DSR is high
    }
    else {
          // DSR is low
    }
}
if (RxBytes > 0) {
    // call FT_Read() to get received data from device
}

FT_Close(ftHandle);