182
Chapter 3
Programming Examples
Making Faster Measurements (multiple measurements)
/* trace data must point to an integer array of size NUM_POINTS */
memcpy(&cOutBuffer[strlen(cScpiCommand)], ipTraceData, iArrayLength);
memcpy(&cOutBuffer, cScpiCommand, strlen(cScpiCommand));
/* Add a <newline> to the end of the data, This isn’t necessary */
/* if the GPIB card has been configured to assert EOI when the last */
/* character is sent, but it ensures a valid iTermLength is provided. */
cOutBuffer[iArray strlen(cScpiCommand)] = 0x0A;
iBlockSize = (strlen(cScpiCommand) + iArray 1);
viWrite(viESA,(ViBuf) cOutBuffer, iBlockSize, &lRetCount );
}
/******* Measure and calculate power-average of multiple measurements
*********/
void average() {
int i=0, iLoop=0;
int iArray[NUM_POINTS];
long lOpc =0L;
double dLogTen = log(10.0);
setup();
iTotalRetCount = lRetCount = 0;
/* start the timer */
ftime( &start_time );
/* Now run through the event loop iNumTraces times */
for(i=0; i<iNumTraces; i++) {
/* trigger a new measurement and wait for complete */
viPrintf(viESA, ":INIT:IMM;*WAI\n");
/* Read the trace data into a buffer */
viPrintf(viESA, ":TRAC:DATA? TRACE1\n");
viRead(viESA,(ViBuf) cInBuffer, (ViUInt32) iBlockSize, &lRetCount );
iTotalRe= lRetCount;
/* copy trace data to an array, */
/* byte order swapping could be done here rather than in ESA */
memcpy(iArray, &cInBuffer[iHeaderLength], iArrayLength);
/* calculate a running dPower-average */
for(iLoop = 0; iLoop < NUM_POINTS; iLoop++) {
/* running average of dPower, in milliwatts */