User`s guide

60 Agilent VISA User’s Guide
3 Programming with VISA
Example: SRQ Callback This program installs an event handler
and enables an SRQ event. When the event occurs, the installed event
handler is called. This sample program is intended to show specific
VISA functionality and does not include error trapping. Error trapping,
however, is good programming practice and is recommended in your
VISA applications. See “Trapping Errors” in this chapter for more
information.
This program is installed on your system in the
ProgrammingSamples subdirectory. See the IO Libraries Suite
Online Help for locations of example programs.
/* srqhdlr.c
This example program illustrates installing an
event handler to be called when an SRQ interrupt
occurs. Note that you may need to change the
address. */
#include <visa.h>
#include <stdio.h>
#if defined (_WIN32)
#include <windows.h> /* for Sleep() */
#define YIELD Sleep( 10 )
#elif defined (_WINDOWS)
#include <io.h> /* for _wyield */
#define YIELD _wyield()
#else
#include <unistd.h>
#define YIELD sleep (1)
#endif
int srqOccurred;
/* trigger event handler */
ViStatus _VI_FUNCH mySrqHdlr(ViSession vi,
ViEventType
eventType, ViEvent ctx, ViAddr userHdlr){
ViUInt16 statusByte;
/* make sure it is an SRQ event */
if(eventType!=VI_EVENT_SERVICE_REQ){
/* Stray event, so ignore */