Newer
Older
// ============================================================================
//
// = CONTEXT
// TANGO Project - NovelecElectrometer Support Library
//
// = FILENAME
// Novelec_MCCE2.cpp
//
// = AUTHOR
// X. Elattaoui
//
// ============================================================================
// ============================================================================
// DEPENDENCIES
// ============================================================================
#include <iostream>
#include <sstream>
#include <string>
#include <helpers/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)
}
// ============================================================================
// Novelec_MCCE2::~Novelec_MCCE2
// ============================================================================
Novelec_MCCE2::~Novelec_MCCE2 (void)
{
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ============================================================================
// 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)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::get_ElectroMeterPolarity( ).");
return _electrometerProtocol->get_polarity();
}
// ============================================================================
// Novelec_MCCE2::set_ElectroMeterPolarity
// ============================================================================
void Novelec_MCCE2::set_ElectroMeterPolarity (std::string polarity)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_ElectroMeterPolarity( ).");
_electrometerProtocol->set_polarity(polarity);
}
// ============================================================================
// Novelec_MCCE2::set_Zero_VonF_function
// ============================================================================
void Novelec_MCCE2::set_Zero_VonF_function (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_Zero_VonF_function( ).");
_electrometerProtocol->unable_zeroVF_func();
}
// ============================================================================
// Novelec_MCCE2::set_Offset_function
// ============================================================================
void Novelec_MCCE2::set_Offset_ZeroV1_function (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_Offset_ZeroV1_function( ).");
_electrometerProtocol->unable_offset_zeroV1_func();
}
// ============================================================================
// Novelec_MCCE2::set_Leakage_ZeroV2_function
// ============================================================================
void Novelec_MCCE2::set_Leakage_ZeroV2_function (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_Leakage_ZeroV2_function( ).");
_electrometerProtocol->unable_leakage_zeroV2_func();
}
// ============================================================================
// Novelec_MCCE2::set_Test_function
// ============================================================================
void Novelec_MCCE2::set_Test_function (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_Test_function( ).");
_electrometerProtocol->unable_test_func();
}
// ============================================================================
// Novelec_MCCE2::set_Measure_function
// ============================================================================
void Novelec_MCCE2::set_Measure_function (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::set_Measure_function( ).");
_electrometerProtocol->unable_measure_func();
}
// ============================================================================
// Novelec_MCCE2::mcce_on
// ============================================================================
void Novelec_MCCE2::mcce_on (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::mcce_on( ).");
_electrometerProtocol->switch_MCCE2_ON();
}
// ============================================================================
// Novelec_MCCE2::mcce_off
// ============================================================================
void Novelec_MCCE2::mcce_off (void)
{
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::mcce_off( ).");
_electrometerProtocol->switch_MCCE2_OFF();
}
// ============================================================================
// Novelec_MCCE2::electrometer_status
// ============================================================================
std::string Novelec_MCCE2::electrometer_status (void)
{

ELATTAOUI
committed
std::string argout("");
std::string typeStr(" ");
std::string tmp(" ");
short _status = 0;
short _errors = 0;
short _type = 0;
if( !this->_electrometerProtocol )
throw electrometer::ElectrometerException("INIT_ERROR",
"Novelec protocol initialization failed.",
"Novelec_MCCE2::electrometer_status( ).");
NovelecProtocol* nproto = dynamic_cast<NovelecProtocol*>(_electrometerProtocol);
if( !nproto )

ELATTAOUI
committed
throw electrometer::ElectrometerException("BAD_ALLOC",
"Memory allocation failed to query the electrmometer status.",

ELATTAOUI
committed
/***********************************************************************
DISABLED PART TO INCREASE SERIAL PERFORMANCE
***********************************************************************/
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
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";

ELATTAOUI
committed
/***********************************************************************/
try
{
//- read novelec status from HW
tmp = _electrometerProtocol->get_raw_status();
//std::cout << "Novelec_MCCE2::electrometer_status -> tmp = \"" << tmp << "\"" << std::endl;
//std::cout << "Novelec_MCCE2::convertFromString -> _status = \"" << _status << "\"" << std::endl;

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

ELATTAOUI
committed
argout += "\nStatus detail :\n";
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
//std::cout << "Novelec_MCCE2::get_errors ..." << std::endl;
//std::cout << "Novelec_MCCE2::convertFromString -> get_errors = \"" << tmp << "\"" << std::endl;
//std::cout << "Novelec_MCCE2::convertFromString -> convertFromString = \"" << _errors << "\"" << std::endl;
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
}
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++)
electroRg = electroRangeList[idx];
std::cout << "\t Novelec_MCCE2::check_range_value idx = " << idx
<< " rgToCheck = $" << rgToCheck << "$"
<< " electroRg = $" << electroRg << "$"
<< std::endl;
if( electroRg.find(rgToCheck) != std::string::npos )
{
//- value is in the list
return idx;
}