Interrupt Callback Handlers

The way you register a handler depends on your programming language or development environment. Refer to the appropriate section below for how to register your handler.

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 callback is performed in a separate thread created by NI-VISA. The thread is signaled as soon as the event occurs.

C/C++

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).

Measurement Studio for Visual C++

When using National Instruments Measurement Studio for Visual C++, callbacks are registered with the InstallEventHandler() method. Refer to 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)

Measurement Studio for .NET

When using National Instruments Measurement Studio for .NET, you can register callbacks for specific events on different classes. For example, the MessageBasedSession class has a ServiceRequest event for which a callback can be registered. The code to register the callback for a ServiceRequest event on a MessageBasedSession in C# would look like the following code:

session.ServiceRequest += new MessageBasedSessionEventHandler(OnServiceRequest);

where OnServiceRequest would be declared as:

private void OnServiceRequest(object sender, MessageBasedSessionEventArgs e)

In VB .NET, the code to register a similar callback would look like:

AddHandler session.ServiceRequest, AddressOf OnServiceRequest

and OnServiceRequest would be defined as:

Private Sub OnServiceRequest(ByVal sender As Object, ByVal e As

' Code here

End Sub

Refer to the Measurement Studio for .NET documentation for more information.