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

/// <summary>
/// Clears the message displayed on the front panel display.
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
HRESULT Agilent34980A::IAgilent34980ADisplay_ClearDisplay()
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Enables/Disables the front panel display.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_DisplayEnabled(VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandBool(Val);

	return hr;
}

/// <summary>
///	Enables/Disables the front panel display.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_put_DisplayEnabled(VARIANT_BOOL Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Displays a message on the instrument's front panel display.  The message sent
/// can be up to 13 characters, and can consist of letters (A-Z), numbers (0-9),
/// and special characters like '@', '%', '*', etc.  Use the '#' symbol to display
/// a degree symbol.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_DisplayText(BSTR* Val)
{
	HRESULT hr = S_OK;

	CString resp;
	hr = InstrQueryCommand(resp, DEFAULT_STRING_LENGTH);
	resp.Remove('\"');
	resp.Remove('\'');

	*Val = resp.AllocSysString();
	return hr;
}

/// <summary>
///	Displays a message on the instrument's front panel display.  The message sent
/// can be up to 13 characters, and can consist of letters (A-Z), numbers (0-9),
/// and special characters like '@', '%', '*', etc.  Use the '#' symbol to display a degree symbol.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_put_DisplayText(BSTR Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Reads the data from the channel currently selected for the Monitor mode
/// or from the internal DMM. One reading is returned each time this property is called.
/// </summary>
/// <remarks>
///	Returns the reading only. The units, time, channel, and alarm information is not returned. 
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_MonitorData(double* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Disables or enables the Monitor mode. 
/// </summary>
/// <remarks>
///	The Monitor mode is equivalent to making continuous 
/// measurements on a single channel with an infinite scan count. Only one channel can be monitored 
/// at a time but you can change the channel being monitored at any time. 
/// This feature is useful for troubleshooting your system before a test or for watching an important signal.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_MonitorEnable(VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	CString sResp;
	hr = InstrQueryCommand(sResp, MAX_BOOL_STRING);
	if( sResp=="+1" || sResp=="1" ) // we have +1 or +0 answered, not 1 or 0
		*Val = VARIANT_TRUE;
	else if( sResp=="+0" || sResp=="0" ) // we have +1 or +0 answered, not 1 or 0
		*Val = VARIANT_FALSE;
	else
		return ReportError( IDS_E_IVI_UNEXPECTED_RESPONSE );
	return hr;

	return hr;
}

/// <summary>
///	Disables or enables the Monitor mode. 
/// </summary>
/// <remarks>
///	The Monitor mode is equivalent to making continuous 
/// measurements on a single channel with an infinite scan count. Only one channel can be monitored 
/// at a time but you can change the channel being monitored at any time. 
/// This feature is useful for troubleshooting your system before a test or for watching an important signal.
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_put_MonitorEnable(VARIANT_BOOL Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Selects whether the Monitor mode uses a channel on one of the modules listed below or the internal DMM.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_MonitorMode(Agilent34980AMonitorModeEnum* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandEnum(Val);

	return hr;
}

/// <summary>
///	Selects whether the Monitor mode uses a channel on one of the modules listed below or the internal DMM.
/// </summary>
/// <remarks>
///	
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_put_MonitorMode(Agilent34980AMonitorModeEnum Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Disables or enables the Monitor mode on the specified channels
/// without modifying the active 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::IAgilent34980ADisplay_get_EnableMonitorChan(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("IAgilent34980ADisplay_get_MonitorEnable"), _T("ChannelList"));
	}
	CorrectChannelList( ChannelList, false );
	CString sResp;
	hr = InstrQueryCommand( sResp, DEFAULT_STRING_LENGTH );
	if( FAILED(hr) ) return hr;
	sResp.Remove( '+' );
	sResp.Remove( '\n' );
	if( sResp=='1' )
		*Val = VARIANT_TRUE;
	else if( sResp=='0' )
		*Val = VARIANT_FALSE;
	else return ReportError( IDS_E_IVI_UNEXPECTED_RESPONSE );

	return hr;
}


/// <summary>
///	Disables or enables the Monitor mode on the specified channels.
/// without modifying the active 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::IAgilent34980ADisplay_put_EnableMonitorChan(BSTR ChannelList, VARIANT_BOOL Val)
{
	HRESULT hr = S_OK;

	CorrectChannelList( ChannelList );

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Selects the channel to be displayed on the front panel in the Monitor mode.
/// Only one channel can be monitored at a time.
/// </summary>
/// <remarks>
///	Channels do not have to be part of an active scan list to be monitored; however,
///  the channel must be configured for a measurement in order to be monitored (see
///  CONFigure and SENSe commands).
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_get_SelectMonitorChan(BSTR* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}


/// <summary>
///	Selects the channel to be displayed on the front panel in the Monitor mode.
/// Only one channel can be monitored at a time.
/// </summary>
/// <remarks>
///	Channels do not have to be part of an active scan list to be monitored; however,
///  the channel must be configured for a measurement in order to be monitored (see
///  CONFigure and SENSe commands).
/// </remarks>
HRESULT Agilent34980A::IAgilent34980ADisplay_put_SelectMonitorChan(BSTR Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
/// Sets Monitor mode to internal DMM.
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
HRESULT Agilent34980A::IAgilent34980ADisplay_MonitorDMM()
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
/// Sets Monitor mode to a channel on one of these modules: 34921A through 34925A Multiplexer Modules, 
/// 34950A Digital I/O Module (digital input and totalizer channels only) and 34952A Multifunction Module (digital input and totalizer channels only).
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="Channel">
///	One channel in the form sccc.
/// </param>
HRESULT Agilent34980A::IAgilent34980ADisplay_MonitorChannel(BSTR Channel)
{
	HRESULT hr = S_OK;

	CString sList(Channel);
	if( -1 != sList.Find( ',' ) || -1!=sList.Find( ':' ) || -1 != sList.Find( '-' ) )
	{
		return ReportInvalidValueError( _T("IAgilent34980ADisplay_get_MonitorEnable"), _T("ChannelList"), sList );
	}
	hr = InstrPrintCommand();

	return hr;
}
