
132
Chapter 3
Programming Examples
Saving Binary Trace Data in an ASCII File
/*set the binary byte order to SWAP*/
viPrintf(viVSA, "FORM:BORD SWAP\n");
/*trigger a spectrum measurement*/
viPrintf(viVSA, "MEAS:SPEC?;*OPC?\n");
/*poll the operation complete query*/
while (!lComplete)
viScanf (viVSA,"%d",&lComplete);
/*query the spectrum trace data*/
viPrintf(viVSA, "FETCH:SPEC7?\n");
/*set the instrument back to continuous mode*/
viPrintf(viVSA, "INIT:CONT 1\n");
/*get trace header data, in this case we know it's 6
bytes of format #DNNNNN */
viRead (viVSA,(ViBuf)sTraceBuffer,6,&lBytesRetrieved);
/*Extract the number of bytes from the trace header*/
memcpy(sBufferInfo,sTrac2,4);
lNumberBytes = atoi(sBufferInfo);
/*calculate the number of points given the number of
bytes in the trace - REAL 64 binary format means each
number is represented by 8 bytes*/
lNumberPoints = lNumberBytes/8;
/*get and save trace in a buffer*/
viRead (viVSA,(ViBuf)sTraceBuffer,lNumberBytes,
&lBytesRetrieved);
/*copy the trace buffer to the array of real*/
memcpy(adTraceArray,sTraceBuffer,(size_t)lNumberBytes);
/*save trace data to an ASCII file*/
fTraceFile=fopen("C:\\HPE4406ATrace.txt","w");
fprintf(fTraceFile,"HPE4406ATrace.exe Output\nAgilent
1998\n\n");
fprintf(fTraceFile,"List of %d points of the averaged
spectrum trace:\n\n",lNumberPoints);
for (long i=0;i<lNumberPoints;i++)
fprintf(fTraceFile,"\tAmplitude of point[%d] =
%.2lf dBm\n",i+1,adTraceArray[i]);
fclose(fTraceFile);
/*print message to the standard output*/
printf("The %d trace points were saved to
C:\\HPE4406ATrace.txt file\n\n",lNumberPoints);
/* close session */
viClose (viVSA);
viClose (defaultRM);
}
Summary of Contents for E4406A VSA Series
Page 4: ...4 ...
Page 59: ...59 2 Programming Fundamentals ...
Page 124: ...124 Chapter2 Programming Fundamentals Using the LAN to Control the Analyzer ...
Page 125: ...125 3 Programming Examples ...
Page 164: ...164 Chapter3 Programming Examples Using Java Programming Over Socket LAN ...
Page 165: ...165 4 Programming Command Cross References ...
Page 379: ...379 6 Error Messages ...
Page 412: ...412 Chapter6 Error Messages Error Message Descriptions ...