Skip to content
Snippets Groups Projects
N_PhotoVoltaique.cpp 5.36 KiB
Newer Older
LE's avatar
LE committed
// ============================================================================
//
// = CONTEXT
//    TANGO Project - NovelecElectrometer Support Library
//			PhotoVoltaique Types are Type 1, 2 & 3
//
// = FILENAME
//    N_PhotoVoltaique.cpp
//
// = AUTHOR
//    X. Elattaoui
//
// ============================================================================

// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <Xstring.h>
#include "N_PhotoVoltaique.h"
#include "NovelecProtocol.h"
/*
* Valid Range values for a N_PhotoVoltaique
*/
ELATTAOUI's avatar
ELATTAOUI committed
static const std::string NType1_rangeValue[] = {"3e-11","1e-11","3e-10","1e-10"};
static const std::string NType2_rangeValue[] = {"3e-10","1e-10","3e-9","1e-9","3e-8","1e-8","3e-7","1e-7"};
static const std::string NType3_rangeValue[] = {"3e-8","1e-8","3e-7","1e-7","3e-6","1e-6","3e-5","1e-5"};
LE's avatar
LE committed


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

	//- init range limit
	switch(novTypeNumber)
	{
	case 1 :	_rangeLimit = 3;
		break;
	case 2 :
	case 3 :	_rangeLimit = 7;
		break;
	}
	
ELATTAOUI's avatar
ELATTAOUI committed
	//std::cout << "N_PhotoVoltaique::N_PhotoVoltaique ->" << std::endl;
LE's avatar
LE committed
}

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

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

// ============================================================================
// N_PhotoVoltaique::range_up
// ============================================================================
void N_PhotoVoltaique::range_up (void) 
{

std::stringstream cmd_to_send;

	_range += 1;

	if(_range > _rangeLimit)
	{
		_range = _rangeLimit;
		throw electrometer::ElectrometerException("OUT_OF_RANGE", 
												"Range up limit reached.",
												"N_PhotoVoltaique::range_up( ).");
	}

	//- build and send the command
	cmd_to_send << _range << std::endl;
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoVoltaique::range_down
// ============================================================================
void N_PhotoVoltaique::range_down (void) 
{

std::stringstream cmd_to_send;

	_range -= 1;

	if(_range < 0)
	{
		_range = 0;
		throw electrometer::ElectrometerException("OUT_OF_RANGE", 
												"Range down limit reached.",
												"N_PhotoVoltaique::range_down( ).");
	}

	//- build and send the command
//	_rangeStr = NType1_rangeValue[_range];
	cmd_to_send << _range << std::endl;
	_electrometerProtocol->set_range(cmd_to_send.str());
}

// ============================================================================
// N_PhotoVoltaique::get_ElectroMeterFrequency Filter
// ============================================================================
std::string N_PhotoVoltaique::get_ElectroMeterFrequency (void)
{ 
	NovelecProtocol* _nproto = dynamic_cast<NovelecProtocol*>(_electrometerProtocol);
	if(!_nproto)
		throw electrometer::ElectrometerException("BAD_CAST", 
												"Unable to query the electrmometer frequency.",
												"N_PhotoVoltaique::get_ElectroMeterFrequency( ).");
ELATTAOUI's avatar
ELATTAOUI committed

LE's avatar
LE committed
	return _nproto->get_frequency();	
}

// ============================================================================
// N_PhotoVoltaique::set_ElectroMeterFrequency Filter
// ============================================================================
void N_PhotoVoltaique::set_ElectroMeterFrequency (std::string freqFilter)
{ 
	NovelecProtocol* _nproto = dynamic_cast<NovelecProtocol*>(_electrometerProtocol);
	if(!_nproto)
		throw electrometer::ElectrometerException("BAD_CAST", 
												"Unable to query the electrmometer frequency.",
												"N_PhotoVoltaique::set_ElectroMeterFrequency( ).");
	_nproto->set_frequency(freqFilter);	
}

ELATTAOUI's avatar
ELATTAOUI committed
// ============================================================================
// N_PhotoVoltaique::set_range
// ============================================================================
void N_PhotoVoltaique::set_range (std::string rgStr)
{
short range_idx = -1;
std::stringstream range_cmd_to_send;

	//- switch the novelec type :
	switch(_MCCE2electroTypeNumber)
	{
	case 1 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType1_rangeValue);
		break;
	case 2 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType2_rangeValue);
		break;
	case 3 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType3_rangeValue);
		break;
	}

	if (range_idx < 0)
		throw electrometer::ElectrometerException("INVALID_PARAMETER", 
												  "This electrometer does not support this range value.",
												  "N_PhotoVoltaique::set_range( ).");
	//- it is OK 
	range_cmd_to_send << range_idx << std::endl;
	_electrometerProtocol->set_range(range_cmd_to_send.str());
}