//Example of using the DAC card 34951A

// """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
//  © Agilent Technologies Inc. 2004, 2005, 2006
//  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 Technologies 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 Technologies support engineers can help explain the
// functionality of Agilent Technologies 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.
//' The IVI-COM driver is loaded as a reference from the Project/References menu
//' When loading the references, select:
//'           IVI Agilent34980A 1.0 Type Library
//'           IVI Agilent34951A 1.0 Type Library
//'
//' 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


using System;
using System.Diagnostics;
using System.Threading;

using Ivi.Driver.Interop;
using Agilent.Agilent34980A.Interop;
using Agilent.Agilent34951A.Interop;
using Agilent.Agilent34950A.Interop;



	public class Dac51
	{
		public static void Main(string[] args)
		{
			string respStr;
			
			//		create an instance of the driver interface
			IAgilent34980A2 host = new Agilent34980AClass();

			try
			{

				// Setup IVI-defined initialization options
				string standardInitOptions = "QueryInstrStatus=true, Simulate=false";
				
				// Setup driver-specific initialization options
				string driverSetupOptions = 
					"DriverSetup=Model=Agilent34980A";
					
				//			Open a session to the instrument and reset the instrument
				//host.Initialize("GPIB::9", false, true, standardInitOptions + "," + driverSetupOptions);
				host.Initialize("TCPIP0::156.140.92.93::INSTR", false, true, standardInitOptions + "," + driverSetupOptions);
				
				//			Get a handle to the 34951A moduel "personality"
				IAgilent34951A dac = (IAgilent34951A) host.Personality.Select( "Agilent34951A" );
				
				// Get and display card type in slot 1
				respStr = host.System.get_CardType(1);
				Console.WriteLine("Card type was:" + respStr);

				// Output a 3.0 Volt level on channel 1
				dac.Source.ApplyLevel("1001", Agilent34951AFunctionTypeEnum.Agilent34951AFunctionTypeVoltage,
					3.0);

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

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

				Console.WriteLine("Should be 500 Hz Sine wave on channel 3, 3V DC on chan 1\n");
				Console.WriteLine("Press Enter key to exit program\n");
				Console.ReadLine();
			}
			catch (Exception e)
			{
				Console.WriteLine(e.Message);
			}

			host.Close();   // close the connection to the instrument gracefully

		}
	}

