Agilent Technologies 8166A User Manual

Page of 274
How to Measure Power using FETCh and READ
VISA Programming Examples
Agilent 8163A/B, 8164A/B & 8166A/B Mainframes, Fifth Edition
197
                    {  if(!strcmp(compBuf,replyBuf))
                        {  printf("Same:%s\n",replyBuf);  }
                    else  printf("New:%s\n",replyBuf);
                    }
                else  printf("First:%s\n",replyBuf);
                strcpy(compBuf,replyBuf);
            }
        /*  now  the  read  command  is  used  in  the  same  manner  to 
demonstrate the difference between fetch and read */
           
      /* read also 10 values, compare them and display the result; */
            for  (i  =  0;  i  <  10;  i++)
            {
            /*  In  comparision  to  the  "FETCH"  command,  the  "READ"  command 
implies         triggering a measurement. Make sure the timeout set is 
greater than the adjusted averaging time, so that the READ command 
will not time out; */
                   
              /*  send  the  read  command  */             
              errStatus  =  viQueryf(vi,"READ1:CHAN1:POW?\n","%t",replyBuf);
              checkError(vi,errStatus);
               
                if(i)
                    {
                    if(!strcmp(compBuf,replyBuf))    printf("Same:%s",replyBuf);
                    else  printf("New    :%s",replyBuf);
                    }
                else  printf("\nFirst:%s",replyBuf); 
                /*copy  new  value  to  compare  buffer*/
                strcpy(compBuf,replyBuf);
            }
        /*  loop,  until  a  key  is  pressed  */
    while(!scanf("%c",&c));
         
    checkError(vi,errStatus);
        /*  close  the  session  */
        viClose(vi);       
}
void checkError(ViSession session, ViStatus err_status )
    {  ViStatus  error;
        ViChar  errMsg[256];
              error  =  viQueryf(session,"SYST:ERR?\n","%t",errMsg);
              if  (error  ==  VI_ERROR_TMO) 
                  {
                  printf("System  Error!\n")  ;
                  exit(1);
                  }