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





/// <summary>
/// Resets all measurement parameters on the specified channels to their default
/// values. Then, configures the channels for temperature measurements but does
/// not initiate the scan.
/// </summary>
/// <remarks>
/// If you supply an empty ChannelList, this method applies to the internal DMM,
/// independent of any channels or a scan list.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
/// <param name="Resolution">
///	Select from Least (4.5 digits), Default (5.5 digits) and Best (6.5 digits).
/// </param>
/// <param name="Type">
///	FRTD Alpha type 85 or 91.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_Configure(BSTR ChannelList, Agilent34980AResolutionEnum Resolution, Agilent34980AFRTDAlphaEnum Type)
{
	HRESULT hr = S_OK;

	CString sList = CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Selects the nominal resistance (Ro) for 4-wire RTD measurements on the specified
/// channels.
/// </summary>
/// <remarks>
///	If you supply an empty ChannelList, this method applies to the internal DMM,
/// independent of any channels or a scan list.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_get_Resistance(BSTR ChannelList, double* Val)
{
	HRESULT hr = S_OK;

	CString sList(ChannelList);
	if( -1 != sList.Find( ',' ) || -1!=sList.Find( ':' ) || -1 != sList.Find( '-' ) )
	{
		return ReportError( E_AGILENT34980A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34980AFRTD_get_Resistance"), _T("ChannelList"));
	}
	CorrectChannelList( ChannelList, false );
	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Selects the nominal resistance (Ro) for 4-wire RTD measurements on the specified
/// channels.
/// </summary>
/// <remarks>
///	If you supply an empty ChannelList, this method applies to the internal DMM,
/// independent of any channels or a scan list.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_put_Resistance(BSTR ChannelList, double Val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	This property selects the FRTD type for 4-wire temperature measurements on the
/// specified channels. If you supply an empty  ChannelList, this property applies
/// to the internal DMM, independent of any channels or a scan list.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_get_Alpha(BSTR ChannelList, Agilent34980AFRTDAlphaEnum* Val)
{
	HRESULT hr = S_OK;

	CString sList(ChannelList);
	if( -1 != sList.Find( ',' ) || -1!=sList.Find( ':' ) || -1 != sList.Find( '-' ) )
	{
		return ReportError( E_AGILENT34980A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34980AFRTD_get_Alpha"), _T("ChannelList"));
	}
	CorrectChannelList( ChannelList, false );
	CString resp;
	hr = InstrQueryCommand(resp, DEFAULT_STRING_LENGTH );
	resp.Remove( '+' );
	if( !EnumFromString<Agilent34980AFRTDAlphaEnum>( resp, *Val ) )
		return ReportError( IDS_E_IVI_UNEXPECTED_RESPONSE );

	return hr;
}


/// <summary>
///	This property selects the FRTD type for 4-wire temperature measurements on the
/// specified channels. If you supply an empty  ChannelList, this property applies
/// to the internal DMM, independent of any channels or a scan list.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_put_Alpha(BSTR ChannelList, Agilent34980AFRTDAlphaEnum val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Enables or Disables the measurement on the specified channel (or the DMM if
/// channelList is empty) to be used as an external reference for a thermocouple
/// measurement that has been configured to use an external reference.
/// </summary>
/// <remarks>
///	Note that this usually requires the external reference channel to be measured
/// BEFORE the thermocouple is measured so that there is a fresh reference value
/// for the thermocouple to use.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_get_IsExternalReference(BSTR ChannelList, VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	CString sList(ChannelList);
	if( -1 != sList.Find( ',' ) || -1!=sList.Find( ':' ) || -1 != sList.Find( '-' ) )
	{
		return ReportError( E_AGILENT34980A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34980AFRTD_get_IsExternalReference"), _T("ChannelList"));
	}
	CorrectChannelList( ChannelList, false );
	hr = InstrQueryCommand(sList, DEFAULT_STRING_LENGTH );
	sList.Remove( '+' );
	if( sList=='1' )
		*Val = VARIANT_TRUE;
	else if( sList=='0' )
		*Val = VARIANT_FALSE;
	else return ReportError( IDS_E_IVI_UNEXPECTED_RESPONSE );

	return hr;
}

/// <summary>
///	Enables or Disables the measurement on the specified channel (or the DMM if
/// channelList is empty) to be used as an external reference for a thermocouple
/// measurement that has been configured to use an external reference.
/// </summary>
/// <remarks>
///	Note that this usually requires the external reference channel to be measured
/// BEFORE the thermocouple is measured so that there is a fresh reference value
/// for the thermocouple to use.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_put_IsExternalReference(BSTR ChannelList, VARIANT_BOOL Val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Enables or disables offset compensation.
/// </summary>
/// <remarks>
///	Offset compensation removes the effects of any dc voltages in the circuit being
/// measured. The technique involves taking the difference between two resistance
/// measurements on the specified channels, one with the current source turned on
/// and one with the current source turned off. If the ChannelList parameter is
/// empty, this command applies to the internal DMM, independent of any channels
/// or a scan list.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_get_OCompensated(BSTR ChannelList, VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	CString sList(ChannelList);
	if( -1 != sList.Find( ',' ) || -1!=sList.Find( ':' ) || -1 != sList.Find( '-' ) )
	{
		return ReportError( E_AGILENT34980A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34980AFRTD_get_IsExternalReference"), _T("ChannelList"));
	}
	CorrectChannelList( ChannelList, false );
	CString sResp;
	hr = InstrQueryCommand(sResp, DEFAULT_STRING_LENGTH );
	sResp.Remove( '+' );
	if( sResp=='1' )
		*Val = VARIANT_TRUE;
	else if( sResp=='0' )
		*Val = VARIANT_FALSE;
	else return ReportError( IDS_E_IVI_UNEXPECTED_RESPONSE );

	return hr;
}


/// <summary>
///	Enables or disables offset compensation.
/// </summary>
/// <remarks>
///	Offset compensation removes the effects of any dc voltages in the circuit being
/// measured. The technique involves taking the difference between two resistance
/// measurements on the specified channels, one with the current source turned on
/// and one with the current source turned off. If the ChannelList parameter is
/// empty, this command applies to the internal DMM, independent of any channels
/// or a scan list.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc. Must contain only 1 entry for the getter.
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_put_OCompensated(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
/// Resets all measurement parameters on the specified channels to their default
/// values. Then, configures the channels for temperature measurements and immediately
///  sweeps through the specified channels one time.
/// </summary>
/// <remarks>
/// The results are sent directly to the instrument output buffer. If you supply
/// empty ChannelList, this method applies to the internal DMM, independent of any
/// channels or a scan list.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
/// <param name="Type">
///	One of RTD Alpha values {85|91}.
/// </param>
/// <param name="Resolution">
///	Select from Least (4.5 digits), Default (5.5 digits) and Best (6.5 digits).
/// </param>
HRESULT Agilent34980A::IAgilent34980AFRTD_Measure(BSTR ChannelList, Agilent34980ARTDAlphaEnum Type, Agilent34980AResolutionEnum Resolution, SAFEARRAY** val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	RETURN_IF_FAIL( InstrPrintCommandNoPoll() );

	hr = FormattedReadList( NtlAsciiType_R8, ",", val );

	return hr;
}
