Specifications

186 Chapter 16
ESA/PSA Programming Examples
Using C and Service Request (SRQ) to Determine When a Measurement is
Complete
ESA/PSA Programming Examples
/*Initiate a sweep*/
viPrintf(viSA,"INIT:IMM\n");
/*Make sure the previous command has been completed*/
viQueryf(viSA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("\nProgram Abort! error ocurred: last command was not
completed!\n");
exit(0);
}
/* Set the service request mask to assert SRQ when either a measurement
is completed or an error message has occurred.*/
viPrintf(viSA,"*SRE 96\n");
viPrintf(viSA,"*ESE 35\n");
/* Configure the computer to respond to an interrupt*/
/*install the handler and enable it */
viInstallHandler(viSA, VI_EVENT_SERVICE_REQ, mySrqHdlr,iAddress);
viEnableEvent(viSA, VI_EVENT_SERVICE_REQ,VI_HNDLR,VI_NULL);
/* Print Comment to user */
printf("Sending illegal command IDN and then waiting for SRQ\n");
/*Send an undefined command to the device*/
viPrintf(viSA,"IDN\n");
/*Wait for SRQ */
WaitForSRQ();
/*Set video averaging to 50 sweeps and turn averaging On*/
viPrintf(viSA,":SENS:AVER:TYPE LPOW;:SENS:AVER:COUN 50;:SENS:AVER:STAT ON\n");
/* Print Comment to user */
printf("\nInitiating measurement and waiting for SRQ when measurement