VISA Programming Examples How to Co-ordinate Two Modules
200 Agilent 8163A/B, 8164A/B & 8166A/B Mainframes, Fifth Edition
    errStatus = viOpen (defaultRM, "GPIB::20::INSTR", 
VI_NULL,VI_NULL,&vi);
    if(errStatus < VI_SUCCESS)
      {
        printf("Failed to open instrument\n"); 
        exit(errStatus); 
      }
 
    /* set timeout to 20 sec; this should work for all commands except 
zeroing */
    errStatus = viSetAttribute(vi,VI_ATTR_TMO_VALUE,20000);
    if (errStatus < VI_SUCCESS) checkError(vi,errStatus);
 
    /* clear error queue */
    errStatus = viPrintf(vi,"*CLS\n");
    checkError(vi,errStatus);
 
    /* read the wavelength from the laser source */
    errStatus = viQueryf(vi,"SOURCE2:CHAN1:WAV?\n","%s",replyBuf);
    checkError(vi,errStatus);
 
    /* feed the source wavelength into the power meter making
       sure to measure the maximum power of the source */ 
    errStatus = viPrintf(vi,"SENS1:CHAN1:POW:WAV %s\n",replyBuf);
    checkError(vi,errStatus);
 
    /* turn auto range on */
    errStatus = viPrintf(vi,"SENS1:CHAN1:POW:RANGE:AUTO 1\n");
    checkError(vi,errStatus);
 
    /* change the power unit of the power meter to dBm */
    errStatus = viPrintf(vi,"SENS1:CHAN1:POW:UNIT 0\n");
    checkError(vi,errStatus);
 
    /*set the averaging time for measuring to 20 ms,
      therefore no timeout needs to implemented */
    errStatus = viPrintf(vi,"SENS1:CHAN1:POW:ATIME 0.02\n");
    checkError(vi,errStatus);
 
    /* set the attenuation to zero for maximum power */
    errStatus = viPrintf(vi,"SOURCE2:CHAN1:POW:ATT 0.0\n");
    checkError(vi,errStatus);
 
    /* set the reference mode to the internal one,
which is now the last displayed value  */