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

/// <summary>
///	The expected maximum voltage level of the input signal for frequency and period
/// measurements. Positive values set the manual range. Negative values set Auto
/// Range mode.  The units are specified in Volts RMS.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IIviDmmFrequency_get_VoltageRange(double* Val)
{
	HRESULT hr = S_OK;

	long lAuto = 0;
	double dRange = 0;

	InstrQuery( "FREQ:VOLT:RANG?", &dRange );
	InstrQuery( "FREQ:VOLT:RANG:AUTO?", &lAuto );
	*Val = (lAuto==1) ? -dRange : dRange;

	return hr;
}

/// <summary>
///	The expected maximum voltage level of the input signal for frequency and period
/// measurements. Positive values set the manual range. Negative values set Auto
/// Range mode.  The units are specified in Volts RMS.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IIviDmmFrequency_put_VoltageRange(double Val)
{
	HRESULT hr = S_OK;
	hr = InstrPrintf( "FREQ:VOLT:RANG %.15g", (Val>0) ? Val : -Val );
	if(FAILED(hr)) return hr;

	// Currently, instrument does not switch to :RANG:AUTO properly according to range sign, so we do it explicitly

	return InstrWrite( (Val>0) ? ":FREQ:VOLT:RANG:AUTO 0" : ":FREQ:VOLT:RANG:AUTO 1" );

	return hr;
}


