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

int Agilent34945A::CalculateBank( CString &chan )
{
	int bank = atoi( (LPCTSTR)chan );
	if( !bank ) return bank; // NAN passed?

	chan.Delete(2,2);
	chan.Insert( 0, "(@" );
	chan += "00)";
	bank = bank - (bank/100)*100;

	if( bank < 19 ) bank = 1;               // channel range is 01 to 18
	else if ( bank < 39 ) bank = 2;         // channel range is 21 to 38
	else if ( bank < 59 ) bank = 3;         // channel range is 41 to 58
	else if ( bank < 79 ) bank = 4;         // channel range is 41 to 58
	else  bank = 0;                         // out of range

	return bank;
}



/// <summary>
///	Configures the bank to drive its channels as either a TTL level or Open-collector
/// sink for the drive current.
/// </summary>
/// <remarks>
///	This property provides per-bank control of this behavior.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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>
/// <param name="Bank">
///	Specify an individual bank (1 to 4).
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_get_BankDriveType(BSTR RemoteModuleList, long Bank, Agilent34945ADriveTypeEnum* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommandEnum(val);

	return hr;
}



/// <summary>
///	Configures the bank to drive its channels as either a TTL level or Open-collector
/// sink for the drive current.
/// </summary>
/// <remarks>
///	This property provides per-bank control of this behavior.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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>
/// <param name="Bank">
///	Specify an individual bank (1 to 4).
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_put_BankDriveType(BSTR RemoteModuleList, long Bank, Agilent34945ADriveTypeEnum val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Disables or enables the LED drives on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The LED drives can be controlled on a per-bank basis.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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.
///	Single channel in the form sccc.
/// </param>
/// <param name="Bank">
///	Specify an individual bank (1 to 4)
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_get_BankLEDEnable(BSTR RemoteModuleList, long Bank, VARIANT_BOOL* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommandBool(val);

	return hr;
}

/// <summary>
///	Disables or enables the LED drives on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The LED drives can be controlled on a per-bank basis.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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.
///	Single channel in the form sccc.
/// </param>
/// <param name="Bank">
///	Specify an individual bank (1 to 4)
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_put_BankLEDEnable(BSTR RemoteModuleList, long Bank, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Sets or gets the current level for the LED drives on the specified 34945EXT remote module.
/// </summary>
/// <remarks>
///	The current level can be varied at the bank level, which allows you to vary the LED brightness for each bank.
/// The current level is specified in Amps.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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>
/// <param name="Bank">
///	Specify an individual bank (1 to 4)
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_get_BankLEDDriveLevel(BSTR RemoteModuleList, long Bank, double* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommand(val);

	return hr;
}



/// <summary>
///	Sets or gets the current level for the LED drives on the specified 34945EXT remote module.
/// </summary>
/// <remarks>
///	The current level can be varied at the bank level, which allows you to vary the LED brightness for each bank.
/// The current level is specified in Amps.
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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>
/// <param name="Bank">
///	Specify an individual bank (1 to 4)
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_put_BankLEDDriveLevel(BSTR RemoteModuleList, long Bank, double val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
/// Sets the preset values on the specified bank.
/// </summary>
/// <remarks>
/// This method immediately reconfigures the specified bank on the 34945A Microwave Switch/Attenuator Driver 
/// to a preset state. The preset configuration is a predefined state for each Distribution Board type in use. 
/// See the Agilent 34980A User's Guide for more information on the preset state for each Distribution Board. 
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\r\n
/// s: Mainframe slot number (1 through 8)\r\n
/// r: 34945EXT remote module (1 through 8)\r\n
/// </param>
/// <param name="Bank">
///	Specify an individual bank (1 to 4).
/// </param>
HRESULT Agilent34945A::IAgilent34945AModule_BankPreset(BSTR RemoteModuleList, long Bank)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Sets or gets the number of simultaneous coil drive activations to be allowed on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	By specifying a value greater than one drive, you can improve cumulative switching times by allowing the 
/// 34945EXT to overlap channel drives. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_get_DriveChannelLimit(BSTR RemoteModuleList, long* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommand(val);

	return hr;
}


/// <summary>
///	Sets or gets the number of simultaneous coil drive activations to be allowed on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	By specifying a value greater than one drive, you can improve cumulative switching times by allowing the 
/// 34945EXT to overlap channel drives. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_put_DriveChannelLimit(BSTR RemoteModuleList, long val)
{
	HRESULT hr = S_OK;

	hr = hr = InstrPrintCommand();

	return hr;
}




/// <summary>
///	Sets or gets the power source for driving channels on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The INTernal source is available only for the 34945EXT Master module, which can be powered directly by the 34980A. 
/// Each of the 34945EXT Slave modules must be powered by an EXTernal source that you apply to the module. 
/// For more information on connecting an external power source to the module, see the Agilent 34980A User's Guide. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_get_DriveSource(BSTR RemoteModuleList, Agilent34945ADriveSourceEnum* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommandEnum(val);

	return hr;
}




/// <summary>
///	Sets or gets the power source for driving channels on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The INTernal source is available only for the 34945EXT Master module, which can be powered directly by the 34980A. 
/// Each of the 34945EXT Slave modules must be powered by an EXTernal source that you apply to the module. 
/// For more information on connecting an external power source to the module, see the Agilent 34980A User's Guide. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_put_DriveSource(BSTR RemoteModuleList, Agilent34945ADriveSourceEnum val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Sets or gets the power source to be used following the next boot (power) cycle or Factory Reset (*RST command) on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The INTernal source is available only for the 34945EXT Master module, which can be powered directly by the 34980A. 
/// Each of the 34945EXT Slave modules must be powered by an EXTernal source that you apply to the module. 
/// For more information on connecting an external power source to the module, see the Agilent 34980A User's Guide. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_get_DriveSourceBootState(BSTR RemoteModuleList, Agilent34945ADriveSourceEnum* val)
{
	HRESULT hr = S_OK;

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

	hr = InstrQueryCommandEnum(val);

	return hr;
}


/// <summary>
///	Sets or gets the power source to be used following the next boot (power) cycle or Factory Reset (*RST command) on the specified 34945EXT remote module connected to the 34945A Microwave Switch/Attenuator Driver.
/// </summary>
/// <remarks>
///	The INTernal source is available only for the 34945EXT Master module, which can be powered directly by the 34980A. 
/// Each of the 34945EXT Slave modules must be powered by an EXTernal source that you apply to the module. 
/// For more information on connecting an external power source to the module, see the Agilent 34980A User's Guide. 
/// </remarks>
/// <param name="RemoteModuleList">
///	One or more remote module identifiers in the form sr00.\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::IAgilent34945AModule_put_DriveSourceBootState(BSTR RemoteModuleList, Agilent34945ADriveSourceEnum val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}
