Interrupt Callback Handlers

NI-VISA

Interrupt Callback Handlers

Application callbacks are available in C/C++ but not in LabVIEW or Visual Basic. Callbacks in C are registered with the viInstallHandler() operation and must be declared with the following signature:

ViStatus _VI_FUNCH appHandler (ViSession vi, ViEventType eventType, ViEvent event, ViAddr userHandle)

Notice that the _VI_FUNCH modifier expands to _stdcall for Windows (32-bit). This is the standard Windows callback definition. On other systems, such as UNIX and Macintosh, VISA defines _VI_FUNCH to be nothing (null). Using _VI_FUNCH for handlers makes your source code portable to systems that need other modifiers (or none at all).

When using National Instruments Measurement Studio for Visual C++, callbacks are registered with the InstallEventHandler() method. See the Measurement Studio for Visual C++ documentation for more information on VISA callbacks. Handlers for this product must be declared with the following signature:

ViStatus __cdecl EventHandler (CNiVisaEvent& event)

After you install an interrupt handler and enable the appropriate event(s), an event occurrence causes VISA to invoke the callback. When VISA invokes an application callback, it does so in the correct application context. From within any handler, you can call back into the NI-VISA driver. On all platforms, you can also make system calls. The way VISA invokes callbacks is platform dependent, as shown in the following table.

How VISA Invokes Callbacks

Platform Callback Invocation Method
Windows Vista/XP/2000, Linux x86, Mac OS X, LabVIEW RT The callback is performed in a separate thread created by NI-VISA. The thread is signaled as soon as the event occurs.
VxWorks x86 For VXI, the callback is performed from within the driver interrupt service routine. For all other interfaces, the callback is performed only when the driver is accessed.

What this means is that on VxWorks (all interfaces other than VXI) you cannot wait in a tight loop for a callback to occur. For example, the following code does not work:

while (!intr_recv)
; /* do nothing */

For callbacks to be invoked on the VxWorks platform, you must call any VISA operation or give up processor time. Notice that NI-VISA on Windows and all UNIX platforms does not require you to call VISA operations or give up processor time to receive callbacks. However, because occasionally calling VISA operations ensures that callbacks will be invoked correctly on any platform, you should keep these issues in mind when writing code that you want to be portable.