//Example of using the Dmm to scan multiplexer channels

// """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
//  © 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
//'
//' This program requires either NI Visa or
//' Visa from Agilent I/O library version M or later to be installed
//' on the computer.
//'
// This program configures some Multiplexer channels for the Dmm to scan, initiates the
// scan, retrieves the data, and prints the results.

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

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


public class DmmScan
{
	static void Main(string[] args)
	{
		int row, numberChannels;

		// create an instace of the core driver
		// NOTE:  A2 interface is the latest one with new driver revision: 1.3.1.0 or higher
		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("TCPIP0::156.140.92.11::INSTR", false, true, standardInitOptions + "," + driverSetupOptions);
		
			// Configure Channel 1001   Temp. Thermist. 5k  °C
			host.Temperature.Thermistor.Configure("1001", Agilent34980AResolutionEnum.Agilent34980AResolutionDefault,
				Agilent34980AThermistorEnum.Agilent34980AThermistor5000);

			// Configure Channels 1004:1005  Volts DC    10 V    5 ½ digits
			host.Voltage.DCVoltage.Configure("1004,1005",10.0,
				Agilent34980AResolutionEnum.Agilent34980AResolutionDefault);

			// Channels 1006   Resistance  10 Mohm 5 ½ digits
			// Channels 1007   Resistance  10 Mohm 5 ½ digits
			host.Resistance.Configure("1006,1007",10000000.0,
				Agilent34980AResolutionEnum.Agilent34980AResolutionDefault);
			
			// Channel 1014   Resistance  100 ohm 5 ½ digits
			host.Resistance.Configure("1014",100.0,
				Agilent34980AResolutionEnum.Agilent34980AResolutionDefault);
			
			// Channels 1015   4w Resistance   100 ohm 4 ½ digits
			host.Resistance.Configure("1015",100.0,
				Agilent34980AResolutionEnum.Agilent34980AResolutionLeast);
			
			
			// Specify the scan list, 1 sweep per trigger, and have the scan order be ascending by channel number
			host.Scan.ConfigureScan("1001,1002:1005,1006,1007,1014,1015", 1, true);
    
			// Configure the trigger source, set number of triggers 2
			// Set trigger source timer, and time between triggers as 2.2 seconds
            host.Trigger.Configure(Agilent34980ATriggerSourceEnum.Agilent34980ATriggerSourceTimer,
				2, 2.2, 1);

			// Read the number of channels in scan list
            numberChannels = host.Scan.ScanSize;
			
			// Arm the trigger with initiate, this starts the measurement process
			host.Measurement.Initiate();
    
			// Wait up to 30 seconds for the scan to complete
			host.System.WaitForOperationComplete(30000);
    
			host.Measurement.DataFormat.Configure(false,true,false,
				Agilent34980ATimeOffsetEnum.Agilent34980ATimeOffsetAbsolute,true);

			//Retrieve the formatted data from the instrument
			string [] strData = host.Measurement.Fetch();
    
			// Print out the data to the console window
			Console.WriteLine("     Data     Units,Channel");
			Console.WriteLine("---------------------------------");
			for(row = 0; row < numberChannels * 2; row++)
			{
				Console.WriteLine(""+strData[row]);
			}
		}
		catch (Exception e)
		{
			Console.WriteLine(e.Message);
		}
		host.Close();   // close the connection to the instrument
		
		Console.WriteLine("Done - Press Enter to Exit");
		Console.ReadLine();

	}
}

