C/c++ example – National Instruments NI-VXI User Manual

Page 37

Advertising
background image

Chapter 2 Introduction to the NI-VXI Functions

NI-VXI User Manual

2-18

© National Instruments Corporation

Alternatively, you can choose to handle either signals or interrupts with
a callback handler. You can use

RouteSignal()

to specify that the

events should be handled by the callback handlers rather than the signal
queue. After you have enabled the callback handler through either the

EnableSignalInt()

or the

EnableVXIint()

call, the callback

function will be invoked when the event occurs. Installing and using
callback handlers is very simple with NI-VXI because all of the
operating system interaction is handled for you. The following section
of code gives an example of using an callback handler.

C/C++ Example:

#define VXI_INT_LEVEL 1

/* this sample only interested in level 1 */

/* NIVXI_HVXIINT is a type defined for VXI/VME interrupt callback handlers */
NIVXI_HVXIINT *OldVXIintHandler; /* pointer to save the old handler */
NIVXI_HVXIINT UserVXIintHandler; /* function declr for new handler */

main () {

INT16 ret, controller;

/* Always begin by initializing the NI-VXI library */
ret = InitVXIlibrary ();
controller = -1;

/* Get address of the old handler */
OldVXIintHandler = GetVXIintHandler (VXI_INT_LEVEL);

/* Set callback handler to new user-defined procedure */
ret = DisableVXIint (controller, 1<<(VXI_INT_LEVEL-1));
ret = SetVXIintHandler (1<<(VXI_INT_LEVEL-1), UserVXIintHandler);
ret = EnableVXIint (controller, 1<<(VXI_INT_LEVEL-1));

/**/
/* user code */
/**/

/* Restore callback handler to what it was before we changed it */
ret = DisableVXIint (controller, 1<<(VXI_INT_LEVEL-1));
SetVXIintHandler (1<<(VXI_INT_LEVEL-1), OldVXIintHandler);
ret = EnableVXIint (controller, 1<<(VXI_INT_LEVEL-1));

/* Always close the NI-VXI library before exiting */
CloseVXIlibrary ();

}

/* The NIVXI_HQUAL and NIVXI_HSPEC should bracket */
/* every interrupt handler as shown below. */
NIVXI_HQUAL void NIVXI_HSPEC UserVXIintHandler (INT16 controller,

UINT16 level, UINT32 statusID)

{

/* user code for processing statusID */

}

Advertising