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




/// <summary>
/// Configures the specified digital input or output channels for the desired width.
/// </summary>
/// <remarks>
/// 
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="Mode">
///	Digital Mode.
/// </param>
/// <param name="Direction">
///	Direction - Input or Output.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_Configure(BSTR ChannelList, Agilent34952ADigitalModeEnum Mode, Agilent34952ADirectionEnum Direction)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
/// Returns the last 8-bit (byte) value written to the specified output channels.
/// </summary>
/// <remarks>
/// If this command is sent to an input channel, the value returned will be:\r\n
/// 0 if the input has not been an output since the last reset\r\n
/// or\r\n
/// the last byte value sent when the channel was previously configured as an  output
/// channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_QueryLastByte(BSTR ChannelList, BYTE* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
/// Returns the last 16-bit value written to the specified output channels (specified
/// channel must be either the first channel or third channel on the module).
/// </summary>
/// <remarks>
/// Each word query involves 2 channels; note that if either of the two channels
/// involved in a word query are presently configured as inputs, this command will
/// return:\r\n
/// 0 if the input has not been an output since the last reset\r\n
///  or\r\n
/// the last byte value sent when the channel was previously configured as an  output
/// channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_QueryLastWord(BSTR ChannelList, short* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}




/// <summary>
/// Reads the value of the specified bit location (0 through 31) on the specified
/// digital input channels and sends the results directly to the instrument output
/// buffer.
/// </summary>
/// <remarks>
/// Each bit read involves 1 channel; note that if any of the specified channels
/// are presently configured as outputs, this command will return the last value
/// output on the specified bit from those channels (the channels are not reconfigured
/// as inputs).
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="BitNumber">
///	The bit number can vary from 0 to the maximum bit that the channel is capable
/// of, as determined by its present width setting (i.e. Byte, Word, LongWord):\r\n
/// Channel 01: BitNumber can range from 0 to 31\r\n
/// Channel 02: BitNumber can range from 0 to 7\r\n
/// Channel 03: BitNumber can range from 0 to 15\r\n
/// Channel 04: BitNumber can range from 0 to 7
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_ReadBit(BSTR ChannelList, long BitNumber, VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandBool(Val);

	return hr;
}



/// <summary>
/// Performs an 8-bit read on the specified digital input channels and sends the
/// results directly to the instrument's output buffer.
/// </summary>
/// <remarks>
/// Each byte read involves 1 channel; note that if any of the specified channels
/// are presently configured as outputs, this command will return the last value
/// output from those channels (the channels are not reconfigured as inputs).
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_ReadByte(BSTR ChannelList, BYTE* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
/// Performs a 16-bit read on the specified digital input channel (specified channel
/// must be either the first channel or third channel on the module) and sends the
/// results directly to the instrument's output buffer.
/// </summary>
/// <remarks>
/// Each word read involves 2 channels; note that if either of the two channels
/// involved in a word read are presently configured as outputs, this command will
/// return the last value output from those channels (the channels are not reconfigured
/// as inputs).
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_ReadWord(BSTR ChannelList, short* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
/// Performs a 32-bit read on the specified digital input channel (specified channel
/// must be the first channel on a bank of 4 channels) and sends the results directly
/// to the instrument's output buffer.
/// </summary>
/// <remarks>
/// Each long word read involves 4 channels; note that if any of the four channels
/// involved in a long word read are presently configured as outputs, this command
/// will return the last value output from those channels (the channels are not
/// reconfigured as inputs).
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_ReadLongWord(BSTR ChannelList, long* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}




/// <summary>
/// Sets or clears individual bits on the specified digital output channels.
/// </summary>
/// <remarks>
/// If an input channel is specified in the list, that channel is reconfigured to
/// be an output channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="BitNumber">
///	The bit number can vary from 0 to the maximum bit that the channel is capable
/// of, as determined by its present width setting (i.e. Byte, Word, LongWord):\r\n
/// Channel 01: BitNumber can range from 0 to 31\r\n
/// Channel 02: BitNumber can range from 0 to 7\r\n
/// Channel 03: BitNumber can range from 0 to 15\r\n
/// Channel 04: BitNumber can range from 0 to 7
/// </param>
/// <param name="Data">
///	A value of 0 or 1 to be written.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_WriteBit(BSTR ChannelList, long BitNumber, long Data)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}




/// <summary>
/// Outputs the specified 8-bit (byte) value on the specified digital output channels.
/// </summary>
/// <remarks>
/// If an input channel is specified in the list, that channel is reconfigured to
/// be an output channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="Data">
///	A data byte to be written.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_WriteByte(BSTR ChannelList, BYTE Data)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}




/// <summary>
/// Outputs the specified 16-bit pattern on the specified digital output channels
/// (must be either first or third channel on a module).
/// </summary>
/// <remarks>
/// Each word write involves 2 channels; note that if either of the two channels
/// involved in a word write are presently configured as inputs, they will be reconfigured
/// to be an output channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="Data">
///	Data to be written.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_WriteWord(BSTR ChannelList, short Data)
{
	HRESULT hr = S_OK;

	hr = InstrPrintf( "SOUR:DIG:DATA:WORD #H%X, (@%s)", (USHORT)Data, LPCTSTR(COLE2T(ChannelList)) );

	return hr;
}



/// <summary>
/// Outputs the specified 32-bit pattern on the specified digital output channels
/// (must be the first channel on a bank of 4 channels).
/// </summary>
/// <remarks>
/// Each long word write involves 4 channels; note that if any of the four channels
/// involved in a word write are presently configured as inputs, they will be reconfigured
/// to be an output channel.
/// </remarks>
/// <returns>
///	
/// </returns>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
/// <param name="Data">
///	Data to be written.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_WriteLongWord(BSTR ChannelList, long Data)
{
	HRESULT hr = S_OK;

	hr = InstrPrintf( "SOUR:DIG:DATA:LWOR #H%X, (@%s)", (ULONG)Data, LPCTSTR(COLE2T(ChannelList)) );

	return hr;
}


/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonData(BSTR ChannelList, BYTE* Val)
{
	HRESULT hr = S_OK;

	// FogBugz # 1158
	return E_NOTIMPL;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonData(BSTR ChannelList, BYTE val)
{
	HRESULT hr = S_OK;

	// FogBugz # 1158
	return E_NOTIMPL;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Disables or enables the pattern comparison mode on the digital modules. This
/// command applies to digital input operations on the specified bank (DIO1 or DIO2).
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonEnable(BSTR ChannelList, VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}



/// <summary>
///	Disables or enables the pattern comparison mode on the digital modules. This
/// command applies to digital input operations on the specified bank (DIO1 or DIO2).
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonEnable(BSTR ChannelList, VARIANT_BOOL val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Sets or gets mask bit pattern for specified channels.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonMask(BSTR ChannelList, long* Val)
{
	HRESULT hr = S_OK;

	// FogBugz # 1158
	return E_NOTIMPL;

	hr = InstrQueryCommand(Val);

	return hr;
}


/// <summary>
///	Sets or gets mask bit pattern for specified channels.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonMask(BSTR ChannelList, long Val)
{
	HRESULT hr = S_OK;

	// FogBugz # 1158
	return E_NOTIMPL;

	hr = InstrPrintCommand();

	return hr;
}



/// <summary>
///	Sets or gets the comparison type used on the specified channels.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonType(BSTR ChannelList, Agilent34952AComparisonTypeEnum* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommandEnum(Val);

	return hr;
}



/// <summary>
///	Sets or gets the comparison type used on the specified channels.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonType(BSTR ChannelList, Agilent34952AComparisonTypeEnum val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Returns the present state (INPut or OUTput) of the specified channel.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc: digital input/output
/// channels only.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_State( BSTR ChannelList, VARIANT_BOOL* Val)
{
	HRESULT hr = S_OK;

	// FogBugz # 1160
	return E_NOTIMPL;

	hr = InstrQueryCommandBool(Val);

	return hr;
}

/// <summary>
///	Sets or gets the state of the channel - input or output.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc. Must be single
/// entry for the getter. For 34952A - channels s001 through s004
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_Direction(BSTR ChannelList, Agilent34952ADirectionEnum* Val)
{
	HRESULT hr = S_OK;
	
	hr = InstrQueryCommandEnum(Val);

	return hr;
}

/// <summary>
///	Sets or gets the state of the channel - input or output.
/// </summary>
/// <remarks>
///	
/// </remarks>
/// <param name="ChannelList">
///	One or more digital input or output channels in the form sccc. Must be single
/// entry for the getter. For 34952A - channels s001 through s004
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_Direction(BSTR ChannelList, Agilent34952ADirectionEnum Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}


/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonDataByte(BSTR ChannelList, BYTE* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}


/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonDataByte(BSTR ChannelList, BYTE Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonDataWord(BSTR ChannelList, short* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonDataWord(BSTR ChannelList, short Val)
{
	HRESULT hr = S_OK;

	if( Val<0 )
		hr = InstrPrintf( "CALC:COMP:DATA:WORD #H%X, (@%s)", (USHORT)Val, LPCTSTR(COLE2T(ChannelList)) );
	else
		hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonDataLongWord(BSTR ChannelList, long* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonDataLongWord(BSTR ChannelList, long Val)
{
	HRESULT hr = S_OK;

	if( Val<0 ) // send negative values as HEX
		hr = InstrPrintf( "CALC:COMP:DATA:LWOR #H%X, (@%s)", (ULONG)Val, LPCTSTR(COLE2T(ChannelList)) );
	else
		hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonMaskByte(BSTR ChannelList, BYTE* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonMaskByte(BSTR ChannelList, BYTE Val)
{
	HRESULT hr = S_OK;

	hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonMaskWord(BSTR ChannelList, short* Val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(Val);

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonMaskWord(BSTR ChannelList, short Val)
{
	HRESULT hr = S_OK;

	if( Val<0 )
		hr = InstrPrintf( "CALC:COMP:MASK:WORD #H%X, (@%s)", (USHORT)Val, LPCTSTR(COLE2T(ChannelList)) );
	else
		hr = InstrPrintCommand();

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_get_ComparisonMaskLongWord(BSTR ChannelList, long* val)
{
	HRESULT hr = S_OK;

	hr = InstrQueryCommand(val);

	return hr;
}

/// <summary>
///	Sets or gets the data bit pattern for comparisons on the digital modules.
/// </summary>
/// <remarks>
///	Used in conjunction with seting the mask bit pattern. Applies to digital input
/// operations on the specified bank (DIO1 or DIO2). Pattern matching always starts
/// on the lowest-numbered channel in the bank.
/// </remarks>
/// <param name="ChannelList">
///	One or more channels in the form sccc.
/// </param>
HRESULT Agilent34952A::IAgilent34952ADigital_put_ComparisonMaskLongWord(BSTR ChannelList, long val)
{
	HRESULT hr = S_OK;

	if( val<0 )
		hr = InstrPrintf( "CALC:COMP:MASK:LWOR #H%X, (@%s)", (ULONG)val, LPCTSTR(COLE2T(ChannelList)) );
	else
		hr = InstrPrintCommand();

	return hr;
}
