Callback Modes

NI-VISA

Callback Modes

VISA gives you the choice of two different modes for using the callback mechanism. You can use either direct callbacks or suspended callbacks. You can have only one of these callback modes enabled at any one time.

To use the direct callback mode, specify VI_HNDLR in the mechanism parameter. In this mode, VISA invokes the callback routine at the time the event occurs.

To use the suspended callback mode, specify VI_SUSPEND_HNDLR in the mechanism parameter. In this mode, VISA does not invoke the callback routine at the time of event occurrence; instead, the events are placed on a suspended handler queue. This queue is similar to the queue used by the queuing mechanism except that you cannot access it directly. You can obtain the events on the queue only by re-enabling the session for callbacks. You can flush the queue with viDiscardEvents().

For example, the following code segment shows how you can halt the arrival of events while you perform some critical operations that would conflict with code in the callback handler. Notice that no events are lost while this code executes, because they are stored on a queue.

status = viEnableEvent(instr, VI_EVENT_SERVICE_REQ,VI_HNDLR, VI_NULL);
.
.
.
status = viEnableEvent(instr, VI_EVENT_SERVICE_REQ, VI_SUSPEND_HNDLR, VI_NULL);

/*Perform code that must not be interrupted by a callback. */

status = viEnableEvent(instr, VI_EVENT_SERVICE_REQ, VI_HNDLR, VI_NULL);

When you switch the event mechanism from VI_HNDLR to VI_SUSPEND_HNDLR, the VISA driver can still detect the events. For example, VXI interrupts still generate a local interrupt on the controller and VISA handles these interrupts. However, the event VISA generates for the VXI interrupt is now placed on the handler queue rather than passed to the application. When the critical section completes, switching the mechanism from VI_SUSPEND_HNDLR back to VI_HNDLR causes VISA to call the application's callback functions whenever it detects a new event as well as for every event waiting on the handler queue.