// ============================================================================
//
// = CONTEXT
//    TANGO Project - Keithley Electrometer Support Library
//
// = FILENAME
//    TangoSerialLink.h
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

#ifndef _TANGO_SERIAL_LINK_H_
#define _TANGO_SERIAL_LINK_H_

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <tango.h>
//#include <DeviceProxyHelper.h>
#include "CommunicationLink.h"

/**
 *  \addtogroup Communication Management
 *  @{
 */

/**
 *  \brief This class manage the SERIAL communication bus
 *
 *  \author Xavier Elattaoui
 *  \date 11-2006
 */

class TangoSerialLink : public CommunicationLink
{
	
public :
 	/**
	* \brief Initialization. 
	*/
	TangoSerialLink (std::string& serial_device_name);
	
	/**	
	* \brief Release resources.
	*/
	~TangoSerialLink ();

  /**
  * \brief One MCCE-2 can manage two differents electrometers
  *   through only one serial line !
  *
  */
  //static TangoSerialLink* get_instance(std::string& serial_device_name);

  //static void delete_instance(CommunicationLink*);
	
	/**
	*  \brief Send command (data) as string to hardware.
	*
	*  \throws Tango::DevFailed
	*/
	void write(std::string cmd)	 throw (Tango::DevFailed);

	/**
	*  \brief Gets hardware response as string. (mode LINE)
	*
	*  \throws Tango::DevFailed
	*/
	std::string read(void)		 throw (Tango::DevFailed);

	/**
	*  \brief Gets hardware response as string. (read nbCharToRead)
	*
	*  \throws Tango::DevFailed
	*/
	std::string read(long nbCharToRead)		 throw (Tango::DevFailed);

	/**
	*  \brief Performs a write read operation as string. (read in mode LINE)
	*
	*  \throws Tango::DevFailed
	*/
	std::string write_read(std::string cmd)  throw (Tango::DevFailed);

	/**
	*  \brief Performs a write read operation as string. (read nb char)
	*
	*  \throws Tango::DevFailed
	*/
	std::string write_read(std::string cmd, long nbChar)  throw (Tango::DevFailed);

private :

	/**	
	* \brief Tango Serial Link instance.
	*/
  //static TangoSerialLink* tsl_Instance;

  /**
	* Creates a proxy on the specified Serial Device.
	*/
	void create_serial_proxy(void) throw (Tango::DevFailed);
  
	//Tango::DeviceProxyHelper* _serial_proxy;
	Tango::DeviceProxy* _serial_proxy;

	bool _is_serial_proxy_created;
	
	std::string response;

};

/** @} */	//- end addtogroup

#endif // _TANGO_SERIAL_LINK_H_