/****************************************************************************
    '    Copyright © 2005, 2006 Agilent Technologies Inc. All rights
    '    reserved.
    '
    ' You have a royalty-free right to use, modify, reproduce and distribute
    ' the Sample Application Files (and/or any modified version) in any way
    ' you find useful, provided that you agree that Agilent has no
    ' warranty,  obligations or liability for any Sample Application Files.
    '
    ' Agilent Technologies provides programming examples for illustration only,
    ' This sample program assumes that you are familiar with the programming
    ' language being demonstrated and the tools used to create and debug
    ' procedures. Agilent support engineers can help explain the
    ' functionality of Agilent software components and associated
    ' commands, but they will not modify these samples to provide added
    ' functionality or construct procedures to meet your specific needs.
'****************************************************************************/

//' This program uses the Agilent 34980A IVI-COM driver.
//' This program requires either NI Visa or
//' Visa from Agilent I/O library version M or later to be installed
//' on the computer.
//'
//' 34951A
//' This program demonstrates the use of the 34951A to create dc output, and a sine wave
//' from the internal waveforms

#include "stdafx.h"
#include <atlstr.h>
#include <atlsafe.h>

#import "C:/Program Files/IVI/Bin/Agilent34951A.dll"	no_namespace


int _tmain(int argc, _TCHAR* argv[])
{
	::CoInitialize(NULL);

	try
	{
		IAgilent34980A2Ptr host(__uuidof(Agilent34980A));
	
		// Setup IVI-defined initialization options
		CString strStandardInitOptions = 
			"Cache=false, InterchangeCheck=false, QueryInstrStatus=true, RangeCheck=false, RecordCoercions=false, Simulate=false";
			
		// Initialize instrument and clear status system/errors
		host->Initialize("TCPIP0::156.140.92.93::INSTR", VARIANT_FALSE, VARIANT_TRUE, LPCTSTR(strStandardInitOptions));	
		host->Status->Clear();

		IAgilent34951APtr dac = (IAgilent34951APtr) host->Personality->Select( _bstr_t("Agilent34951A") );

		// Output a 3.0 Volt level on channel 1
		dac->Source->ApplyLevel(_bstr_t("1001"), Agilent34951AFunctionTypeVoltage, 3.0);

		// Create a Sinewave named ExampleTrace
		dac->Trace->CreateStandard( 1, "ExampleTrace", 200,	Agilent34951ATraceWaveformSinusoid);

		// Output the waveform continuously at frequency 500 Hz, amplitude 5.0 V, offset 0.5 V
		dac->Source->ApplyTrace(_bstr_t("1003"),"ExampleTrace", Agilent34951AFunctionTypeVoltage,
					5.0, 0.5, 500);

		printf("Channel 3 should be outputting a 500 Hz Sine wave.\n");
		printf("Press Enter to exit the program\n");
		getchar();

		host->Close();

	}
	catch (_com_error& e)
	{
		::MessageBox(NULL, e.Description(), e.ErrorMessage(), MB_ICONERROR);
	}

	::CoUninitialize();

	return 0;
}
