4 Programming example
4.2 Advanced operation example
108
This example uses the functions of the VISA library to query different states and conditions of the device.
Start VS2010, add the required files, and enter the following code into your .cpp file.
*************************************************************************/
#include <visa.h>
#include “stdafx.h”
#include <iostream>
#include <conio.h>
#include <stdlib.h>
void ShowMsg(PCHAR lpszText)
{
#ifdef _UNICODE
AfxMessageBox((CString)lpszText);
#else
AfxMessageBox(lpszText);
#endif
}
void main()
{
ViSession defaultRM,vi;
ViStatus vistatus;
Char buff[256];
int num;
vistatus = viOpenDefaultRM(&defaultRM); //open the GPIB task with the address of 18
vistatus = viOpen(defaultRM,"TCPIP0::172.141.114.254::5000::SOCKET",VI_NULL,VI_NULL,&vi);
if(vistatus)
{
ShowMsg
(
“the task cannot be opened, please re-check the device and connect ”);
exit(0);
}
viSetAttribute(vi,VI_ATTR_TERMCHAR_EN,VI_TRUE);
viP
rintf(vi,”*RST\n”); //reset the broadband receiver
viP
rintf(vi,”:SENS:FREQ:CENT?\n”); //query the center frequency
viScanf(vi,"%s"
,
buff); //put the query results into the array
CString strMsg;
strMsg.Format("Value:%s",buff);
ShowMsg(strMsg);
viClose(vi);