Skip to content
Snippets Groups Projects
N_PhotoConducteur.cpp 6.94 KiB
Newer Older
LE's avatar
LE committed
// ============================================================================
//
// = CONTEXT
//    TANGO Project - NovelecElectrometer Support Library
//			PhotoConducteur Types are Type 4 & 5 only
//
// = FILENAME
//    N_PhotoConducteur.cpp
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <Xstring.h>
LE's avatar
LE committed
#include "N_PhotoConducteur.h"
#include "NovelecProtocol.h"
/*
* Valid Range values for a N_PhotoConducteur
*/
ELATTAOUI's avatar
ELATTAOUI committed
static const std::vector<std::string> NType4_rangeValue {"100","30","10","3"};			//- MOhms
static const std::vector<std::string> NType5_rangeValue {"1000","300","100","30"};	//- KOhms
LE's avatar
LE committed


// ============================================================================
// N_PhotoConducteur::N_PhotoConducteur
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short address)
:	Novelec_MCCE2(comLink_device_name, address)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoConducteur::N_PhotoConducteur <-" << std::endl;
LE's avatar
LE committed

	_rangeLimit = 3;
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoConducteur::N_PhotoConducteur ->" << std::endl;
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoConducteur::~N_PhotoConducteur
// ============================================================================
N_PhotoConducteur::~N_PhotoConducteur (void)
{
ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoConducteur::~N_PhotoConducteur <-" << std::endl;
LE's avatar
LE committed

ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoConducteur::~N_PhotoConducteur ->" << std::endl;
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoConducteur::range_up
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoConducteur::range_up (void)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoConducteur::range_up( ).");
LE's avatar
LE committed

std::stringstream cmd_to_send;

	_range += 1;

	if(_range > _rangeLimit)
	{
		_range = _rangeLimit;
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("OUT_OF_RANGE",
LE's avatar
LE committed
												"Range up limit reached.",
												"N_PhotoConducteur::range_up( ).");
	}

	//- build and send the command
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << _range;
LE's avatar
LE committed
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoConducteur::range_down
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoConducteur::range_down (void)
LE's avatar
LE committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoConducteur::range_down( ).");
LE's avatar
LE committed

std::stringstream cmd_to_send;

	_range -= 1;

	if(_range < 0)
	{
		_range = 0;
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("OUT_OF_RANGE",
LE's avatar
LE committed
												"Range down limit reached.",
												"N_PhotoConducteur::range_down( ).");
	}

	//- build and send the command
//	_rangeStr = NType1_rangeValue[_range];
ELATTAOUI's avatar
ELATTAOUI committed
	cmd_to_send << _range;
LE's avatar
LE committed
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoConducteur::get_ElectroMeterGain
// ============================================================================
std::string N_PhotoConducteur::get_ElectroMeterGain (void)
ELATTAOUI's avatar
ELATTAOUI committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
LE's avatar
LE committed
												"N_PhotoConducteur::get_ElectroMeterGain( ).");
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
  return _electrometerProtocol->get_gain();
LE's avatar
LE committed
}

// ============================================================================
// N_PhotoConducteur::set_ElectroMeterGain
// ============================================================================
void N_PhotoConducteur::set_ElectroMeterGain (std::string gain)
ELATTAOUI's avatar
ELATTAOUI committed
{
ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
LE's avatar
LE committed
												"N_PhotoConducteur::set_ElectroMeterGain( ).");
ELATTAOUI's avatar
ELATTAOUI committed

ELATTAOUI's avatar
ELATTAOUI committed
	_electrometerProtocol->set_gain(gain);
LE's avatar
LE committed
}
ELATTAOUI's avatar
ELATTAOUI committed

// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
// N_PhotoConducteur::set_ElectroMeterRange
ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
ELATTAOUI's avatar
ELATTAOUI committed
void N_PhotoConducteur::set_ElectroMeterRange (std::string rgStr)
ELATTAOUI's avatar
ELATTAOUI committed
{
std::stringstream range_cmd_to_send;

ELATTAOUI's avatar
ELATTAOUI committed
  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoConducteur::set_ElectroMeterRange( ).");

  //- switch the novelec type :
ELATTAOUI's avatar
ELATTAOUI committed
	switch(_MCCE2electroTypeNumber)
	{
ELATTAOUI's avatar
ELATTAOUI committed
	case 4 : _range = Novelec_MCCE2::check_range_value(rgStr, NType4_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
ELATTAOUI's avatar
ELATTAOUI committed
	case 5 : _range = Novelec_MCCE2::check_range_value(rgStr, NType5_rangeValue);
ELATTAOUI's avatar
ELATTAOUI committed
		break;
	}

ELATTAOUI's avatar
ELATTAOUI committed
	if (_range < 0)
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INVALID_PARAMETER",
ELATTAOUI's avatar
ELATTAOUI committed
												  "This electrometer does not support this range value.",
ELATTAOUI's avatar
ELATTAOUI committed
												  "N_PhotoConducteur::set_ElectroMeterRange( ).");
ELATTAOUI's avatar
ELATTAOUI committed
	//- it is OK
ELATTAOUI's avatar
ELATTAOUI committed
	range_cmd_to_send << _range;
ELATTAOUI's avatar
ELATTAOUI committed
	_electrometerProtocol->set_range(range_cmd_to_send.str());
}
ELATTAOUI's avatar
ELATTAOUI committed

// ============================================================================
// N_PhotoConducteur::get_ElectroMeterRange
// ============================================================================
std::string N_PhotoConducteur::get_ElectroMeterRange()
{
std::string rangeStr("");

  if( !this->_electrometerProtocol )
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INIT_ERROR",
ELATTAOUI's avatar
ELATTAOUI committed
												"Novelec protocol initialization failed.",
												"N_PhotoConducteur::get_ElectroMeterRange( ).");

	rangeStr = this->_electrometerProtocol->get_range();

	//- switch the novelec type :
	switch(_MCCE2electroTypeNumber)
	{
	case 4 : _range = Novelec_MCCE2::check_range_value(rangeStr, NType4_rangeValue);
		break;
	case 5 : _range = Novelec_MCCE2::check_range_value(rangeStr, NType5_rangeValue);
		break;
	}

	if (_range < 0)
ELATTAOUI's avatar
ELATTAOUI committed
		throw electrometer::ElectrometerException("INVALID_PARAMETER",
ELATTAOUI's avatar
ELATTAOUI committed
												  "Cannot find the applied range value.",
												  "N_PhotoConducteur::get_ElectroMeterRange( ).");

	return rangeStr;
}
ELATTAOUI's avatar
ELATTAOUI committed

// ============================================================================
// N_PhotoConducteur::ranges_list
// ============================================================================
std::vector<std::string> N_PhotoConducteur::ranges_list(void)
{
  std::vector<std::string> vrangeslist;

	//- switch the novelec type :
	switch(_MCCE2electroTypeNumber)
	{
	case 4 : vrangeslist = NType4_rangeValue;
		break;
	case 5 : vrangeslist = NType5_rangeValue;
		break;
	}
	return vrangeslist;
}