4 Programming example
4.2 Advanced operation example
109
viClose(defaultRM);
}
4.2.3 Setting Point Frequency for GPIB Interface and Query
/*************************************************************************
This example uses the functions of the VISA library to set the point frequency of the signal source
outputting 500 MHZ signals and the power of -2 dBm, and query the current frequency and power.
Start VS2010, add the required files, and enter the following code into your .cpp file
************************************************************************/
#include “stdafx.h”
#include <visa.h>
#include <iostream>
#include <stdlib.h>
#include <conio.h>
void ShowMsg(PCHAR lpszText)
{
#ifdef _UNICODE
AfxMessageBox((CString)lpszText);
#else
AfxMessageBox(lpszText);
#endif
}
void main()
{
ViSession defaultRM,vi;
ViStatus vistatus = 0;
Char buff[256];
int num;
vistatus = viOpenDefaultRM(&defalutRM);
vistatus =
viOpen(defaultRM,”GPIB0::8::INSTR”,VI_NULL,VI_NULL,&vi);
if(vistatus)
{
ShowMsg(
“the task cannot be opened, please re-check the device and connect”);
exit(0);
}
viPrintf(vi,”*RST\n”); //reset the signal source
viPrintf(vi,":SENS:FREQ:FIX 500MHz\n"); //set the point frequency to 500 MHz
viPrintf(vi,":SENS:FREQ:FIX?\n");
viScanf(vi,"%s",buff);