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



/// <summary>
/// Configures the channel subsystem.
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
/// <param name="Paired">
///	OFF for 1-coil drive, ON for SP2T 2-coil operation.
/// </param>
/// <param name="PulseMode">
///	Pulsed or Continuous mode.
/// </param>
/// <param name="PulseWidth">
///	Pulse width.
/// </param>
/// <param name="RecoveryTime">
///	Recovery time.
/// </param>
/// <param name="SettleTime">
///	Settling time.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_Configure(BSTR ChannelList, VARIANT_BOOL Paired, VARIANT_BOOL PulseMode, double PulseWidth, double RecoveryTime, double SettleTime)
{
	HRESULT hr = S_OK;

	hr = _IAgilent34945AChannel::put_RecoveryTime(ChannelList, RecoveryTime);
	if (FAILED(hr)) return hr;

	hr = _IAgilent34945AChannel::put_SettleTime(ChannelList, SettleTime);
	if (FAILED(hr)) return hr;

	hr = _IAgilent34945AChannel::put_PulseWidth(ChannelList, PulseWidth);
	if (FAILED(hr)) return hr;

	hr = _IAgilent34945AChannel::put_PairedMode(ChannelList, Paired);
	if (FAILED(hr)) return hr;

	hr = _IAgilent34945AChannel::put_PulseMode(ChannelList, PulseMode);
	if (FAILED(hr)) return hr;

	return hr;
}

/// <summary>
/// Closes the specified channels on a multiplexer or switch module.
/// </summary>
/// <remarks>
/// On the multiplexer modules, if any channel in a bank is defined to be part of
/// the scan list, attempting to close another channel (including Analog Bus channels)
/// within the same bank will result in an error. Channel closures in the other
/// bank are allowed as long as no channels are part of the scan list; however,
/// Analog Bus relay closures are not allowed.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_Close(BSTR ChannelList)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
/// Opens the specified channels on a multiplexer or switch module.
/// </summary>
/// <remarks>
/// The RF Multiplexer modules (34941A, 34942A) and Microwave Switch modules (34946A,
/// 34947A) do not respond to the ROUTe:OPEN commands. To "open" a channel, send
/// the ROUTe:CLOSe command to another channel in the same bank.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_Open(BSTR ChannelList)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Returns the current drive state of the specified channels on the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	This method is provided specifically for the verified, single-coil, non-pulsed channel drive configuration, 
/// where the results from the ROUTe:CLOSe? command cannot reliably report the current drive state. 
/// The response from this method indicates whether or not the specified channels are currently being driven. 
/// </remarks>
/// <param name="ChannelList">
///	A single channel in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_DriveState(BSTR ChannelList, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_DriveState"), _T("ChannelList"));
	}

	hr = InstrQueryCommandBool(val);

	return hr;
}


/// <summary>
///	Sets or gets the mode for drive pairing.
/// </summary>
/// <remarks>
/// When enabled (True), the module automatically pairs channel n (as specified by this command) 
/// with channel n+10 for single-pole, two-coil (SP2T) operations. When disabled (False), the specified 
/// channels are configured for non-paired one-coil (SPST) operations.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For paired operations, channel n is automatically paired with channel n+10 
/// (e.g., 01 with 11, 21 with 31, 41 with 51, etc.). With this method, specify the lower numbered channel in the pair.\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_PairedMode(BSTR ChannelList, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_PairedMode"), _T("ChannelList"));
	}

	hr = InstrQueryCommandBool(val);

	return hr;
}


/// <summary>
///	Sets or gets the mode for drive pairing.
/// </summary>
/// <remarks>
/// When enabled (True), the module automatically pairs channel n (as specified by this command) 
/// with channel n+10 for single-pole, two-coil (SP2T) operations. When disabled (False), the specified 
/// channels are configured for non-paired one-coil (SPST) operations.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For paired operations, channel n is automatically paired with channel n+10 
/// (e.g., 01 with 11, 21 with 31, 41 with 51, etc.). With this method, specify the lower numbered channel in the pair.\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_PairedMode(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Sets or gets a value indicating whether the channel drive is Pulsed or Continuous.
/// </summary>
/// <remarks>
/// This method enables (True) or disables (False) the pulsed drive mode on the specified channels 
/// on the 34945A Microwave Switch/Attenuator Driver. When the pulsed mode is disabled, the continuous 
/// drive mode is enabled (sometimes referred to as the level control mode). The continuous drive mode 
/// is useful for driving non-latching devices.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_PulseMode(BSTR ChannelList, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_PulseMode"), _T("ChannelList"));
	}

	hr = InstrQueryCommandBool(val);

	return hr;
}


/// <summary>
///	Sets or gets a value indicating whether the channel drive is Pulsed or Continuous.
/// </summary>
/// <remarks>
/// This method enables (True) or disables (False) the pulsed drive mode on the specified channels 
/// on the 34945A Microwave Switch/Attenuator Driver. When the pulsed mode is disabled, the continuous 
/// drive mode is enabled (sometimes referred to as the level control mode). The continuous drive mode 
/// is useful for driving non-latching devices.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_PulseMode(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the coil drive pulse width duration.
/// </summary>
/// <remarks>
///	Applies only if Pulse mode is enabled. Pulse width of 0 may not be configured
/// to prevent the situation where user sets a minimum value and gets no pulse at all, thinking
/// the the drive is not operational.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_PulseWidth(BSTR ChannelList, double* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_PulseWidth"), _T("ChannelList"));
	}

	hr = InstrQueryCommand(val);

	return hr;
}

/// <summary>
///	Sets or gets the coil drive pulse width duration.
/// </summary>
/// <remarks>
///	Applies only if Pulse mode is enabled. Pulse width of 0 may not be configured
/// to prevent the situation where user sets a minimum value and gets no pulse at all, thinking
/// the the drive is not operational.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_PulseWidth(BSTR ChannelList, double val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the minimum recovery time for the channel drive power source, prior
/// to driving another channel.
/// </summary>
/// <remarks>
/// The specified recovery time is inserted prior to driving a channel. 
/// For pulsed operations, the recovery time begins with the falling edge of the drive pulse. 
/// For non-pulsed (continuous) operations, the recovery time begins with the initiation of the drive signal. 
/// See the Agilent 34980A User's Guide for more information.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_RecoveryTime(BSTR ChannelList, double* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_RecoveryTime"), _T("ChannelList"));
	}

	hr = InstrQueryCommand(val);

	return hr;
}

/// <summary>
///	Sets or gets the minimum recovery time for the channel drive power source, prior
/// to driving another channel.
/// </summary>
/// <remarks>
/// The specified recovery time is inserted prior to driving a channel. 
/// For pulsed operations, the recovery time begins with the falling edge of the drive pulse. 
/// For non-pulsed (continuous) operations, the recovery time begins with the initiation of the drive signal. 
/// See the Agilent 34980A User's Guide for more information.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_RecoveryTime(BSTR ChannelList, double val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
/// Sets or gets a settling time on the specified channels on the 34945A Microwave Switch/Attenuator Driver
/// </summary>
/// <remarks>
/// For pulsed operations, the settling time begins with the falling edge of the drive pulse. 
/// For non-pulsed (continuous) operations, the settling time begins with the initiation of the drive signal.
/// See the Agilent 34980A User's Guide for more information.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_SettleTime(BSTR ChannelList, double* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_RecoveryTime"), _T("ChannelList"));
	}

	hr = InstrQueryCommand(val);

	return hr;
}

/// <summary>
///	Sets or gets an additional period of time imposed by the 34945EXT hardware following
/// driving the channel before the switch operation is considerd complete (channel
/// is busy until this time elapses).
/// </summary>
/// <remarks>
///	To avoid several settings conflicts that result if the Settling Time is defined
/// to always begin at the onset of driving a channel, the following two Settling
/// time definitions exist depending on whether the drive is Pulsed or Continuous.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_SettleTime(BSTR ChannelList, double val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Sets ore gets the verification state for the specified channel(s).
/// </summary>
/// <remarks>
/// This property enables (True) or disables (False) verification, 
/// which senses the actual hardware state of the specified channels following a close or open operation. 
/// By default, verification is disabled because not all external microwave devices have verify lines 
/// and verification will slow switching performance.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_VerificationEnable(BSTR ChannelList, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_VerificationEnable"), _T("ChannelList"));
	}

	hr = InstrQueryCommandBool(val);

	return hr;
}


/// <summary>
///	Sets ore gets the verification state for the specified channel(s).
/// </summary>
/// <remarks>
/// This property enables (True) or disables (False) verification, 
/// which senses the actual hardware state of the specified channels following a close or open operation. 
/// By default, verification is disabled because not all external microwave devices have verify lines 
/// and verification will slow switching performance.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_VerificationEnable(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the logic polarity of the verification lines on the specified channels.
/// </summary>
/// <remarks>
///	You can specify the polarity as "normal" (active high) or "inverted" (active low). 
/// Depending on the external microwave device connected, the specified polarity will be found on 
/// the verification lines when the verified state is asserted. 
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_VerificationPolarity(BSTR ChannelList, Agilent34945APolarityEnum* val)
{
	HRESULT hr = S_OK;

	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_VerificationPolarity"), _T("ChannelList"));
	}

	hr = InstrQueryCommandEnum(val);

	return hr;
}

/// <summary>
///	Sets or gets the logic polarity of the verification lines on the specified channels.
/// </summary>
/// <remarks>
///	You can specify the polarity as "normal" (active high) or "inverted" (active low). 
/// Depending on the external microwave device connected, the specified polarity will be found on 
/// the verification lines when the verified state is asserted. 
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_VerificationPolarity(BSTR ChannelList, Agilent34945APolarityEnum val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}




/// <summary>
/// Sets or gets the default state of the specified channels.
/// </summary>
/// <remarks>
/// This property configures the specified channels on the 34945A Microwave Switch/Attenuator Driver 
/// to assume a default state of closed (True) or open (False) following the next boot (power) cycle, 
/// Factory Reset (*RST command), or when the drive source is changed. 
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_StateAtReset(BSTR ChannelList, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;
	
	CString strList(ChannelList);
	if (strList.Find(',') != -1 || strList.Find(':') != -1 || strList.Find('-') != -1) // means more than 1 channel
	{
		return ReportError( E_AGILENT34945A_MULTIPLE_CHANNELS_IN_GET, _T("IAgilent34945AChannel_get_StateAtReset"), _T("ChannelList"));
	}

	long lResult;
	hr = InstrQueryf(_T("ROUT:CHAN:DRIV:CLOS:DEF? (@%s)"), &lResult, COLE2T(ChannelList));
	if (SUCCEEDED(hr))
	{
		*val = (lResult == 1) ? VARIANT_TRUE : VARIANT_FALSE;
	}

	return hr;
}



/// <summary>
/// Sets or gets the default state of the specified channels.
/// </summary>
/// <remarks>
/// This property configures the specified channels on the 34945A Microwave Switch/Attenuator Driver 
/// to assume a default state of closed (True) or open (False) following the next boot (power) cycle, 
/// Factory Reset (*RST command), or when the drive source is changed. 
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form srcc.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// For the getter, only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_put_StateAtReset(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	if (val != VARIANT_FALSE)
	{
		hr = InstrPrintf(_T("ROUT:CHAN:DRIV:CLOS:DEF (@%s)"), COLE2T(ChannelList));
	}
	else
	{
		hr = InstrPrintf(_T("ROUT:CHAN:DRIV:OPEN:DEF (@%s)"), COLE2T(ChannelList));
	}

	return hr;
}

/// <summary>
///	Returns the state of the specified channel.
/// </summary>
/// <remarks>
///	True => channel is closed.\r\n
/// False => channel is closed.
/// </remarks>
/// <param name="Channel">
///	Channel number in the form sccc.  Only a single channel may be specified.
/// </param>
HRESULT Agilent34945A::IAgilent34945AChannel_get_IsClosed(BSTR Channel, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandBool(val);

	return hr;
}
