Chapter 3 133
ProgrammingExamples
Reading Trace Data Using 32-bit Real Format (RS-232)
/*Query number of sweep points p er trace (firmware revision A.04.00 or later)*/
/*For firmware revisions prior t o A.04.00, the number of sweep poin ts is 401 */
iSwpPnts = 401;
viQueryf(viESA,"SENSE:SWEEP:POIN TS?\n","%d",&iSwpPnts);
/*Calculate number of bytes in t he header. The header consists of t he "#" sign*/
/*followed by a digit representi ng the number of digits to follow. The digits */
/*which follow represent the num ber of sweep points multiplied by t he number */
/*of bytes per point. */
iHeaderBytes = 3; /* iDataBytes >0, plus increment for " #" and "n" */
iDataBytes = (iSwpPnts*iBytesPerPnt);
lNumberBytes = iDataBytes;
while ((iDataBytes = (iDataBytes / 10 )) > 0 )
{
iHeaderBytes++;
}
/*Set analyzer to single sweep m ode */
viPrintf(viESA,"INIT:CONT 0 \n");
/* Set the analyzer to 50MHz-center frequency */
viPrintf(viESA,"SENS:FREQ:CENT 5 0 MHZ\n");
/*Set the analyzer to 50MHz Span */
viPrintf(viESA,"SENS:FREQ:SPAN 5 0 MHZ\n");
/* Specify dB per division of ea ch vertical division & Units */
viPrintf(viESA,"DISP:WIND:TRAC:Y :SCAL:PDIV 10dB\n");
viPrintf(viESA,"UNIT:POW DBM\n") ;
/*Set analyzer trace data format to 32-bit Real */
viPrintf(viESA,"FORM:DATA REAL,32\n" );
/*Set the binary byte order to S WAP */
viPrintf(viESA, "FORM:BORD SWAP\ n");
/*Trigger a sweep */
viPrintf(viESA,"INIT:IMM\n");
/*Read the operation complete query */
viQueryf(viESA, "*OPC?\n", "%d", &lOpc);
if (!lOpc)
{
printf("Program Abort! error ocurr ed: last command was not completed !\n");
exit(0);
}