User`s guide
PCIS-DASK Application Hints ? 37
4.6 Interrupt Event Message Programming Hints
PCIS-DASK provides two methods to perform interrupt occurrence notification for NuDAQ DIO cards that have dual
interrupt system.
The Event Message method handles event notification through user-defined callbacks and/or the Windows Message
queue (for VB5, through user-defined callbacks only). When a user-specified interrupt event occurs, PCIS-DASK calls
the user-defined callback (if defined) and/or puts a message into the Windows Message queue, if you specified a
window handle. After receiving the message, the user’s application can carry out the appropriate task.
The event message mechanism is easy and safe in Windows 98 and NT systems; however, the time delay between the
event and notification is highly variable and depends largely on how loaded your system is. In addition, if a callback
function is called, succeeding events will not be handled until your callback has returned. If the time interval between
interrupt events is smaller than the time taken for callback function processing, the succeeding interrupt events will not
be handled. Therefore this mechanism is not suitable for the frequent interrupt occurrence condition.
The Event Status checking and waiting method handles interrupt event status checking through Win32 wait
functions, such as WaitForSingleObject or WaitForMultipleObjects. This method is useful for the situation that the
interrupt event occurs very often, and the applications written in the language that doesn’t support function pointers (e.g.
VB4).
1. Through user-defined callbacks and the Windows Message queue
[Example Code Fragment]
card = Register_Card(PCI_7230, card_number);
//INT1 event notification is through window message
DIO_INT1_EventMessage (card, INT1_EXT_SIGNAL, hWnd, WM_INT, NULL);
//INT2 event notification is through a callback function
DIO_INT2_EventMessage (card, INT2_EXT_SIGNAL, hWnd, NULL, (void *) cbfn);
….
//window message handling function
long PASCAL MainWndProc(hWnd, message, wParam, lParam)
{
switch(message) {
….
case WM_INT: //interrupt event occurring message
….
break;
….
case WM_DESTROY:
//Disable interrupts
DIO_INT1_EventMessage (card, INT1_DISABLE, hMainWnd, NULL, NULL);
DIO_INT2_EventMessage (card, INT2_DISABLE, hMainWnd, NULL, NULL);
//Release card
if (card >= 0) Release_Card(card);
PostQuitMessage(0);
break;
….
}
}
….
//call back function
LRESULT CALLBACK cbfn()
{
….
}
2. Through a Win32 wait function
[Example Code Fragment]
card = Register_Card(PCI_7230, card_number);
DIO_SetDualInterrupt(card, INT1_EXT_SIGNAL, INT2_EXT_SIGNAL, hEvent);
….
//wait for INT1 event
if (WaitForSingleObject(hEvent[0], INFINITE) == WAIT_OBJECT_0) {
ResetEvent(hEvent[0]);
……
}