//---------------------------------------------------------------------------
#pragma hdrstop
#include <stdio.h>
#include <conio.h>
#include <locale.h>
#include <stdlib.h>
#include "visa.h" // VISA header
//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
	ViSession rm, rsrc;
	ViStatus status;
	char buff[128];

	// Create VISA resource manager
	status = viOpenDefaultRM(&rm);

	// Create session 
	// With specified device address
	status = viOpen(rm, "TCPIP::169.254.0.254::8888::SOCKET::GEN", VI_EXCLUSIVE_LOCK, 5000, &rsrc); 
	if (status != VI_SUCCESS)
	{ // Check connection error
		viStatusDesc(rm, status, buff);
		printf("viOpen: %s\r\n", buff);
		_getch();
		return 0;
	}
	// Set timeout attribute (for operations)
	status = viSetAttribute(rsrc, VI_ATTR_TMO_VALUE, 5000);

	// Get identification string of device
	status = viQueryf(rsrc,"*IDN?\n","%T",buff);
	status = printf("IDN: %s", buff);

	// Set sweep mode to fixed
	status = viPrintf(rsrc,"SOURce:FREQuency:MODE FIXed\r\n");
	// Set fixed frequency value
	status = viPrintf(rsrc,"SOURce:FREQuency:FIXed 1253MHz\r\n");
	// Read fixed frequency value
	status = viQueryf(rsrc,"SOURce:FREQuency:FIXed?\n","%T", buff);
	printf("frequency: %s", buff);
	// Set trigger automatic mode
	status = viPrintf(rsrc, "INITiate:CONTinuous ON\r\n");
	//	Set reference generator to external source
	status = viPrintf(rsrc,"ROSCillator:SOURce EXTernal\n");
	// Set external reference generator frequency
	status = viPrintf(rsrc,"ROSCillator:EXTernal:FREQuency 10MHz\n");
	// Pulse modulation parameters
	// Set pulse modulation source to internal
	status = viPrintf(rsrc,"SOURce:PULM:SOURce INTernal\n");
	// Set period of pulse modulation
	status = viPrintf(rsrc,"SOURce:PULM:INTernal:PERiod 0.00000008\r\n");
	// Set pulse width of pulse modulation
	status = viPrintf(rsrc,"SOURce:PULM:INTernal:PWIDth 0.00000003\r\n");
	// Set pulse modulation on
	status = viPrintf(rsrc,"SOURce:PULM:STATe ON\r\n");
	// Set pover level value
	status = viPrintf(rsrc,"SOURce:POWer:LEVel -10\r\n");
	// Set power out on
	status = viPrintf(rsrc,"OUTPut:STATe ON\r\n");
	// Check Errors
	status = viQueryf(rsrc,"SYSTem:ERRor?\n","%T",buff);
	printf("status: %s", buff);

	// Waiting for user action
	_getch();
	// Set power out off
	status = viPrintf(rsrc,"OUTPut:STATe OFF\n");
	// Close session
	status = viClose(rsrc);
	// Close resource manager
	viClose(rm);
	
	return 0;
}
//---------------------------------------------------------------------------
 