Enabling and Disabling Events
Before a session can use either the VISA callback or queuing mechanism, you need to enable the session to sense events. You use the viEnableEvent() operation to enable an event type using either of the mechanisms. For example, to enable the VI_EVENT_SERVICE_REQ event for queuing, use the following code:
status = viEnableEvent(instr,VI_EVENT_SERVICE_REQ,VI_QUEUE,VI_NULL);
Note VISA currently allows both queuing and callbacks to be enabled for the same event type on the same session. You can do this in one call by bitwise ORing the mechanisms together (VI_QUEUE|VI_HNDLR), or you can do this in two separate calls to viEnableEvent(). The two mechanisms operate independently of each other. However, using both mechanisms for the same event type on the same session is usually unnecessary and is difficult to debug. Therefore, this is highly discouraged. |
Use viDisableEvent() to stop a session from receiving events of a specified type. You can specify the mechanism for which you are disabling, although it is more convenient to use VI_ALL_MECH to disable the event type for all mechanisms. For example, to disable the VI_EVENT_SERVICE_REQ event regardless of the mechanism for which it was enabled, use the following code:
status = viDisableEvent(instr,VI_EVENT_SERVICE_REQ,VI_ALL_MECH);
The viEnableEvent() operation also automatically enables the hardware, if necessary for detecting the event. The hardware is enabled when the first call to viEnableEvent() for the event is made from any of the sessions currently active. Similarly, viDisableEvent() disables the hardware when the last enabled session disables itself for the event.