Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Novelec_MCCE2.cpp 9.80 KiB
// ============================================================================
//
// = CONTEXT
//    TANGO Project - NovelecElectrometer Support Library
//
// = FILENAME
//    Novelec_MCCE2.cpp
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <Xstring.h>
#include "NovelecProtocol.h"
#include "Novelec_MCCE2.h"


// ============================================================================
// Novelec_MCCE2::Novelec_MCCE2
// ============================================================================
Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address, unsigned short novTypeNumber)
:	AbstractElectrometerClass(comLink_device_name),
	_rangeLimit(0),
  _address(address),
	_MCCE2electroTypeNumber(novTypeNumber)
{
	//std::cout << "Novelec_MCCE2::Novelec_MCCE2 <-" << std::endl;

	//std::cout << "Novelec_MCCE2::Novelec_MCCE2 ->" << std::endl;
}

// ============================================================================
// Novelec_MCCE2::~Novelec_MCCE2
// ============================================================================
Novelec_MCCE2::~Novelec_MCCE2 (void)
{
	//std::cout << "Novelec_MCCE2::~Novelec_MCCE2 <-" << std::endl;

	//std::cout << "Novelec_MCCE2::~Novelec_MCCE2 ->" << std::endl;
}

// ============================================================================
// Novelec_MCCE2::init_protocol
// ============================================================================
bool Novelec_MCCE2::init_protocol (void)
{ 
  std::string description("");
  bool success = false;
  try
  {
	  //- build the keithley Electrometer protocol obj
	_electrometerProtocol = new NovelecProtocol(_device_proxy_name, _address, _MCCE2electroTypeNumber);
     
    if(_electrometerProtocol)
      success = _electrometerProtocol->build_communicationLink();
  }
  catch(Tango::DevFailed& df)
  {
		description = "FAILED to create proxy on : " + _device_proxy_name;
		
		Tango::Except::re_throw_exception (df,
			(const char*)"COMMUNICATION_ERROR",
			description.c_str(),
			(const char*)"Novelec_MCCE2::init_protocol");
  }
  catch(...)
  {
		description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...].";
		
		Tango::Except::throw_exception (
			(const char*)"COMMUNICATION_ERROR",
			description.c_str(),
			(const char*)"Novelec_MCCE2::init_protocol");
  }
  return success;
}

// ============================================================================
// Novelec_MCCE2::get_ElectroMeterPolarity
// ============================================================================
std::string Novelec_MCCE2::get_ElectroMeterPolarity (void)
{ 
	return _electrometerProtocol->get_polarity();	
}

// ============================================================================
// Novelec_MCCE2::set_ElectroMeterPolarity
// ============================================================================
void Novelec_MCCE2::set_ElectroMeterPolarity (std::string polarity)
{ 
	_electrometerProtocol->set_polarity(polarity);	
}

// ============================================================================
// Novelec_MCCE2::set_Zero_VonF_function
// ============================================================================
void Novelec_MCCE2::set_Zero_VonF_function (void)
{ 
	_electrometerProtocol->unable_zeroVF_func();	
}

// ============================================================================
// Novelec_MCCE2::set_Offset_function
// ============================================================================
void Novelec_MCCE2::set_Offset_ZeroV1_function (void)
{ 
	_electrometerProtocol->unable_offset_zeroV1_func();	
}

// ============================================================================
// Novelec_MCCE2::set_Leakage_ZeroV2_function
// ============================================================================
void Novelec_MCCE2::set_Leakage_ZeroV2_function (void)
{ 
	_electrometerProtocol->unable_leakage_zeroV2_func();	
}

// ============================================================================
// Novelec_MCCE2::set_Test_function
// ============================================================================
void Novelec_MCCE2::set_Test_function (void)
{ 
	_electrometerProtocol->unable_test_func();	
}

// ============================================================================
// Novelec_MCCE2::set_Measure_function
// ============================================================================
void Novelec_MCCE2::set_Measure_function (void)
{ 
	_electrometerProtocol->unable_measure_func();	
}
// ============================================================================
// Novelec_MCCE2::mcce_on
// ============================================================================
void Novelec_MCCE2::mcce_on (void)
{ 
	_electrometerProtocol->switch_MCCE2_ON();	
}

// ============================================================================
// Novelec_MCCE2::mcce_off
// ============================================================================
void Novelec_MCCE2::mcce_off (void)
{ 
	_electrometerProtocol->switch_MCCE2_OFF();	
}

// ============================================================================
// Novelec_MCCE2::electrometer_status
// ============================================================================
std::string Novelec_MCCE2::electrometer_status (void)
{ 
	std::string argout("");
	std::string typeStr(" ");
	std::string tmp(" ");
	short _status	= 0;
	short _errors	= 0;
	short _type		= 0;

	NovelecProtocol* _nproto = dynamic_cast<NovelecProtocol*>(_electrometerProtocol);
	if(!_nproto)
		throw electrometer::ElectrometerException("BAD_ALLOC", 
												"Memory allocation failed to query the electrmometer status.",
												"Novelec_MCCE2::electrometer_status( ).");
	
  /***********************************************************************
          DISABLED PART TO INCREASE SERIAL PERFORMANCE
	//- get Electrometer type :
	//try
	//{
	//	tmp		= _nproto->get_electrotype();
	//	_type	= XString<short>::convertFromString(tmp);
	//}
	//catch(...)
	//{
	//	set_electroState(FAULT);
	//	throw electrometer::ElectrometerException("INTERNAL_ERROR", 
	//											"Unable to query the electrmometer type.",
	//											"Novelec_MCCE2::electrometer_status( ).");
	//}

	//argout = "\n\nINFOS :\n";
	//argout += "----------\n";

	//switch(_type)
	//{
	//case 1 :	typeStr = "Photovoltaque UHS";
	//	break;
	//case 2 :	typeStr = "Photovoltaque HS";
	//	break;
	//case 3 :	typeStr = "Photovoltaque MS";
	//	break;
	//case 4 :	typeStr = "Photoconducteur HS";
	//	break;
	//case 5 :	typeStr = "Photoconducteur MS";
	//	break;
	//default :	set_electroState(FAULT);
	//			argout = "Invalid status string returned !";
	//			return argout;
	//}
	//argout += "Novelec type : " + typeStr + "\n";

	////- get Electrometer mode :
	//argout += "Novelec mode : " + _electrometerProtocol->get_mode() + "\n";
  
  ***********************************************************************/
	
	try
	{
		//- read novelec status from HW	
		tmp		= _electrometerProtocol->get_raw_status();
		_status	= XString<short>::convertFromString(tmp);
	}
	catch(...)
	{
		set_electroState(FAULT);
    argout = "Unable to query the electrometer status.";
    return argout;

		//throw electrometer::ElectrometerException("COMMUNICATION_ERROR", 
		//										"Unable to query the electrmometer status.",
		//										"Novelec_MCCE2::electrometer_status( ).");
	}

	argout += "\nStatus detail :\n";
	argout += "------------------------\n";

	//- build novelec status
	if(_status & 0x10)
		argout += "En mesure\n";
	else
		argout += "Hors mesure\n";
	if(_status & 0x20)
		argout += "Paramtres par defaut\n";
	else
		argout += "Ram OK\n";
	if(_status & 0x40)
		argout += "Paramtre invalide\n";
	else
		argout += "Paramtre OK\n";
	if(_status & 0x80)
	{
		argout += "ERREUR\n";
		set_electroState(ALARM);
	}
	else
	{
		argout += "Pas d'erreur\n";
		set_electroState(ON);
	}

	//- error(s) detail(s)
	if(_status & 0x80)
	{
		try
		{
			//- read novelec error(s) from HW
			tmp		= _nproto->get_errors();
			_errors	= XString<short>::convertFromString(tmp);
		}
		catch(...)
		{
			set_electroState(FAULT);
			throw electrometer::ElectrometerException("INTERNAL_ERROR", 
													"Unable to query the electrmometer errors.",
													"Novelec_MCCE2::electrometer_status( ).");
		}

		argout += "\nError(s) detail(s) :\n";
		argout += "------------------------\n";
		if(_errors & 0x01)
			argout += "Paramtre par dfaut\n";
		if(_errors & 0x02)
			argout += "Erreur srie\n";
		if(_errors & 0x04)
			argout += "Paramtre invalide\n";
		if(_errors & 0x08)
			argout += "Electromtre satur\n";
		if(_errors & 0x10)
			argout += "Electromtre bloqu\n";
		if(_errors & 0x20)
			argout += "HT < limite basse\n";
		if(_errors & 0x40)
			argout += "HT > limite haute\n";
		if(_errors & 0x80)
			argout += "Initialisation\n";
		if(_errors & 0x100)
			argout += "Dfaut batterie\n";
		if(_errors & 0x200)
			argout += "Dfaut d'alimentation\n";
		if(_errors & 0x400)
			argout += "Type d'lectromtre inconnu\n";
		if(_errors & 0x800)
			argout += "Electromtre dconnect\n";

		set_electroState(ALARM);
	}

	return argout;
}

// ============================================================================
// Novelec_MCCE2::check_range_value
// ============================================================================
short Novelec_MCCE2::check_range_value (const std::string& rgToCheck, const std::string* electroRangeList)
{ 
	for (unsigned int idx = 0; idx < _rangeLimit; idx++)
	{
		if(electroRangeList[idx].find(rgToCheck) != std::string::npos)
			//- value is in the list
			return idx;
	}

	//- new range value not found in the electrometer range list !
	return -1;
}