/******************************************************************************
 *                                                                         
 *               Copyright 2004-2006 Agilent Technologies
 *               All rights reserved.
 *
 *****************************************************************************/
 
#include "stdafx.h"
#include "CoAgilent34980A.h"

/// <summary>
///	Sets or gets the number of readings (samples) that will be taken on each channel
/// in the scan list, or on the DMM if the scan list is empty, when either the Initiate,
/// Read, or ReadNumbersOnly method is executed.
/// </summary>
/// <remarks>
///	Legal values are 1 to 500,000.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_SampleCount(long* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Sets or gets the number of readings (samples) that will be taken on each channel
/// in the scan list, or on the DMM if the scan list is empty, when either the Initiate,
/// Read, or ReadNumbersOnly method is executed.
/// </summary>
/// <remarks>
///	Legal values are 1 to 500,000.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_SampleCount(long Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets/gets the number of triggers that will be used to complete the measurement
/// started with either the Measurement Initiate, Read, or ReadNumbersOnly method.
/// </summary>
/// <remarks>
///	Allowable values are 1 to 500,000 and -1.  Sending -1 will set the trigger count
/// to infinite (continous measurement).
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_Count(long* Val)
{
	HRESULT hr = S_OK;

	CString sResp;
	hr = InstrQuery( ":TRIG:COUN?", sResp, DEFAULT_STRING_LENGTH );

	sResp.Remove( '\n' );
	sResp.Remove( '+' );
	if( sResp=="9.9E37" )
		*Val = -1;
	else
		*Val = (long)(atof( LPCTSTR(sResp) ) );

	return hr;
}

/// <summary>
///	Sets/gets the number of triggers that will be used to complete the measurement
/// started with either the Measurement Initiate, Read, or ReadNumbersOnly method.
/// </summary>
/// <remarks>
///	Allowable values are 1 to 500,000 and -1.  Sending -1 will set the trigger count
/// to infinite (continous measurement).
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_Count(long Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the trigger source for measurements.
/// </summary>
/// <remarks>
///	The instrument will accept a software (bus) signal, an immediate (continuous)
/// trigger, an external TTL trigger pulse, an alarm-initiated action, or an internally-paced
/// timer.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_Source(Agilent34980ATriggerSourceEnum* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandEnum(Val);

	return hr;
}

/// <summary>
///	Sets or gets the trigger source for measurements.
/// </summary>
/// <remarks>
///	The instrument will accept a software (bus) signal, an immediate (continuous)
/// trigger, an external TTL trigger pulse, an alarm-initiated action, or an internally-paced
/// timer.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_Source(Agilent34980ATriggerSourceEnum Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Sets/gets the trigger-to-trigger interval (in seconds) for measurements started
/// with the Initiate routine that have a trigger count greater than 1 and a trigger
/// source setting of TIMer.
/// </summary>
/// <remarks>
///	Allowable values are 0 to 359,999 seconds with a resolution of 0.001 seconds.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_Timer(double* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
///	Sets/gets the trigger-to-trigger interval (in seconds) for measurements started
/// with the Initiate routine that have a trigger count greater than 1 and a trigger
/// source setting of TIMer.
/// </summary>
/// <remarks>
///	Allowable values are 0 to 359,999 seconds with a resolution of 0.001 seconds.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_Timer(double Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}






/// <summary>
/// Configures the trigger subsystem with desired source, trigger count, timer and
/// sample count.
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="Source">
///	Sets the trigger source. Allowable values are {IMMediate|BUS|EXTernal|TIMer}.
/// </param>
/// <param name="TriggerCount">
///	Sets the trigger count.  Allowable values are 1 to 500,000, send -1 for infinite
/// (continous) triggering.
/// </param>
/// <param name="Timer">
///	Sets the trigger timer.  The allowable values are from 0 to 359,999 seconds
/// with resolution of 0.001 seconds.
/// </param>
/// <param name="SampleCount">
///	Selects the number of auto-triggered samples per channel per trigger.  Allowable
/// values are 1 to 500,000.
/// </param>
HRESULT Agilent34980A::IAgilent34980ATrigger_Configure(Agilent34980ATriggerSourceEnum Source, long TriggerCount, double Timer, long SampleCount)
{
	HRESULT hr = S_OK;

	if( TriggerCount==-1 )
	{
		hr = InstrPrintf( ":TRIG:SOUR %s; COUN INF; TIM %d; :SAMP:COUN %d", 
									EnumToString<Agilent34980ATriggerSourceEnum>(Source), 
									Timer, 
									SampleCount );
	}
	else
	{
		hr = InstrPrintCommand();
	}

	return hr;
}


/// <summary>
///	This setting overrides the automatic trigger delay calculated by the instrument,
/// and adds a delay between the trigger signal and the first reading taken on a
/// DMM only measurement (a measurement taken with the Scan List set to empty, and
/// started with one of the following Measurement routines:  Initiate, ReadNumbersOnly,
/// or Read.
/// </summary>
/// <remarks>
///	Allowable values are 0 to 3600 seconds with 0.000004 second resolution.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_Delay(double* val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(val);

	return hr;
}


/// <summary>
///	This setting overrides the automatic trigger delay calculated by the instrument,
/// and adds a delay between the trigger signal and the first reading taken on a
/// DMM only measurement (a measurement taken with the Scan List set to empty, and
/// started with one of the following Measurement routines:  Initiate, ReadNumbersOnly,
/// or Read.
/// </summary>
/// <remarks>
///	Allowable values are 0 to 3600 seconds with 0.000004 second resolution.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_Delay(double Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Disables or enables an automatic trigger delay.
/// </summary>
/// <remarks>
///	If enabled, the instrument determines the delay based on function, range, and
/// integration time.A non-automatic trigger delay is used only on DMM only measurements
/// (a measurement taken with the Scan List set to empty, and started with one of
/// the following Measurement routines:  Initiate, ReadNumbersOnly, or Read
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_get_DelayAuto(VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}


/// <summary>
///	Disables or enables an automatic trigger delay.
/// </summary>
/// <remarks>
///	If enabled, the instrument determines the delay based on function, range, and
/// integration time.A non-automatic trigger delay is used only on DMM only measurements
/// (a measurement taken with the Scan List set to empty, and started with one of
/// the following Measurement routines:  Initiate, ReadNumbersOnly, or Read
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ATrigger_put_DelayAuto(VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

