Specifications

Chapter 18 289
PSA Programming Examples
Using C to Save Binary Trace Data
PSA Programming Examples
/*print message to the standard output*/
printf("Getting the spectrum trace in binary format...\nPlease wait...\n\n");
/* get number of bytes in length of postceeding trace data
and put this in sBuffer*/
viRead (viPSA,(ViBuf)sBuffer,2,&lBytesRetrieved);
/* Put the trace data into sBuffer */
viRead (viPSA,(ViBuf)sBuffer,sBuffer[1] - 0,&lBytesRetrieved);
/* append a null to sBuffer */
sBuffer[lBytesRetrieved] = 0;
/* convert sBuffer from ASCII to integer */
lNumberBytes = atoi(sBuffer);
/* calculate the number of points given the number of byte in the trace
REAL 64 binary format means each number is represented by 8 bytes*/
lNumberPoints = lNumberBytes/sizeof(ViReal64);
/*get and save trace in data array */
viRead (viPSA,(ViBuf)adTraceArray,lNumberBytes,&lBytesRetrieved);
/* read the terminator character and discard */
viRead (viPSA,(ViBuf)sBuffer,1, &lLength);
/*print message to the standard output*/
printf("Querying instrument to see if any errors in Queue.\n");
/* loop until all errors read */
do
{
viPrintf (viPSA,"SYST:ERR?\n");/* check for errors */
viRead (viPSA,(ViBuf)sBuffer,80,&lLength);/* read back last error message
*/