Specifications
274 Chapter 17 
ESA Programming Examples
Using C to Make Faster Power Averaging Measurements
ESA Programming Examples
/****************  Write binary trace data to ESA *******************/
void write_binary_trace(char *cScpiCommand, int *ipTraceData) {
 /*  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[iArrayLength + strlen(cScpiCommand)] = 0x0A; 
 iBlockSize = (strlen(cScpiCommand) + iArrayLength + 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 );
  iTotalRetCount += lRetCount;
 /* copy trace data to an array,  */
 /* byte order swapping could be done here rather than in ESA */
  memcpy(iArray, &cInBuffer[iHeaderLength], iArrayLength);










