
253
Chapter 6 Application Programs
Example Programs for C and C++
4
6
do{ /* Stay in loop until the srqFlag goes negative */
index = 1;
for (count = 0; count <45; count++)
{
index = 0;
printf(".");
}
printf(" srq flag = %d\n",srqFlag);
}
while (srqFlag>=0); /* A negative srqFlag indicates scan is done */
/* The instrument is done, so close the SRQ handler */
viDisableEvent(DataAcqu,VI_EVENT_SERVICE_REQ,VI_HNDLR);
viUninstallHandler (DataAcqu,VI_EVENT_SERVICE_REQ,SRQ_handler,(ViAddr)10);
viPrintf (DataAcqu,
"FETCH?\n"
);
/* Get all the readings */
viScanf(DataAcqu,"%,10lf",&volt);/* Put readings into an array */
for (index = 0;index<10;index++){ /* Print the readings */
printf("reading %d = %lf\n",index+1,volt[index]);
}
viClose (DataAcqu);
/* Close the communication port */
viClose (defaultRM);
}
/* This function will be called when the instrument interrupts the controller with
an SRQ for alarm and/or Operation Complete */
ViStatus _VI_FUNCH SRQ_handler(ViSession DataAcqu, ViEventType eventType,
ViEvent context,ViAddr userHdlr)
{
ViUInt16 statusByte;
viReadSTB(DataAcqu,&statusByte); /* Read status byte register and clear SRQ */
/* Bit 6 (64) indicates this SRQ is for our instrument, bit 1 (2) indicates
an alarm, and bit 5 (32) indicates the standard event register;
so alarm 64+2=66; OPC 64+32=96; both 64+32+2=98 */
if ((statusByte==66)|(statusByte==98)){
srqFlag = 1; /* Set flag to indicate this is an alarm */
viPrintf (DataAcqu,
"STATUS:ALARM:EVENT?\n"
);/* Check and clear alarm */
viScanf(DataAcqu,"%s",&reply_string);
printf("alarm event; bit = %s\n",reply_string);
}
if ((statusByte==96)|(statusByte==98)){
srqFlag = -1; /* Set flag to indicate end of operation */
viPrintf (DataAcqu,
"*ESR?\n"
); /* Check and clear ESR bit */
viScanf(DataAcqu,"%s",&reply_string);
printf("Standard Event Register; bit %s\n",reply_string);
}
return VI_SUCCESS;
}
34970A Refresh UG.book Page 253 Wednesday, February 17, 2010 12:34 PM
Содержание 34970A
Страница 16: ...16 34970A Refresh UG book Page 16 Wednesday February 17 2010 12 34 PM ...
Страница 20: ...34970A Refresh UG book Page 20 Wednesday February 17 2010 12 34 PM ...
Страница 21: ...1 1 Quick Start 34970A Refresh UG book Page 21 Wednesday February 17 2010 12 34 PM ...
Страница 39: ...2 2 Front Panel Overview 34970A Refresh UG book Page 39 Wednesday February 17 2010 12 34 PM ...
Страница 59: ...3 3 System Overview 34970A Refresh UG book Page 59 Wednesday February 17 2010 12 34 PM ...
Страница 87: ...4 4 Features and Functions 34970A Refresh UG book Page 87 Wednesday February 17 2010 12 34 PM ...
Страница 217: ...5 5 Error Messages 34970A Refresh UG book Page 217 Wednesday February 17 2010 12 34 PM ...
Страница 240: ...240 Chapter 5 Error Messages Plug In Module Errors 34970A Refresh UG book Page 240 Wednesday February 17 2010 12 34 PM ...
Страница 241: ...6 6 Application Programs 34970A Refresh UG book Page 241 Wednesday February 17 2010 12 34 PM ...
Страница 254: ...254 34970A Refresh UG book Page 254 Wednesday February 17 2010 12 34 PM ...
Страница 255: ...7 7 Tutorial 34970A Refresh UG book Page 255 Wednesday February 17 2010 12 34 PM ...
Страница 324: ...324 34970A Refresh UG book Page 324 Wednesday February 17 2010 12 34 PM ...