diff --git a/include/N_PhotoConducteur.h b/include/N_PhotoConducteur.h index 9d3a3beb760737899266d4d9a189e72a1b97c4c1..2be4fc33bd33b1536493d21265e31c6ecbfd280f 100644 --- a/include/N_PhotoConducteur.h +++ b/include/N_PhotoConducteur.h @@ -33,10 +33,11 @@ class N_PhotoConducteur : public Novelec_MCCE2 public: /** - * \brief Initialization. + * \brief Initialization. */ - N_PhotoConducteur (std::string& comLink_device_name, short channel_address, short electroType); - +// N_PhotoConducteur (std::string& comLink_device_name, short channel_address, short electroType); + N_PhotoConducteur (std::string& comLink_device_name, short channel_address); + /** * \brief Release resources. */ @@ -47,7 +48,7 @@ public: */ void range_up (void); void range_down (void); - + /** * \brief Checks and Sets the new range value. */ diff --git a/include/N_PhotoVoltaique.h b/include/N_PhotoVoltaique.h index d5eb77ecc9185e5bfa2e16d015ea351edab01266..9a63c3d571839920973cb0823f9fa7796994a783 100644 --- a/include/N_PhotoVoltaique.h +++ b/include/N_PhotoVoltaique.h @@ -33,10 +33,11 @@ class N_PhotoVoltaique : public Novelec_MCCE2 public: /** - * \brief Initialization. + * \brief Initialization. */ - N_PhotoVoltaique (std::string comLink_device_name, short channel_address, short electroType); - +// N_PhotoVoltaique (std::string comLink_device_name, short channel_address, short electroType); + N_PhotoVoltaique (std::string comLink_device_name, short channel_address); + /** * \brief Release resources. */ diff --git a/include/NovelecProtocol.h b/include/NovelecProtocol.h index 2ea97c51a0d42b247b4f0479e8c1810fa7195b60..6b518c45bee78aaaed2873fd40058cec5f890c46 100644 --- a/include/NovelecProtocol.h +++ b/include/NovelecProtocol.h @@ -19,7 +19,7 @@ #include "TangoSerialLink.h" /** - * \addtogroup Standard Commands Protocol + * \addtogroup Standard Commands Protocol * @{ */ @@ -35,10 +35,11 @@ class NovelecProtocol : public ElectrometerProtocol public: /** - * \brief Initialization. + * \brief Initialization. */ - NovelecProtocol (std::string& gpib_device_name, unsigned short channel_address, unsigned short electroTypeNumber); - + //NovelecProtocol (std::string& communication_device_name, unsigned short channel_address, unsigned short electroTypeNumber); + NovelecProtocol (std::string& communication_device_name, unsigned short channel_address); + /** * \brief Release resources. */ @@ -68,13 +69,13 @@ public: /** * \brief Electrometer Mode : Novelec SUPPORTS these commands */ - void switch_MCCE2_ON (void); - void switch_MCCE2_OFF (void); - void unable_zeroVF_func (void); - void unable_offset_zeroV1_func (void); - void unable_leakage_zeroV2_func (void); - void unable_test_func (void); - void unable_measure_func (void); + void switch_MCCE2_ON (void); + void switch_MCCE2_OFF (void); + void unable_zeroVF_func (void); + void unable_offset_zeroV1_func (void); + void unable_leakage_zeroV2_func (void); + void unable_test_func (void); + void unable_measure_func (void); /** * \brief Get Raw Electrometer Status. @@ -83,17 +84,23 @@ public: /** * \brief Electrometer Mode : getters and setters. */ - std::string get_mode (void); + std::string get_mode (void); std::string get_polarity (void); std::string get_frequency (void); - std::string get_gain (void); + std::string get_gain (void); std::string get_errors (void); - std::string get_electrotype (void); - void set_polarity (std::string pola); + short get_electrometerType(void) { + return this->_novType; + } + void set_polarity (std::string pola); void set_frequency (std::string freq); - void set_gain (std::string gain); - void set_electrometer_active_channel(unsigned short channel_add) { this->_devAdd = channel_add;}; - unsigned short get_electrometer_active_channel(void) { return this->_devAdd;}; + void set_gain (std::string gain); + void set_electrometer_active_channel(unsigned short channel_add) { + this->_devAdd = channel_add; + } + unsigned short get_electrometer_active_channel(void) { + return this->_devAdd; + } /** * \brief init the MCCE-2 device : @@ -102,13 +109,14 @@ public: * - clear error(s) */ void init_MCCE2_for_communication(void); + std::string check_electrotype (void); protected : short _devAdd; //- novelec active channel address short _novType; //- novelec type number (1 to 5) - short _rangeParameterNum; //- command number for the range + short _rangeParameterNum; //- command number for the range std::string _function; //- the novelec mode - + //- check if the cmd is understood void check_command (std::string resp_to_check); //- check if the cmd is understood and extract data from the response @@ -121,8 +129,6 @@ private : void is_allowed(); CommunicationLink* _communication_link; - //TangoSerialLink* _tgSerLk; //- to use SerialLink specific methods ! - //- if true, parameters cannot be changed ! bool _is_measure_mode_on; diff --git a/include/Novelec_MCCE2.h b/include/Novelec_MCCE2.h index e732d9147bf8d9cdb18bd183f0724d9fe6bee2bf..24edddd6377f3eff47b3d86b0e8365dfb8bc5ffe 100644 --- a/include/Novelec_MCCE2.h +++ b/include/Novelec_MCCE2.h @@ -33,10 +33,11 @@ class Novelec_MCCE2 : public AbstractElectrometerClass public: /** - * \brief Initialization. + * \brief Initialization. */ - Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address, unsigned short electroType); - +// Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address, unsigned short electroType); + Novelec_MCCE2 (std::string& comLink_device_name, unsigned short channel_address); + /** * \brief Release resources. */ @@ -45,27 +46,33 @@ public: bool init_protocol(void); std::string get_ElectroMeterPolarity(void); - void set_ElectroMeterPolarity (std::string); + void set_ElectroMeterPolarity (std::string); + + short get_electrometer_type() { + return this->_MCCE2electroTypeNumber; + } /** * \brief Electrometer Functions : mode for novelec types. */ - void set_Zero_VonF_function (void); + void set_Zero_VonF_function (void); void set_Offset_ZeroV1_function (void); void set_Leakage_ZeroV2_function (void); - void set_Test_function (void); - void set_Measure_function (void); + void set_Test_function (void); + void set_Measure_function (void); /** * \brief Sets the new range value */ - //virtual void set_ElectroMeterRange(std::string range_str) = 0; + //virtual void set_ElectroMeterRange(std::string range_str) = 0; + virtual void range_up (void) {}; + virtual void range_down (void) {}; /** * \brief Commands to start/stop the data acquisition * - * - * This emulate the MCCE2 key ON/OFF + * + * This emulate the MCCE2 key ON/OFF * (all parameters must be set before switching ON the MCCE2) */ void mcce_on (void); @@ -79,13 +86,13 @@ public: protected : unsigned short _rangeLimit; //- define the range limit for each novelec type unsigned short _address; //- a DAIP manages 2 "channels" (or address) - unsigned short _MCCE2electroTypeNumber; //- the mcce2 electrometer type number (to check range value) + unsigned short _MCCE2electroTypeNumber; //- the mcce2 electrometer type number (to check range value) /** * \brief Checks the new range value */ short check_range_value(const std::string& rgToCheck, const std::string* electroRangeList); - + }; /** @} */ //- end addtogroup diff --git a/pom.xml b/pom.xml index 4b99f3ae0d319ec9f21655456c5cd71794d30ae0..072be3d8165843e3e669bc93d7a663fb2c0d0663 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ </parent> <groupId>fr.soleil.lib</groupId> <artifactId>Electrometers-${aol}-${library}-${mode}</artifactId> - <version>2.5.14-SNAPSHOT</version> + <version>2.5.15</version> <packaging>nar</packaging> <name>Electrometers library</name> <description>Electrometers library</description> diff --git a/src/AbstractElectrometerClass.cpp b/src/AbstractElectrometerClass.cpp index 2cc075f0b3ec4d9c22d267eb5f604ee62c518431..6695583ca0ec9bce8ec25f3035428d4b67df4548 100644 --- a/src/AbstractElectrometerClass.cpp +++ b/src/AbstractElectrometerClass.cpp @@ -136,7 +136,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "AbstractElectrometerClass.h" #include "ElectrometerException.h" @@ -165,7 +165,7 @@ AbstractElectrometerClass::AbstractElectrometerClass (std::string comLink_device // ============================================================================ AbstractElectrometerClass::~AbstractElectrometerClass (void) { - std::cout << "AbstractElectrometerClass::~AbstractElectrometerClass <-" << std::endl; +// std::cout << "AbstractElectrometerClass::~AbstractElectrometerClass <-" << std::endl; if(_electrometerProtocol) { @@ -173,7 +173,7 @@ AbstractElectrometerClass::~AbstractElectrometerClass (void) _electrometerProtocol = 0; } - std::cout << "AbstractElectrometerClass::~AbstractElectrometerClass ->" << std::endl; +// std::cout << "AbstractElectrometerClass::~AbstractElectrometerClass ->" << std::endl; } // ============================================================================ @@ -734,7 +734,6 @@ std::string AbstractElectrometerClass::get_ElectroMeterGain (void) void AbstractElectrometerClass::set_ElectroMeterRange (std::string rang) { _electrometerProtocol->set_range(rang); - std::cout << "\t AbstractElectrometerClass::set_ElectroMeterRange val = " << rang << std::endl; } // ============================================================================ diff --git a/src/KeithleyDDCProtocol.cpp b/src/KeithleyDDCProtocol.cpp index d8884e2808087fc081e24d241d0d9bfb5add3121..443bdbb0b6a151e71976db62ce192418eae02a0b 100644 --- a/src/KeithleyDDCProtocol.cpp +++ b/src/KeithleyDDCProtocol.cpp @@ -17,7 +17,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "KeithleyDDCProtocol.h" // ============================================================================ diff --git a/src/KeithleySCPIProtocol.cpp b/src/KeithleySCPIProtocol.cpp index 573f996e134744f969b0fb6ac169d7108b28a95d..005f46ad36e5f577827f672bc59d6cbe47861af5 100644 --- a/src/KeithleySCPIProtocol.cpp +++ b/src/KeithleySCPIProtocol.cpp @@ -17,7 +17,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #ifndef WIN32 # include <unistd.h> #endif @@ -676,7 +676,7 @@ std::string dataStr(""); std::vector<double> argout; std::string::size_type posBeg; std::string::size_type posEnd; -short numberOfData = 0; + //- posBeg = 0; posEnd = datalist.find(',', posBeg); @@ -695,7 +695,7 @@ std::cout << "\t*****::buildDataList -> JUST ONE DATA :$" << datalist << "$" << { int i = 0; //std::string tmp = get_triggercount(); - numberOfData = XString<short>::convertFromString(get_triggercount()); + short numberOfData = XString<short>::convertFromString(get_triggercount()); for(i=0; i < numberOfData; i++) { diff --git a/src/Keithley_485.cpp b/src/Keithley_485.cpp index ea9af931fefc42bc5cc912b13111c0d1e021d09a..5a514d6eae1336cfec907ab44f9455aa89d2918f 100644 --- a/src/Keithley_485.cpp +++ b/src/Keithley_485.cpp @@ -18,7 +18,7 @@ #include <stdexcept> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "KeithleyDDCProtocol.h" #include "Keithley_485.h" @@ -40,11 +40,11 @@ static const short K485_triggerModeLimit = 5; // ============================================================================ // Keithley_485::Keithley_485 // ============================================================================ -Keithley_485::Keithley_485 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) +Keithley_485::Keithley_485 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) { std::cout << "Keithley_485::Keithley_485 <-" << std::endl; - + std::cout << "Keithley_485::Keithley_485 ->" << std::endl; } @@ -69,14 +69,14 @@ bool Keithley_485::init_protocol (void) { //- build the keithley Electrometer protocol obj _electrometerProtocol = new KeithleyDDCProtocol (_device_proxy_name); - + 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(), @@ -85,7 +85,7 @@ bool Keithley_485::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -97,11 +97,11 @@ bool Keithley_485::init_protocol (void) // ============================================================================ // Keithley_485::range_up // ============================================================================ -void Keithley_485::range_up (void) +void Keithley_485::range_up (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable electrometer_status(); _range += 1; @@ -109,7 +109,7 @@ std::stringstream cmd_to_send; if(_range > K485_rangeLimit) { _range = K485_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_485::range_up( )."); } @@ -122,7 +122,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_485::range_down // ============================================================================ -void Keithley_485::range_down (void) +void Keithley_485::range_down (void) { std::stringstream cmd_to_send; @@ -134,7 +134,7 @@ std::stringstream cmd_to_send; if(_range < 0) { _range=0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_485::range_down( )."); } @@ -146,7 +146,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_485::get_ElectroMeterRange // ============================================================================ -std::string Keithley_485::get_ElectroMeterRange (void) +std::string Keithley_485::get_ElectroMeterRange (void) { // force read of range on instrument to update _range variable electrometer_status(); @@ -157,12 +157,12 @@ std::string Keithley_485::get_ElectroMeterRange (void) // ============================================================================ // Keithley_485::set_triggerMode // ============================================================================ -void Keithley_485::set_triggerMode (short trigMod) +void Keithley_485::set_triggerMode (short trigMod) { std::stringstream cmd_to_send; if(trigMod<0 || trigMod>K485_triggerModeLimit) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Trigger mode value invalid. Please enter a value in the range 0 - 5.", "Keithley_485::set_triggerMode( )."); @@ -176,12 +176,12 @@ std::stringstream cmd_to_send; // Keithley_485::electrometer_status // ============================================================================ std::string Keithley_485::electrometer_status (void) -{ +{ std::string _kstatus("undefined status"); std::string argout(""); std::string tmp(""); - //- read keithley status from HW + //- read keithley status from HW _kstatus = _electrometerProtocol->get_DDC_configuration(); //- build status @@ -301,7 +301,7 @@ std::string Keithley_485::electrometer_status (void) { set_electroState(ALARM); - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Cannot extract device status [find or substr failed !].", "Keithley_485::electrometer_status( )."); } diff --git a/src/Keithley_486.cpp b/src/Keithley_486.cpp index 87d03b50f8d76164e9579fdebdc39faa552b4070..ba2dcbe1b46f6eaf0c7c91462c745f246c9d9f75 100644 --- a/src/Keithley_486.cpp +++ b/src/Keithley_486.cpp @@ -19,7 +19,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_486.h" #include "KeithleyDDCProtocol.h" @@ -45,7 +45,7 @@ static int K486_conversionRate = 360; // ============================================================================ // Keithley_486::Keithley_486 // ============================================================================ -Keithley_486::Keithley_486 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) +Keithley_486::Keithley_486 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) { std::cout << "Keithley_486::Keithley_486 <-" << std::endl; @@ -77,14 +77,14 @@ bool Keithley_486::init_protocol (void) { //- build the keithley Electrometer protocol obj _electrometerProtocol = new KeithleyDDCProtocol (_device_proxy_name); - + 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(), @@ -93,7 +93,7 @@ bool Keithley_486::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -105,7 +105,7 @@ bool Keithley_486::init_protocol (void) // ============================================================================ // Keithley_486::autoRange_off // ============================================================================ -void Keithley_486::autoRange_off (void) +void Keithley_486::autoRange_off (void) { //- send the appropriate command KeithleyDDCProtocol* _kddc = dynamic_cast<KeithleyDDCProtocol*>(_electrometerProtocol); @@ -116,11 +116,11 @@ void Keithley_486::autoRange_off (void) // ============================================================================ // Keithley_486::range_up // ============================================================================ -void Keithley_486::range_up (void) +void Keithley_486::range_up (void) { std::stringstream cmd_to_send(""); - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range += 1; @@ -128,7 +128,7 @@ std::stringstream cmd_to_send(""); if(_range > K486_rangeLimit) { _range =K486_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_486::range_up( )."); } @@ -141,7 +141,7 @@ std::stringstream cmd_to_send(""); // ============================================================================ // Keithley_486::range_down // ============================================================================ -void Keithley_486::range_down (void) +void Keithley_486::range_down (void) { std::stringstream cmd_to_send(""); @@ -153,7 +153,7 @@ std::stringstream cmd_to_send(""); if(_range < 0) { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_486::range_down( )."); } @@ -165,7 +165,7 @@ std::stringstream cmd_to_send(""); // ============================================================================ // Keithley_486::get_ElectroMeterRange // ============================================================================ -std::string Keithley_486::get_ElectroMeterRange (void) +std::string Keithley_486::get_ElectroMeterRange (void) { // force read of range on instrument to update _range variable this->get_configuration(); @@ -176,16 +176,16 @@ std::string Keithley_486::get_ElectroMeterRange (void) // ============================================================================ // Keithley_486::set_buffer_size() // ============================================================================ -void Keithley_486::set_buffer_size (short size) +void Keithley_486::set_buffer_size (short size) { std::stringstream cmd_to_send(""); //- check if size is valid if(size<0 || size>512) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Buffer size value invalid. Please enter a value in the range 0 - 512.", "Keithley_487::set_buffer_size( )."); - + //- just for internal use _size = size; //- send command : size = number of triggers @@ -197,10 +197,10 @@ std::stringstream cmd_to_send(""); // ============================================================================ // Keithley_487::set_triggerMode // ============================================================================ -void Keithley_486::set_triggerMode (short trigMod) +void Keithley_486::set_triggerMode (short trigMod) { if(trigMod<0 || trigMod>K486_triggerModeLimit) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Trigger mode value invalid. Please enter a value in the range 0 - 7.", "Keithley_486::set_triggerMode( )."); @@ -218,7 +218,7 @@ void Keithley_486::set_triggerMode (short trigMod) // ============================================================================ // Keithley_487::set_integrationTime // ============================================================================ -void Keithley_486::set_integrationTime (double seconds) +void Keithley_486::set_integrationTime (double seconds) { double msSeconds = seconds / 1000; @@ -229,7 +229,7 @@ void Keithley_486::set_integrationTime (double seconds) // ============================================================================ // Keithley_486::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_486::init_keithley (void) +void Keithley_486::init_keithley (void) { //- default conversion rate // _electrometerProtocol->set_conversionRate( ); @@ -304,7 +304,7 @@ std::string Keithley_486::electrometer_status (void) { argout += "Trigger error : Trigger received while instrument is still processing a reading from a previous trigger.\n"; } - //- Conflict Error : Set when trying to send a calibration value with the instrument on a measurement + //- Conflict Error : Set when trying to send a calibration value with the instrument on a measurement //- range that is too small to accommodate the value.. tmp = kconfig.substr(8,1); short conflict = XString<short>::convertFromString(tmp); @@ -375,8 +375,8 @@ std::string Keithley_486::electrometer_status (void) catch(...) { set_electroState(ALARM); - - throw electrometer::ElectrometerException("UNKNOWN_ERROR", + + throw electrometer::ElectrometerException("UNKNOWN_ERROR", "Cannot extract device error status.", "Keithley_486::electrometer_status( )."); } @@ -389,12 +389,12 @@ std::string Keithley_486::electrometer_status (void) // Keithley_486::get_configuration // ============================================================================ std::string Keithley_486::get_configuration (void) -{ +{ std::string _kstatus("undefined status"); std::string argout("undefined status"); std::string tmp(""); - //- read keithley status from HW + //- read keithley status from HW _kstatus = _electrometerProtocol->get_DDC_configuration(); //- build status @@ -604,7 +604,7 @@ std::string Keithley_486::get_configuration (void) { set_electroState(ALARM); - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Cannot extract device status [find or substr failed !].", "Keithley_486::get_configuration( )."); } diff --git a/src/Keithley_487.cpp b/src/Keithley_487.cpp index 9b8900bb2f48f0aa3d3d90f4f23444061958ca2e..fd0f17fd5084cf95e322abec4e297bf0c9d5c05f 100644 --- a/src/Keithley_487.cpp +++ b/src/Keithley_487.cpp @@ -19,7 +19,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_487.h" #include "KeithleyDDCProtocol.h" @@ -45,7 +45,7 @@ static int K487_conversionRate = 360; // ============================================================================ // Keithley_487::Keithley_487 // ============================================================================ -Keithley_487::Keithley_487 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) +Keithley_487::Keithley_487 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) { std::cout << "Keithley_487::Keithley_487 <-" << std::endl; @@ -74,14 +74,14 @@ bool Keithley_487::init_protocol (void) { //- build the keithley Electrometer protocol obj _electrometerProtocol = new KeithleyDDCProtocol (_device_proxy_name); - + 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(), @@ -90,7 +90,7 @@ bool Keithley_487::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -102,7 +102,7 @@ bool Keithley_487::init_protocol (void) // ============================================================================ // Keithley_487::autoRange_off // ============================================================================ -void Keithley_487::autoRange_off (void) +void Keithley_487::autoRange_off (void) { //- send the appropriate command KeithleyDDCProtocol* _kddc = dynamic_cast<KeithleyDDCProtocol*>(_electrometerProtocol); @@ -113,11 +113,11 @@ void Keithley_487::autoRange_off (void) // ============================================================================ // Keithley_487::range_up // ============================================================================ -void Keithley_487::range_up (void) +void Keithley_487::range_up (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range += 1; @@ -126,7 +126,7 @@ std::stringstream cmd_to_send; { _range = K487_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_487::range_up( )."); } @@ -139,11 +139,11 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_487::range_down // ============================================================================ -void Keithley_487::range_down (void) +void Keithley_487::range_down (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range -= 1; @@ -152,7 +152,7 @@ std::stringstream cmd_to_send; { _range=0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_487::range_down( )."); } @@ -164,7 +164,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_487::get_ElectroMeterRange // ============================================================================ -std::string Keithley_487::get_ElectroMeterRange (void) +std::string Keithley_487::get_ElectroMeterRange (void) { // get config from instrument to update _range variable this->get_configuration(); @@ -175,13 +175,13 @@ std::string Keithley_487::get_ElectroMeterRange (void) // ============================================================================ // Keithley_487::set_buffer_size() // ============================================================================ -void Keithley_487::set_buffer_size (short size) +void Keithley_487::set_buffer_size (short size) { std::stringstream cmd_to_send; //- check if size is valid if(size<0 || size>512) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Buffer size value invalid. Please enter a value in the range 0 - 512.", "Keithley_487::set_buffer_size( )."); @@ -195,7 +195,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_487::set_integrationTime // ============================================================================ -void Keithley_487::set_integrationTime (double seconds) +void Keithley_487::set_integrationTime (double seconds) { double msSeconds = seconds / 1000; @@ -206,10 +206,10 @@ void Keithley_487::set_integrationTime (double seconds) // ============================================================================ // Keithley_487::set_triggerMode // ============================================================================ -void Keithley_487::set_triggerMode (short trigMod) +void Keithley_487::set_triggerMode (short trigMod) { if(trigMod<0 || trigMod>K487_triggerModeLimit) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Trigger mode value invalid. Please enter a value in the range 0 - 7.", "Keithley_487::set_triggerMode( )."); @@ -226,7 +226,7 @@ void Keithley_487::set_triggerMode (short trigMod) // ============================================================================ // Keithley_487::get_triggerMode // ============================================================================ -/*std::string Keithley_487::get_triggerMode (void) +/*std::string Keithley_487::get_triggerMode (void) { // force read of range on instrument to update _range variable // electrometer_status(); @@ -237,7 +237,7 @@ void Keithley_487::set_triggerMode (short trigMod) // ============================================================================ // Keithley_487::get_ElectroMeterMode // ============================================================================ -std::string Keithley_487::get_ElectroMeterMode (void) +std::string Keithley_487::get_ElectroMeterMode (void) { // get config from instrument to update _mode variable this->get_configuration(); @@ -248,14 +248,14 @@ std::string Keithley_487::get_ElectroMeterMode (void) // ============================================================================ // Keithley_487::setAmperMeterMode // ============================================================================ -void Keithley_487::setAmperMeterMode (void) +void Keithley_487::setAmperMeterMode (void) { //- send the appropriate command KeithleyDDCProtocol* _kddc = dynamic_cast<KeithleyDDCProtocol*>(_electrometerProtocol); if(_kddc) _kddc->setAmperMeterMode_forK487(); else - throw electrometer::ElectrometerException("BAD_CAST", + throw electrometer::ElectrometerException("BAD_CAST", "Unable to switch the electrmometer mode.", "Keithley_487::setAmperMeterMode( )."); } @@ -263,7 +263,7 @@ void Keithley_487::setAmperMeterMode (void) // ============================================================================ // Keithley_487::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_487::init_keithley (void) +void Keithley_487::init_keithley (void) { //- set trigger mode this->set_triggerMode(_trigMod); @@ -334,7 +334,7 @@ std::string Keithley_487::electrometer_status (void) { argout += "Trigger error : Trigger received while instrument is still processing a reading from a previous trigger.\n"; } - //- Conflict Error : Set when trying to send a calibration value with the instrument on a measurement + //- Conflict Error : Set when trying to send a calibration value with the instrument on a measurement //- range that is too small to accommodate the value.. tmp = kconfig.substr(8,1); short conflict = XString<short>::convertFromString(tmp); @@ -405,8 +405,8 @@ std::string Keithley_487::electrometer_status (void) catch(...) { set_electroState(ALARM); - - throw electrometer::ElectrometerException("UNKNOWN_ERROR", + + throw electrometer::ElectrometerException("UNKNOWN_ERROR", "Cannot extract device error status.", "Keithley_487::electrometer_status( )."); } @@ -419,12 +419,12 @@ std::string Keithley_487::electrometer_status (void) // Keithley_487::get_configuration // ============================================================================ std::string Keithley_487::get_configuration (void) -{ +{ std::string _kstatus("undefined status"); std::string argout("undefined status"); std::string tmp(""); - //- read keithley status from HW + //- read keithley status from HW _kstatus = _electrometerProtocol->get_DDC_configuration(); //- build status @@ -513,7 +513,7 @@ std::string Keithley_487::get_configuration (void) argout += "Data Format : Binary Reading - counts and exponent, bytes in normal order for Motorola CPUs\n"; //- Self Test ('J') tmp = _kstatus.substr(_kstatus.find('J')+1,1); - short stest = XString<short>::convertFromString(tmp); + short stest = XString<short>::convertFromString(tmp); if(!stest) argout += "Self Test : No Errors\n"; else @@ -645,7 +645,7 @@ std::string Keithley_487::get_configuration (void) { set_electroState(ALARM); - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Cannot extract device status [find or substr failed !].", "Keithley_487::get_configuration( )."); } diff --git a/src/Keithley_617.cpp b/src/Keithley_617.cpp index edb99b3a1d9130f64add7c4917bbc81aa6003741..dc70d1891c4eada6197066597cd7ce722eaca780 100644 --- a/src/Keithley_617.cpp +++ b/src/Keithley_617.cpp @@ -18,7 +18,7 @@ #include <stdexcept> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_617.h" #include "KeithleyDDCProtocol.h" @@ -44,7 +44,7 @@ static short K617_triggerModeLimit = 7; // ============================================================================ // Keithley_617::Keithley_617 // ============================================================================ -Keithley_617::Keithley_617 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) +Keithley_617::Keithley_617 (std::string& comLink_device_name):AbstractElectrometerClass(comLink_device_name) { std::cout << "Keithley_617::Keithley_617 <-" << std::endl; @@ -73,14 +73,14 @@ bool Keithley_617::init_protocol (void) { //- build the keithley Electrometer protocol obj _electrometerProtocol = new KeithleyDDCProtocol (_device_proxy_name); - + 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(), @@ -89,7 +89,7 @@ bool Keithley_617::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -101,7 +101,7 @@ bool Keithley_617::init_protocol (void) // ============================================================================ // Keithley_617::autoRange_off // ============================================================================ -void Keithley_617::autoRange_off (void) +void Keithley_617::autoRange_off (void) { //- send the appropriate command KeithleyDDCProtocol* _kddc = dynamic_cast<KeithleyDDCProtocol*>(_electrometerProtocol); @@ -112,11 +112,11 @@ void Keithley_617::autoRange_off (void) // ============================================================================ // Keithley_617::range_up // ============================================================================ -void Keithley_617::range_up (void) +void Keithley_617::range_up (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range += 1; @@ -124,7 +124,7 @@ std::stringstream cmd_to_send; if(_range > K617_rangeLimit) { _range = K617_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_617::range_up( )."); } @@ -137,11 +137,11 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_617::range_down // ============================================================================ -void Keithley_617::range_down (void) +void Keithley_617::range_down (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range -= 1; @@ -149,7 +149,7 @@ std::stringstream cmd_to_send; if(_range < 0) { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_617::range_down( )."); } @@ -162,7 +162,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_617::get_ElectroMeterRange // ============================================================================ -std::string Keithley_617::get_ElectroMeterRange (void) +std::string Keithley_617::get_ElectroMeterRange (void) { // get config from instrument to update _range variable this->get_configuration(); @@ -173,9 +173,9 @@ std::string Keithley_617::get_ElectroMeterRange (void) // ============================================================================ // Keithley_617::set_buffer_size() // ============================================================================ -void Keithley_617::set_buffer_size (short ) +void Keithley_617::set_buffer_size (short ) { - throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", + throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", "The 617 Keithley device buffer size cannot be set (it stores up to 100 points internally.)", "Keithley_617::set_triggerMode( )."); } @@ -183,10 +183,10 @@ void Keithley_617::set_buffer_size (short ) // ============================================================================ // Keithley_617::set_triggerMode // ============================================================================ -void Keithley_617::set_triggerMode (short trigMod) +void Keithley_617::set_triggerMode (short trigMod) { if(trigMod<0 || trigMod>K617_triggerModeLimit) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Trigger mode value invalid. Please enter a value in the range 0 - 7.", "Keithley_617::set_triggerMode( )."); @@ -202,18 +202,18 @@ void Keithley_617::set_triggerMode (short trigMod) // ============================================================================ // Keithley_617::get_ElectroMeterMode // ============================================================================ -std::string Keithley_617::get_ElectroMeterMode (void) +std::string Keithley_617::get_ElectroMeterMode (void) { // get config from instrument to update _mode variable this->get_configuration(); - + return _mode; } // ============================================================================ // Keithley_617::setAmperMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_617::setAmperMeterMode (void) +void Keithley_617::setAmperMeterMode (void) { _electrometerProtocol->setAmperMeterMode( ); } @@ -221,7 +221,7 @@ void Keithley_617::setAmperMeterMode (void) // ============================================================================ // Keithley_617::setAmperMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_617::setVoltMeterMode (void) +void Keithley_617::setVoltMeterMode (void) { _electrometerProtocol->setVoltMeterMode( ); } @@ -229,7 +229,7 @@ void Keithley_617::setVoltMeterMode (void) // ============================================================================ // Keithley_617::setAmperMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_617::setOhmMeterMode (void) +void Keithley_617::setOhmMeterMode (void) { _electrometerProtocol->setOhmMeterMode( ); } @@ -237,7 +237,7 @@ void Keithley_617::setOhmMeterMode (void) // ============================================================================ // Keithley_617::setAmperMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_617::setCoulombMeterMode (void) +void Keithley_617::setCoulombMeterMode (void) { _electrometerProtocol->setCoulombMeterMode( ); } @@ -245,7 +245,7 @@ void Keithley_617::setCoulombMeterMode (void) // ============================================================================ // Keithley_617::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_617::init_keithley (void) +void Keithley_617::init_keithley (void) { //- set trigger mode this->set_triggerMode(_trigMod); @@ -324,7 +324,7 @@ std::string Keithley_617::electrometer_status (void) catch(...) { set_electroState(ALARM); - throw electrometer::ElectrometerException("UNKNOWN_ERROR", + throw electrometer::ElectrometerException("UNKNOWN_ERROR", "Cannot extract device error status.", "Keithley_617::electrometer_status( )."); } @@ -337,12 +337,12 @@ std::string Keithley_617::electrometer_status (void) // Keithley_617::get_configuration // ============================================================================ std::string Keithley_617::get_configuration (void) -{ +{ std::string _kstatus("undefined status"); std::string argout("undefined status"); std::string tmp(""); - //- read keithley status from HW + //- read keithley status from HW _kstatus = _electrometerProtocol->get_DDC_configuration(); //- build status @@ -540,7 +540,7 @@ std::string Keithley_617::get_configuration (void) catch(std::out_of_range) { set_electroState(ALARM); - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Cannot extract device status [find or substr failed !].", "Keithley_617::get_configuration( )."); } diff --git a/src/Keithley_6485.cpp b/src/Keithley_6485.cpp index 18b665183e4ba8344ed435e2768dd10d235957c9..5088fec357564144431f5914cc35858ae2f434bb 100644 --- a/src/Keithley_6485.cpp +++ b/src/Keithley_6485.cpp @@ -18,7 +18,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_6485.h" #include "KeithleySCPIProtocol.h" /* @@ -39,11 +39,11 @@ Keithley_6485::Keithley_6485 (std::string& comLink_device_name) : AbstractElectrometerClass(comLink_device_name) { std::cout << "Keithley_6485::Keithley_6485 <-" << std::endl; - + _numPLC = 0; _trigCounts = 0; _size = 0; - + std::cout << "Keithley_6485::Keithley_6485 ->" << std::endl; } @@ -53,7 +53,7 @@ Keithley_6485::Keithley_6485 (std::string& comLink_device_name) Keithley_6485::~Keithley_6485 (void) { std::cout << "Keithley_6485::~Keithley_6485 <-" << std::endl; - + std::cout << "Keithley_6485::~Keithley_6485 ->" << std::endl; } @@ -76,14 +76,14 @@ bool Keithley_6485::init_protocol (void) KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) _kscpi->set_isDiffSuportedMode(false); - + 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(), @@ -92,7 +92,7 @@ bool Keithley_6485::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -104,23 +104,23 @@ bool Keithley_6485::init_protocol (void) // ============================================================================ // Keithley_6485::range_up // ============================================================================ -void Keithley_6485::range_up (void) +void Keithley_6485::range_up (void) { std::stringstream cmd_to_send; - + //- update range index from hardware this->get_ElectroMeterRange( ); _range += 1; - + if(_range > K6485_rangeLimit) { _range = K6485_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6485::range_up( )."); } - + //- build and send the command _rangeStr = K6485_rangeValue[_range]; cmd_to_send << _rangeStr << std::endl; @@ -130,19 +130,19 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6485::range_down // ============================================================================ -void Keithley_6485::range_down (void) +void Keithley_6485::range_down (void) { std::stringstream cmd_to_send; - + //- update range index from hardware this->get_ElectroMeterRange( ); _range -= 1; - + if(_range < 0) { _range=0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_6485::range_down( )."); } @@ -156,35 +156,30 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6485::update_range // ============================================================================ -//void Keithley_6485::update_range (void) -std::string Keithley_6485::get_ElectroMeterRange (void) +//void Keithley_6485::update_range (void) +std::string Keithley_6485::get_ElectroMeterRange (void) { -std::string range_str(""); -double rangeValueReturned = 0; -double rangeValueCalculated = 0; -double delta = 0; - /** * NOTE : SCPI models return a range value +/- 5% */ //- get range from hardware - range_str = _electrometerProtocol->get_range( ); + std::string range_str = _electrometerProtocol->get_range( ); //- convert range in decimal value - rangeValueReturned = XString<double>::convertFromString(range_str); - + double rangeValueReturned = XString<double>::convertFromString(range_str); + //- find and return the index short idx = 0; for(idx=0; idx<K6485_rangeLimit ; idx++) { - rangeValueCalculated = XString<double>::convertFromString(K6485_rangeValue[idx]); - delta = rangeValueCalculated * 5 / 100; + double rangeValueCalculated = XString<double>::convertFromString(K6485_rangeValue[idx]); + double delta = rangeValueCalculated * 5 / 100; if( (rangeValueCalculated + delta) >= rangeValueReturned && (rangeValueCalculated - delta) <= rangeValueReturned) break; } //- throw if index not found if(idx == K6485_rangeLimit) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Failed to get range index.", "Keithley_6485::get_ElectroMeterRange( )."); @@ -197,41 +192,41 @@ double delta = 0; // ============================================================================ // Keithley_6485::get_integratedValue // ============================================================================ -std::vector<double> Keithley_6485::get_integratedValue (void) +std::vector<double> Keithley_6485::get_integratedValue (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(!_kscpi) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Dynamic cast failed !.", "Keithley_6485::get_integratedValue( )."); return _electrometerProtocol->get_integratedValue( ); -} +} // ============================================================================ // Keithley_6485::get_fetchValue // ============================================================================ -std::vector<double> Keithley_6485::get_fetchValue (void) +std::vector<double> Keithley_6485::get_fetchValue (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(!_kscpi) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Dynamic cast failed !.", "Keithley_6485::get_fetchValue( )."); return _kscpi->get_fetchValue( ); -} +} // ============================================================================ // Keithley_6485::set_knplc // ============================================================================ -void Keithley_6485::set_knplc (double numPLC) +void Keithley_6485::set_knplc (double numPLC) { std::stringstream cmd_to_send; if(numPLC <= 0 || numPLC > 5.0) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid number of PLC.\n Please enter a value in the range 0.01 to 5.0.", "Keithley_6485::set_knplc( )."); } @@ -241,18 +236,18 @@ std::stringstream cmd_to_send; cmd_to_send << numPLC << std::endl; //- default conversion rate _electrometerProtocol->set_knplc(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6485::set_triggercount // ============================================================================ -void Keithley_6485::set_triggercount (short trigCounts) +void Keithley_6485::set_triggercount (short trigCounts) { std::stringstream cmd_to_send; if(trigCounts == 0 || trigCounts > 2500) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid trigger count.\n Please enter a value in the range 1 to 2500 or set -1 for INFinite.", "Keithley_6485::set_triggercount( )."); } @@ -265,18 +260,18 @@ std::stringstream cmd_to_send; _trigCounts = trigCounts; //- default conversion rate _electrometerProtocol->set_triggercount(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6485::set_buffer_size // ============================================================================ -void Keithley_6485::set_buffer_size (short size) +void Keithley_6485::set_buffer_size (short size) { std::stringstream cmd_to_send; if(size < 1 || size > 2500) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid buffer size. \nPlease enter a value in the range 1 to 2500.", "Keithley_6485::set_buffer_size( )."); } @@ -286,12 +281,12 @@ std::stringstream cmd_to_send; cmd_to_send << size << std::endl; //- default conversion rate _electrometerProtocol->set_buffer_size(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6485::set_integrationTime // ============================================================================ -void Keithley_6485::set_integrationTime (double seconds) +void Keithley_6485::set_integrationTime (double seconds) { //- set the number of Power Line Cycle(s) -> Fast integration _numPLC = 0.05; @@ -305,7 +300,7 @@ void Keithley_6485::set_integrationTime (double seconds) // ============================================================================ // Keithley_6485::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_6485::init_keithley (void) +void Keithley_6485::init_keithley (void) { //- clear all registers _electrometerProtocol->clear_registers(); @@ -332,11 +327,11 @@ void Keithley_6485::init_keithley (void) // ============================================================================ // Keithley_6485::save_configuration // ============================================================================ -void Keithley_6485::save_configuration (unsigned short memoryIdx) +void Keithley_6485::save_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6485::save_configuration( )."); } @@ -346,11 +341,11 @@ void Keithley_6485::save_configuration (unsigned short memoryIdx) // ============================================================================ // Keithley_6485::restore_configuration // ============================================================================ -void Keithley_6485::restore_configuration (unsigned short memoryIdx) +void Keithley_6485::restore_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6485::restore_configuration( )."); } diff --git a/src/Keithley_6487.cpp b/src/Keithley_6487.cpp index 1a076aed15c111e82c81ddb11727524bfa4cfbb3..95e499548ea4d3850adca8ede4be1fad647129f4 100644 --- a/src/Keithley_6487.cpp +++ b/src/Keithley_6487.cpp @@ -18,7 +18,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_6487.h" #include "KeithleySCPIProtocol.h" /* @@ -76,14 +76,14 @@ bool Keithley_6487::init_protocol (void) KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) _kscpi->set_isDiffSuportedMode(true); - + 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(), @@ -92,7 +92,7 @@ bool Keithley_6487::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -104,10 +104,10 @@ bool Keithley_6487::init_protocol (void) // ============================================================================ // Keithley_6487::range_up // ============================================================================ -void Keithley_6487::range_up (void) +void Keithley_6487::range_up (void) { std::stringstream cmd_to_send; - + //- update range index from hardware this->get_ElectroMeterRange( ); @@ -116,7 +116,7 @@ std::stringstream cmd_to_send; if(_range > K6487_rangeLimit) { _range = K6487_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6487::range_up( )."); } @@ -130,7 +130,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6487::range_down // ============================================================================ -void Keithley_6487::range_down (void) +void Keithley_6487::range_down (void) { std::stringstream cmd_to_send; @@ -142,7 +142,7 @@ std::stringstream cmd_to_send; if(_range < 0) { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_6487::range_down( )."); } @@ -154,7 +154,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6487::setAmperMeterMode // ============================================================================ -void Keithley_6487::setAmperMeterMode (void) +void Keithley_6487::setAmperMeterMode (void) { _electrometerProtocol->setAmperMeterMode( ); } @@ -162,66 +162,61 @@ void Keithley_6487::setAmperMeterMode (void) // ============================================================================ // Keithley_6487::get_integratedValue // ============================================================================ -std::vector<double> Keithley_6487::get_integratedValue (void) +std::vector<double> Keithley_6487::get_integratedValue (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(!_kscpi) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Dynamic cast failed !.", "Keithley_6487::get_integratedValue( )."); return _kscpi->get_integratedValue( ); -} +} // ============================================================================ // Keithley_6487::get_fetchValue // ============================================================================ -std::vector<double> Keithley_6487::get_fetchValue (void) +std::vector<double> Keithley_6487::get_fetchValue (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(!_kscpi) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Dynamic cast failed !.", "Keithley_6487::get_fetchValue( )."); return _kscpi->get_fetchValue( ); -} +} // ============================================================================ // Keithley_6487::update_range // ============================================================================ -//void Keithley_6487::update_range (void) -std::string Keithley_6487::get_ElectroMeterRange (void) +//void Keithley_6487::update_range (void) +std::string Keithley_6487::get_ElectroMeterRange (void) { -std::string range_str(""); -double rangeValueReturned = 0; -double rangeValueCalculated = 0; -double delta = 0; - /** * NOTE : SCPI models return a range value +/- 5% */ //- get range from hardware - range_str = _electrometerProtocol->get_range( ); + std::string range_str = _electrometerProtocol->get_range( ); //- convert range in decimal value - rangeValueReturned = XString<double>::convertFromString(range_str); - + double rangeValueReturned = XString<double>::convertFromString(range_str); + //- find and return the index short idx = 0; for(idx=0; idx<K6487_rangeLimit ; idx++) { - rangeValueCalculated = XString<double>::convertFromString(K6487_rangeValue[idx]); - delta = rangeValueCalculated * 5 / 100; + double rangeValueCalculated = XString<double>::convertFromString(K6487_rangeValue[idx]); + double delta = rangeValueCalculated * 5 / 100; if( (rangeValueCalculated + delta) >= rangeValueReturned && (rangeValueCalculated - delta) <= rangeValueReturned) break; } //- throw if index not found if(idx == K6487_rangeLimit) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Failed to get range index.", "Keithley_6487::get_ElectroMeterRange( )."); - + //- update range with the index found this->_range = idx; @@ -231,13 +226,13 @@ double delta = 0; // ============================================================================ // Keithley_6487::set_knplc // ============================================================================ -void Keithley_6487::set_knplc (double numPLC) +void Keithley_6487::set_knplc (double numPLC) { std::stringstream cmd_to_send; if(numPLC < 0.01 || numPLC > 5.0) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid number of PLC.\n Please enter a value in the range 0.01 to 5.0.", "Keithley_6487::set_knplc( )."); } @@ -247,18 +242,18 @@ std::stringstream cmd_to_send; cmd_to_send << numPLC << std::endl; //- default conversion rate _electrometerProtocol->set_knplc(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6487::set_triggercount // ============================================================================ -void Keithley_6487::set_triggercount (short trigCounts) +void Keithley_6487::set_triggercount (short trigCounts) { std::stringstream cmd_to_send; if(trigCounts == 0 || trigCounts > 2048) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid trigger count.\n Please enter a value in the range 1 to 2048 or set -1 for INFinite.", "Keithley_6487::set_triggercount( )."); } @@ -271,18 +266,18 @@ std::stringstream cmd_to_send; _trigCounts = trigCounts; //- default conversion rate _electrometerProtocol->set_triggercount(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6487::set_buffer_size // ============================================================================ -void Keithley_6487::set_buffer_size (short size) +void Keithley_6487::set_buffer_size (short size) { std::stringstream cmd_to_send; if(size < 1 || size > 3000) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid buffer size. \nPlease enter a value in the range 1 to 3000.", "Keithley_6487::set_buffer_size( )."); } @@ -292,12 +287,12 @@ std::stringstream cmd_to_send; cmd_to_send << size << std::endl; //- default conversion rate _electrometerProtocol->set_buffer_size(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6487::set_integrationTime // ============================================================================ -void Keithley_6487::set_integrationTime (double seconds) +void Keithley_6487::set_integrationTime (double seconds) { //- set the number of Power Line Cycle(s) -> Fast integration _numPLC = 0.05; @@ -311,7 +306,7 @@ void Keithley_6487::set_integrationTime (double seconds) // ============================================================================ // Keithley_6487::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_6487::init_keithley (void) +void Keithley_6487::init_keithley (void) { //- get data only (no timestamp info ... wanted!) _electrometerProtocol->read_data_with_no_timestamp(); @@ -334,11 +329,11 @@ void Keithley_6487::init_keithley (void) // ============================================================================ // Keithley_6487::save_configuration // ============================================================================ -void Keithley_6487::save_configuration (unsigned short memoryIdx) +void Keithley_6487::save_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6487::save_configuration( )."); } @@ -348,11 +343,11 @@ void Keithley_6487::save_configuration (unsigned short memoryIdx) // ============================================================================ // Keithley_6487::restore_configuration // ============================================================================ -void Keithley_6487::restore_configuration (unsigned short memoryIdx) +void Keithley_6487::restore_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6487::restore_configuration( )."); } diff --git a/src/Keithley_6512.cpp b/src/Keithley_6512.cpp index 99b6f43c3f5a9ffba660054065385b915e0987c4..8919229c04d557b2cdb1013c82a06938f38cc4b4 100644 --- a/src/Keithley_6512.cpp +++ b/src/Keithley_6512.cpp @@ -18,7 +18,7 @@ #include <stdexcept> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_6512.h" #include "KeithleyDDCProtocol.h" @@ -80,7 +80,7 @@ bool Keithley_6512::init_protocol (void) 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(), @@ -89,7 +89,7 @@ bool Keithley_6512::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -101,7 +101,7 @@ bool Keithley_6512::init_protocol (void) // ============================================================================ // Keithley_6512::autoRange_off // ============================================================================ -void Keithley_6512::autoRange_off (void) +void Keithley_6512::autoRange_off (void) { KeithleyDDCProtocol* _kddc = dynamic_cast<KeithleyDDCProtocol*>(_electrometerProtocol); if(_kddc) @@ -111,11 +111,11 @@ void Keithley_6512::autoRange_off (void) // ============================================================================ // Keithley_6512::range_up // ============================================================================ -void Keithley_6512::range_up (void) +void Keithley_6512::range_up (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range += 1; @@ -123,7 +123,7 @@ std::stringstream cmd_to_send; if(_range > K6512_rangeLimit) { _range = K6512_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6512::range_up( )."); } @@ -136,11 +136,11 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6512::range_down // ============================================================================ -void Keithley_6512::range_down (void) +void Keithley_6512::range_down (void) { std::stringstream cmd_to_send; - // force read of range on instrument to update _range variable + // force read of range on instrument to update _range variable this->get_configuration(); _range -= 1; @@ -148,11 +148,11 @@ std::stringstream cmd_to_send; if(_range < 0) { _range =0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_6512::range_down( )."); } - + //- build and send the command cmd_to_send << _range << std::endl; _electrometerProtocol->set_range(cmd_to_send.str()); @@ -161,7 +161,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6512::get_ElectroMeterRange // ============================================================================ -std::string Keithley_6512::get_ElectroMeterRange (void) +std::string Keithley_6512::get_ElectroMeterRange (void) { // get config from instrument to update _range variable this->get_configuration(); @@ -172,9 +172,9 @@ std::string Keithley_6512::get_ElectroMeterRange (void) // ============================================================================ // Keithley_6512::set_buffer_size() // ============================================================================ -void Keithley_6512::set_buffer_size (short ) +void Keithley_6512::set_buffer_size (short ) { - throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", + throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", "The 6512 Keithley device buffer size cannot be set (it stores up to 100 points internally.)", "Keithley_6512::set_triggerMode( )."); } @@ -182,10 +182,10 @@ void Keithley_6512::set_buffer_size (short ) // ============================================================================ // Keithley_6512::set_triggerMode // ============================================================================ -void Keithley_6512::set_triggerMode (short trigMod) +void Keithley_6512::set_triggerMode (short trigMod) { if(trigMod<0 || trigMod>K6512_triggerModeLimit) - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Trigger mode value invalid. Please enter a value in the range 0 - 7.", "Keithley_6512::set_triggerMode( )."); @@ -201,7 +201,7 @@ void Keithley_6512::set_triggerMode (short trigMod) // ============================================================================ // Keithley_6512::get_ElectroMeterMode // ============================================================================ -std::string Keithley_6512::get_ElectroMeterMode (void) +std::string Keithley_6512::get_ElectroMeterMode (void) { // get config from instrument to update _mode variable this->get_configuration(); @@ -212,7 +212,7 @@ std::string Keithley_6512::get_ElectroMeterMode (void) // ============================================================================ // Keithley_6512::setAmperMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_6512::setAmperMeterMode (void) +void Keithley_6512::setAmperMeterMode (void) { _electrometerProtocol->setAmperMeterMode( ); } @@ -220,7 +220,7 @@ void Keithley_6512::setAmperMeterMode (void) // ============================================================================ // Keithley_6512::setVoltMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_6512::setVoltMeterMode (void) +void Keithley_6512::setVoltMeterMode (void) { _electrometerProtocol->setVoltMeterMode( ); } @@ -228,7 +228,7 @@ void Keithley_6512::setVoltMeterMode (void) // ============================================================================ // Keithley_6512::setOhmMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_6512::setOhmMeterMode (void) +void Keithley_6512::setOhmMeterMode (void) { _electrometerProtocol->setOhmMeterMode( ); } @@ -236,7 +236,7 @@ void Keithley_6512::setOhmMeterMode (void) // ============================================================================ // Keithley_6512::setCoulombMeterMode (617 & 6512 Keithley DDC models // ============================================================================ -void Keithley_6512::setCoulombMeterMode (void) +void Keithley_6512::setCoulombMeterMode (void) { _electrometerProtocol->setCoulombMeterMode( ); } @@ -244,7 +244,7 @@ void Keithley_6512::setCoulombMeterMode (void) // ============================================================================ // Keithley_6512::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_6512::init_keithley (void) +void Keithley_6512::init_keithley (void) { //- set trigger mode this->set_triggerMode(_trigMod); @@ -323,8 +323,8 @@ std::string Keithley_6512::electrometer_status (void) catch(...) { set_electroState(ALARM); - - throw electrometer::ElectrometerException("UNKNOWN_ERROR", + + throw electrometer::ElectrometerException("UNKNOWN_ERROR", "Cannot extract device error status.", "Keithley_6512::electrometer_status( )."); } @@ -337,12 +337,12 @@ std::string Keithley_6512::electrometer_status (void) // Keithley_6512::get_configuration // ============================================================================ std::string Keithley_6512::get_configuration (void) -{ +{ std::string _kstatus("undefined status"); std::string argout("undefined status"); std::string tmp(""); - //- read keithley status from HW + //- read keithley status from HW _kstatus = _electrometerProtocol->get_DDC_configuration(); //- build status @@ -534,7 +534,7 @@ std::string Keithley_6512::get_configuration (void) { set_electroState(ALARM); - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Cannot extract device status [find or substr failed !].", "Keithley_6512::get_configuration( )."); } diff --git a/src/Keithley_6514.cpp b/src/Keithley_6514.cpp index 91c4893b350f56dce0a13f6b085df4627d5269bb..6d56793f80f4acd5cac848cf4ebef379a6f9f6a5 100644 --- a/src/Keithley_6514.cpp +++ b/src/Keithley_6514.cpp @@ -18,7 +18,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include <tango.h> //- Tango exceptions #include "Keithley_6514.h" #include "KeithleySCPIProtocol.h" @@ -89,14 +89,14 @@ bool Keithley_6514::init_protocol (void) KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) _kscpi->set_isDiffSuportedMode(true); - + 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(), @@ -105,7 +105,7 @@ bool Keithley_6514::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -117,7 +117,7 @@ bool Keithley_6514::init_protocol (void) // ============================================================================ // Keithley_6514::range_up // ============================================================================ -void Keithley_6514::range_up (void) +void Keithley_6514::range_up (void) { std::stringstream cmd_to_send; @@ -132,7 +132,7 @@ std::stringstream cmd_to_send; if(_range > K6514_AMP_rangeLimit) { _range = K6514_AMP_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6514::range_up( )."); } @@ -144,19 +144,19 @@ std::stringstream cmd_to_send; if(_range > K6514_VOLT_rangeLimit) { _range = K6514_VOLT_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6514::range_up( )."); } _rangeStr = K6514_VOLT_rangeStr[_range]; } - else + else if (_kmode.find("RES") != std::string::npos) { if(_range > K6514_OHM_rangeLimit) { _range = K6514_OHM_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6514::range_up( )."); } @@ -167,14 +167,14 @@ std::stringstream cmd_to_send; if(_range > K6514_COU_rangeLimit) { _range = K6514_COU_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6514::range_up( )."); } _rangeStr = K6514_COU_rangeStr[_range]; } else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6514::range_up( )."); @@ -186,7 +186,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6514::range_down // ============================================================================ -void Keithley_6514::range_down (void) +void Keithley_6514::range_down (void) { std::stringstream cmd_to_send; @@ -199,7 +199,7 @@ std::stringstream cmd_to_send; { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_6514::range_down( )."); } @@ -214,7 +214,7 @@ std::stringstream cmd_to_send; else if (_kmode.find("CHAR") != std::string::npos) cmd_to_send << K6514_COU_rangeStr[_range] << std::endl; else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6514::range_down( )."); @@ -225,23 +225,23 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6514::get_integratedValue // ============================================================================ -std::vector<double> Keithley_6514::get_integratedValue (void) +std::vector<double> Keithley_6514::get_integratedValue (void) { return _electrometerProtocol->get_integratedValue( ); -} +} // ============================================================================ // Keithley_6514::get_fetchValue // ============================================================================ -std::vector<double> Keithley_6514::get_fetchValue (void) +std::vector<double> Keithley_6514::get_fetchValue (void) { return _electrometerProtocol->get_fetchValue( ); -} +} // ============================================================================ -// Keithley_6514::setAmperMeterMode +// Keithley_6514::setAmperMeterMode // ============================================================================ -void Keithley_6514::setAmperMeterMode (void) +void Keithley_6514::setAmperMeterMode (void) { _electrometerProtocol->setAmperMeterMode( ); } @@ -249,7 +249,7 @@ void Keithley_6514::setAmperMeterMode (void) // ============================================================================ // Keithley_6514::setVoltMeterMode // ============================================================================ -void Keithley_6514::setVoltMeterMode (void) +void Keithley_6514::setVoltMeterMode (void) { _electrometerProtocol->setVoltMeterMode( ); } @@ -257,7 +257,7 @@ void Keithley_6514::setVoltMeterMode (void) // ============================================================================ // Keithley_6514::setOhmMeterMode // ============================================================================ -void Keithley_6514::setOhmMeterMode (void) +void Keithley_6514::setOhmMeterMode (void) { _electrometerProtocol->setOhmMeterMode( ); } @@ -265,7 +265,7 @@ void Keithley_6514::setOhmMeterMode (void) // ============================================================================ // Keithley_6514::setCoulombMeterMode // ============================================================================ -void Keithley_6514::setCoulombMeterMode (void) +void Keithley_6514::setCoulombMeterMode (void) { _electrometerProtocol->setCoulombMeterMode( ); } @@ -273,8 +273,8 @@ void Keithley_6514::setCoulombMeterMode (void) // ============================================================================ // Keithley_6514::update_range // ============================================================================ -//void Keithley_6514::update_range (void) -std::string Keithley_6514::get_ElectroMeterRange (void) +//void Keithley_6514::update_range (void) +std::string Keithley_6514::get_ElectroMeterRange (void) { std::string range_str(""); double rangeValueReturned = 0; @@ -284,9 +284,9 @@ double delta = 0; /** * NOTE : SCPI models return a range value +/- 5% */ - //- get device mode + //- get device mode _kmode = AbstractElectrometerClass::get_ElectroMeterMode(); - + //- get range from hardware range_str = _electrometerProtocol->get_range( ); //- convert range in decimal value @@ -305,7 +305,7 @@ double delta = 0; else if ( _kmode.find("CHAR") != std::string::npos ) idx_limit = K6514_COU_rangeLimit; else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6514::get_ElectroMeterRange( )."); @@ -344,7 +344,7 @@ double delta = 0; //- throw if index not found if( idx == idx_limit ) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Failed to get range index.", "Keithley_6514::get_ElectroMeterRange( )."); @@ -357,13 +357,13 @@ double delta = 0; // ============================================================================ // Keithley_6514::set_knplc // ============================================================================ -void Keithley_6514::set_knplc (double numPLC) +void Keithley_6514::set_knplc (double numPLC) { std::stringstream cmd_to_send; if(numPLC < 0.01 || numPLC > 10.0) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid number of PLC.\n Please enter a value in the range 0.01 to 10.0.", "Keithley_6514::set_knplc( )."); } @@ -373,18 +373,18 @@ std::stringstream cmd_to_send; cmd_to_send << numPLC << std::endl; //- default conversion rate _electrometerProtocol->set_knplc(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6514::set_triggercount // ============================================================================ -void Keithley_6514::set_triggercount (short trigCounts) +void Keithley_6514::set_triggercount (short trigCounts) { std::stringstream cmd_to_send; if(trigCounts == 0 || trigCounts > 2500) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid trigger count.\n Please enter a value in the range 1 to 2500 or set -1 for INFinite.", "Keithley_6514::set_triggercount( )."); } @@ -397,18 +397,18 @@ std::stringstream cmd_to_send; _trigCounts = trigCounts; //- default conversion rate _electrometerProtocol->set_triggercount(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6514::set_buffer_size // ============================================================================ -void Keithley_6514::set_buffer_size (short size) +void Keithley_6514::set_buffer_size (short size) { std::stringstream cmd_to_send; if(size < 1 || size > 2500) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid buffer size. \nPlease enter a value in the range 1 to 2500.", "Keithley_6514::set_buffer_size( )."); } @@ -418,12 +418,12 @@ std::stringstream cmd_to_send; cmd_to_send << size << std::endl; //- default conversion rate _electrometerProtocol->set_buffer_size(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6514::set_integrationTime // ============================================================================ -void Keithley_6514::set_integrationTime (double seconds) +void Keithley_6514::set_integrationTime (double seconds) { //- set the number of Power Line Cycle(s) -> Fast integration _numPLC = 0.05; @@ -437,7 +437,7 @@ void Keithley_6514::set_integrationTime (double seconds) // ============================================================================ // Keithley_6514::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_6514::init_keithley (void) +void Keithley_6514::init_keithley (void) { //- get data only (no timestamp info ... wanted!) _electrometerProtocol->read_data_with_no_timestamp(); @@ -460,11 +460,11 @@ void Keithley_6514::init_keithley (void) // ============================================================================ // Keithley_6514::save_configuration // ============================================================================ -void Keithley_6514::save_configuration (unsigned short memoryIdx) +void Keithley_6514::save_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6514::save_configuration( )."); } @@ -474,11 +474,11 @@ void Keithley_6514::save_configuration (unsigned short memoryIdx) // ============================================================================ // Keithley_6514::restore_configuration // ============================================================================ -void Keithley_6514::restore_configuration (unsigned short memoryIdx) +void Keithley_6514::restore_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6514::restore_configuration( )."); } diff --git a/src/Keithley_6517.cpp b/src/Keithley_6517.cpp index c77e745cd4e0d7ebb01d819283b626663438d568..d65dd9af32f694f4a17986cdf22eaeb49d7c0764 100644 --- a/src/Keithley_6517.cpp +++ b/src/Keithley_6517.cpp @@ -18,7 +18,7 @@ #include <sstream> #include <string> #include <math.h> //- for ceil -#include <helpers/XString.h> +#include <Xstring.h> #include "Keithley_6517.h" #include "KeithleySCPIProtocol.h" /* @@ -86,7 +86,7 @@ bool Keithley_6517::init_protocol (void) 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(), @@ -95,7 +95,7 @@ bool Keithley_6517::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -108,7 +108,7 @@ bool Keithley_6517::init_protocol (void) // ============================================================================ // Keithley_6517::range_up // ============================================================================ -void Keithley_6517::range_up (void) +void Keithley_6517::range_up (void) { std::stringstream cmd_to_send; @@ -124,7 +124,7 @@ std::stringstream cmd_to_send; if(_range > K6517_AMP_rangeLimit) { _range = K6517_AMP_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6517::range_up( )."); } @@ -136,19 +136,19 @@ std::stringstream cmd_to_send; if(_range > K6517_VOLT_rangeLimit) { _range = K6517_VOLT_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6517::range_up( )."); } _rangeStr = K6517_VOLT_rangeStr[_range]; } - else + else if (_kmode.find("RES") != std::string::npos) { if(_range > K6517_OHM_rangeLimit) { _range = K6517_OHM_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6517::range_up( )."); } @@ -159,14 +159,14 @@ std::stringstream cmd_to_send; if(_range > K6517_COU_rangeLimit) { _range = K6517_COU_rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "Keithley_6517::range_up( )."); } _rangeStr = K6517_COU_rangeStr[_range]; } else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6517::range_up( )."); @@ -178,7 +178,7 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6517::range_down // ============================================================================ -void Keithley_6517::range_down (void) +void Keithley_6517::range_down (void) { std::stringstream cmd_to_send; @@ -192,7 +192,7 @@ std::stringstream cmd_to_send; { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "Keithley_6517::range_down( )."); } @@ -207,7 +207,7 @@ std::stringstream cmd_to_send; else if (_kmode.find("CHAR") != std::string::npos) cmd_to_send << K6517_COU_rangeStr[_range] << std::endl; else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6517::range_down( )."); @@ -219,23 +219,23 @@ std::stringstream cmd_to_send; // ============================================================================ // Keithley_6517::get_integratedValue // ============================================================================ -std::vector<double> Keithley_6517::get_integratedValue (void) +std::vector<double> Keithley_6517::get_integratedValue (void) { return _electrometerProtocol->get_integratedValue( ); -} +} // ============================================================================ // Keithley_6517::get_fetchValue // ============================================================================ -std::vector<double> Keithley_6517::get_fetchValue (void) +std::vector<double> Keithley_6517::get_fetchValue (void) { return _electrometerProtocol->get_fetchValue( ); -} +} // ============================================================================ -// Keithley_6517::setAmperMeterMode +// Keithley_6517::setAmperMeterMode // ============================================================================ -void Keithley_6517::setAmperMeterMode (void) +void Keithley_6517::setAmperMeterMode (void) { _electrometerProtocol->setAmperMeterMode( ); } @@ -243,7 +243,7 @@ void Keithley_6517::setAmperMeterMode (void) // ============================================================================ // Keithley_6517::setVoltMeterMode // ============================================================================ -void Keithley_6517::setVoltMeterMode (void) +void Keithley_6517::setVoltMeterMode (void) { _electrometerProtocol->setVoltMeterMode( ); } @@ -251,7 +251,7 @@ void Keithley_6517::setVoltMeterMode (void) // ============================================================================ // Keithley_6517::setOhmMeterMode // ============================================================================ -void Keithley_6517::setOhmMeterMode (void) +void Keithley_6517::setOhmMeterMode (void) { _electrometerProtocol->setOhmMeterMode( ); } @@ -259,25 +259,25 @@ void Keithley_6517::setOhmMeterMode (void) // ============================================================================ // Keithley_6517::setCoulombMeterMode // ============================================================================ -void Keithley_6517::setCoulombMeterMode (void) +void Keithley_6517::setCoulombMeterMode (void) { _electrometerProtocol->setCoulombMeterMode( ); } - + // ============================================================================ // Keithley_6517::enable_VSourceOutput // ============================================================================ -void Keithley_6517::enable_VSourceOutput (void) +void Keithley_6517::enable_VSourceOutput (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) _kscpi->setVSourceOutputON(); } - + // ============================================================================ // Keithley_6517::disable_VSourceOutput // ============================================================================ -void Keithley_6517::disable_VSourceOutput (void) +void Keithley_6517::disable_VSourceOutput (void) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) @@ -287,7 +287,7 @@ void Keithley_6517::disable_VSourceOutput (void) // ============================================================================ // Keithley_6517::set_VSourceValue // ============================================================================ -void Keithley_6517::set_VSourceValue (double volts) +void Keithley_6517::set_VSourceValue (double volts) { KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); if(_kscpi) @@ -297,7 +297,7 @@ void Keithley_6517::set_VSourceValue (double volts) // ============================================================================ // Keithley_6517::set_VSourceValue // ============================================================================ -double Keithley_6517::get_VSourceValue (void) +double Keithley_6517::get_VSourceValue (void) { std::string response(""); double volts; @@ -314,8 +314,8 @@ double Keithley_6517::get_VSourceValue (void) // ============================================================================ // Keithley_6517::update_range // ============================================================================ -//void Keithley_6517::update_range (void) -std::string Keithley_6517::get_ElectroMeterRange (void) +//void Keithley_6517::update_range (void) +std::string Keithley_6517::get_ElectroMeterRange (void) { std::string range_str(""); double rangeValueReturned = 0; @@ -325,9 +325,9 @@ double delta = 0; /** * NOTE : SCPI models return a range value +/- 5% */ - //- get device mode + //- get device mode _kmode = AbstractElectrometerClass::get_ElectroMeterMode(); - + //- get range from hardware range_str = _electrometerProtocol->get_range( ); //- convert range in decimal value @@ -346,11 +346,11 @@ double delta = 0; else if (_kmode.find("CHAR") != std::string::npos) idx_limit = K6517_COU_rangeLimit; else - throw electrometer::ElectrometerException("UNKNOWN_MODE", + throw electrometer::ElectrometerException("UNKNOWN_MODE", "Unable to find the electrometer mode used.", "Keithley_6517::get_ElectroMeterRange( )."); - + //- find the range index for ( idx = 0; idx < idx_limit ; idx++ ) { @@ -386,7 +386,7 @@ double delta = 0; //- throw if index not found if( idx == idx_limit ) - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Failed to get range index.", "Keithley_6517::get_ElectroMeterRange( )."); @@ -399,7 +399,7 @@ double delta = 0; // ============================================================================ // Keithley_6517::get_averagecount // ============================================================================ -std::string Keithley_6517::get_averagecount (void) +std::string Keithley_6517::get_averagecount (void) { std::string averCountStr(""); @@ -414,7 +414,7 @@ std::string Keithley_6517::get_averagecount (void) // ============================================================================ // Keithley_6517::set_averagecount // ============================================================================ -void Keithley_6517::set_averagecount (std::string nbAverCountStr) +void Keithley_6517::set_averagecount (std::string nbAverCountStr) { //- this model needs to prefix this command with the current mode KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); @@ -426,7 +426,7 @@ void Keithley_6517::set_averagecount (std::string nbAverCountStr) // ============================================================================ // Keithley_6517::get_averagecontrol // ============================================================================ -std::string Keithley_6517::get_averagecontrol (void) +std::string Keithley_6517::get_averagecontrol (void) { std::string nbAverCtrlStr(""); @@ -441,7 +441,7 @@ std::string Keithley_6517::get_averagecontrol (void) // ============================================================================ // Keithley_6517::set_averagecontrol // ============================================================================ -void Keithley_6517::set_averagecontrol (std::string nbAverCtrlStr) +void Keithley_6517::set_averagecontrol (std::string nbAverCtrlStr) { //- this model needs to prefix this command with the current mode KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); @@ -452,7 +452,7 @@ void Keithley_6517::set_averagecontrol (std::string nbAverCtrlStr) // ============================================================================ // Keithley_6517::averageStateON // ============================================================================ -void Keithley_6517::averageStateON (void) +void Keithley_6517::averageStateON (void) { //- this model needs to prefix this command with the current mode KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); @@ -463,7 +463,7 @@ void Keithley_6517::averageStateON (void) // ============================================================================ // Keithley_6517::averageStateOFF // ============================================================================ -void Keithley_6517::averageStateOFF (void) +void Keithley_6517::averageStateOFF (void) { //- this model needs to prefix this command with the current mode KeithleySCPIProtocol* _kscpi = dynamic_cast<KeithleySCPIProtocol*>(_electrometerProtocol); @@ -474,13 +474,13 @@ void Keithley_6517::averageStateOFF (void) // ============================================================================ // Keithley_6517::set_knplc // ============================================================================ -void Keithley_6517::set_knplc (double numPLC) +void Keithley_6517::set_knplc (double numPLC) { std::stringstream cmd_to_send; if(numPLC <= 0 || numPLC > 10.0) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid number of PLC.\n Please enter a value in the range 0.01 to 10.0.", "Keithley_6517::set_knplc( )."); } @@ -490,18 +490,18 @@ std::stringstream cmd_to_send; cmd_to_send << numPLC << std::endl; //- default conversion rate _electrometerProtocol->set_knplc(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6517::set_triggercount // ============================================================================ -void Keithley_6517::set_triggercount (short trigCounts) +void Keithley_6517::set_triggercount (short trigCounts) { std::stringstream cmd_to_send; if(trigCounts == 0 || trigCounts > 99999) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid trigger count.\n Please enter a value in the range 1 to 99999 or set -1 for INFinite.", "Keithley_6517::set_triggercount( )."); } @@ -514,18 +514,18 @@ std::stringstream cmd_to_send; _trigCounts = trigCounts; //- default conversion rate _electrometerProtocol->set_triggercount(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6517::set_buffer_size // ============================================================================ -void Keithley_6517::set_buffer_size (short size) +void Keithley_6517::set_buffer_size (short size) { std::stringstream cmd_to_send; if(size < 1 || size > 10000) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Invalid buffer size. \nPlease enter a value in the range 1 to 10000.", "Keithley_6517::set_buffer_size( )."); } @@ -535,12 +535,12 @@ std::stringstream cmd_to_send; cmd_to_send << size << std::endl; //- default conversion rate _electrometerProtocol->set_buffer_size(cmd_to_send.str()); -} +} // ============================================================================ // Keithley_6517::set_integrationTime // ============================================================================ -void Keithley_6517::set_integrationTime (double seconds) +void Keithley_6517::set_integrationTime (double seconds) { //- set the number of Power Line Cycle(s) -> Fast integration _numPLC = 0.05; @@ -554,7 +554,7 @@ void Keithley_6517::set_integrationTime (double seconds) // ============================================================================ // Keithley_6517::init_keithley : command to perform an integration cycle // ============================================================================ -void Keithley_6517::init_keithley (void) +void Keithley_6517::init_keithley (void) { //- clear all registers _electrometerProtocol->clear_registers(); @@ -579,23 +579,23 @@ void Keithley_6517::init_keithley (void) } // ============================================================================ -// Keithley_6517:: THIS MODEL DOES NOT SUPPORT THESE COMMANDS +// Keithley_6517:: THIS MODEL DOES NOT SUPPORT THESE COMMANDS // ============================================================================ // ============================================================================ // Keithley_6517::auto_zero_on // ============================================================================ -void Keithley_6517::auto_zero_on (void) +void Keithley_6517::auto_zero_on (void) { - throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", + throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", "This Keithley 6517 does bot support this command.", "Keithley_6517::auto_zero_on( )."); } // ============================================================================ // Keithley_6517::auto_zero_off // ============================================================================ -void Keithley_6517::auto_zero_off (void) +void Keithley_6517::auto_zero_off (void) { - throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", + throw electrometer::ElectrometerException("COMMAND_NOT_SUPPORTED", "This Keithley 6517 does bot support this command.", "Keithley_6517::auto_zero_off( )."); } @@ -603,11 +603,11 @@ void Keithley_6517::auto_zero_off (void) // ============================================================================ // Keithley_6517::save_configuration // ============================================================================ -void Keithley_6517::save_configuration (unsigned short memoryIdx) +void Keithley_6517::save_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-2].", "Keithley_6487::save_configuration( )."); } @@ -617,11 +617,11 @@ void Keithley_6517::save_configuration (unsigned short memoryIdx) // ============================================================================ // Keithley_6517::restore_configuration // ============================================================================ -void Keithley_6517::restore_configuration (unsigned short memoryIdx) +void Keithley_6517::restore_configuration (unsigned short memoryIdx) { if( memoryIdx > MAX_SAVED_CONFIG ) { - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Index of saved configuration must be in the range [0-9].", "Keithley_6517::restore_configuration( )."); } diff --git a/src/N_PhotoConducteur.cpp b/src/N_PhotoConducteur.cpp index 6c278d7e36ef8a790e439b41919acabb3d1fb4c4..e8d2895b4ff076ba3a12f52f74dfae4b12c7f577 100644 --- a/src/N_PhotoConducteur.cpp +++ b/src/N_PhotoConducteur.cpp @@ -18,7 +18,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "N_PhotoConducteur.h" #include "NovelecProtocol.h" /* @@ -31,13 +31,13 @@ static const std::string NType5_rangeValue[] = {"1000","300","100","30"}; //- KO // ============================================================================ // N_PhotoConducteur::N_PhotoConducteur // ============================================================================ -N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short address, short novTypeNumber) -: Novelec_MCCE2(comLink_device_name, address, novTypeNumber) +N_PhotoConducteur::N_PhotoConducteur (std::string& comLink_device_name, short address) +: Novelec_MCCE2(comLink_device_name, address) { //std::cout << "N_PhotoConducteur::N_PhotoConducteur <-" << std::endl; _rangeLimit = 3; - + //std::cout << "N_PhotoConducteur::N_PhotoConducteur ->" << std::endl; } @@ -54,10 +54,10 @@ N_PhotoConducteur::~N_PhotoConducteur (void) // ============================================================================ // N_PhotoConducteur::range_up // ============================================================================ -void N_PhotoConducteur::range_up (void) +void N_PhotoConducteur::range_up (void) { if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::range_up( )."); @@ -68,24 +68,24 @@ std::stringstream cmd_to_send; if(_range > _rangeLimit) { _range = _rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "N_PhotoConducteur::range_up( )."); } //- build and send the command cmd_to_send << _range; - std::cout << "\t N_PhotoConducteur::range_up cmd2send = " << cmd_to_send.str() << std::endl; + _electrometerProtocol->set_range(cmd_to_send.str()); } // ============================================================================ // N_PhotoConducteur::range_down // ============================================================================ -void N_PhotoConducteur::range_down (void) +void N_PhotoConducteur::range_down (void) { if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::range_down( )."); @@ -96,7 +96,7 @@ std::stringstream cmd_to_send; if(_range < 0) { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "N_PhotoConducteur::range_down( )."); } @@ -104,7 +104,7 @@ std::stringstream cmd_to_send; //- build and send the command // _rangeStr = NType1_rangeValue[_range]; cmd_to_send << _range; - std::cout << "\t N_PhotoConducteur::range_up cmd2send = " << cmd_to_send.str() << std::endl; + _electrometerProtocol->set_range(cmd_to_send.str()); } @@ -112,26 +112,26 @@ std::stringstream cmd_to_send; // N_PhotoConducteur::get_ElectroMeterGain // ============================================================================ std::string N_PhotoConducteur::get_ElectroMeterGain (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::get_ElectroMeterGain( )."); - return _electrometerProtocol->get_gain(); + return _electrometerProtocol->get_gain(); } // ============================================================================ // N_PhotoConducteur::set_ElectroMeterGain // ============================================================================ void N_PhotoConducteur::set_ElectroMeterGain (std::string gain) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::set_ElectroMeterGain( )."); - _electrometerProtocol->set_gain(gain); + _electrometerProtocol->set_gain(gain); } // ============================================================================ @@ -142,11 +142,10 @@ void N_PhotoConducteur::set_ElectroMeterRange (std::string rgStr) std::stringstream range_cmd_to_send; if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::set_ElectroMeterRange( )."); - std::cout << "\t N_PhotoConducteur::set_ElectroMeterRange val2set = " << rgStr << std::endl; //- switch the novelec type : switch(_MCCE2electroTypeNumber) { @@ -155,15 +154,14 @@ std::stringstream range_cmd_to_send; case 5 : _range = Novelec_MCCE2::check_range_value(rgStr, NType5_rangeValue); break; } - std::cout << "\t N_PhotoConducteur::set_ElectroMeterRange idx found = " << _range << std::endl; if (_range < 0) - throw electrometer::ElectrometerException("INVALID_PARAMETER", + throw electrometer::ElectrometerException("INVALID_PARAMETER", "This electrometer does not support this range value.", "N_PhotoConducteur::set_ElectroMeterRange( )."); - //- it is OK + //- it is OK range_cmd_to_send << _range; - std::cout << "\t N_PhotoConducteur::set_ElectroMeterRange cmd2send = " << range_cmd_to_send.str() << std::endl; + _electrometerProtocol->set_range(range_cmd_to_send.str()); } @@ -175,13 +173,12 @@ std::string N_PhotoConducteur::get_ElectroMeterRange() std::string rangeStr(""); if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoConducteur::get_ElectroMeterRange( )."); rangeStr = this->_electrometerProtocol->get_range(); - std::cout << "\t N_PhotoConducteur::get_ElectroMeterRange rgVal = $" << rangeStr << "$" << std::endl; //- switch the novelec type : switch(_MCCE2electroTypeNumber) { @@ -190,10 +187,9 @@ std::string rangeStr(""); case 5 : _range = Novelec_MCCE2::check_range_value(rangeStr, NType5_rangeValue); break; } - std::cout << "\t N_PhotoConducteur::get_ElectroMeterRange idx found = " << _range << std::endl; if (_range < 0) - throw electrometer::ElectrometerException("INVALID_PARAMETER", + throw electrometer::ElectrometerException("INVALID_PARAMETER", "Cannot find the applied range value.", "N_PhotoConducteur::get_ElectroMeterRange( )."); diff --git a/src/N_PhotoVoltaique.cpp b/src/N_PhotoVoltaique.cpp index eac66a5353ae4d96ecb9a4ed998da59d7e2c9017..cce39d7fb5ce31a2f1735166427b59d72fd33eae 100644 --- a/src/N_PhotoVoltaique.cpp +++ b/src/N_PhotoVoltaique.cpp @@ -18,7 +18,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "N_PhotoVoltaique.h" #include "NovelecProtocol.h" /* @@ -32,21 +32,11 @@ static const std::string NType3_rangeValue[] = {"1E-08AcC","3E-08AcC","1E-07AcC" // ============================================================================ // N_PhotoVoltaique::N_PhotoVoltaique // ============================================================================ -N_PhotoVoltaique::N_PhotoVoltaique (std::string comLink_device_name, short address, short novTypeNumber) -: Novelec_MCCE2(comLink_device_name, address, novTypeNumber) +N_PhotoVoltaique::N_PhotoVoltaique (std::string comLink_device_name, short address) +: Novelec_MCCE2(comLink_device_name, address) { //std::cout << "N_PhotoVoltaique::N_PhotoVoltaique <-" << std::endl; - //- init range limit - switch(novTypeNumber) - { - case 1 : _rangeLimit = 3; - break; - case 2 : - case 3 : _rangeLimit = 7; - break; - } - //std::cout << "N_PhotoVoltaique::N_PhotoVoltaique ->" << std::endl; } @@ -63,10 +53,10 @@ N_PhotoVoltaique::~N_PhotoVoltaique (void) // ============================================================================ // N_PhotoVoltaique::range_up // ============================================================================ -void N_PhotoVoltaique::range_up (void) +void N_PhotoVoltaique::range_up (void) { if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::range_up( )."); @@ -76,28 +66,37 @@ std::stringstream cmd_to_send; this->get_ElectroMeterRange(); _range += 1; - +/* + //- get range limit + switch(_MCCE2electroTypeNumber) + { + case 1 : _rangeLimit = 3; + break; + case 2 : + case 3 : _rangeLimit = 7; + break; + } +*/ if(_range > _rangeLimit) { _range = _rangeLimit; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range up limit reached.", "N_PhotoVoltaique::range_up( )."); } //- build and send the command cmd_to_send << _range; - std::cout << "\t N_PhotoVoltaique::range_up cmd2send = " << cmd_to_send.str() << std::endl; _electrometerProtocol->set_range(cmd_to_send.str()); } // ============================================================================ // N_PhotoVoltaique::range_down // ============================================================================ -void N_PhotoVoltaique::range_down (void) +void N_PhotoVoltaique::range_down (void) { if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::range_down( )."); @@ -107,11 +106,21 @@ std::stringstream cmd_to_send; this->get_ElectroMeterRange(); _range -= 1; - +/* + //- get range limit + switch(_MCCE2electroTypeNumber) + { + case 1 : _rangeLimit = 3; + break; + case 2 : + case 3 : _rangeLimit = 7; + break; + } +*/ if(_range < 0) { _range = 0; - throw electrometer::ElectrometerException("OUT_OF_RANGE", + throw electrometer::ElectrometerException("OUT_OF_RANGE", "Range down limit reached.", "N_PhotoVoltaique::range_down( )."); } @@ -119,7 +128,7 @@ std::stringstream cmd_to_send; //- build and send the command // _rangeStr = NType1_rangeValue[_range]; cmd_to_send << _range; - std::cout << "\t N_PhotoVoltaique::range_down cmd2send = " << cmd_to_send.str() << std::endl; + _electrometerProtocol->set_range(cmd_to_send.str()); } @@ -127,26 +136,26 @@ std::stringstream cmd_to_send; // N_PhotoVoltaique::get_ElectroMeterFrequency Filter // ============================================================================ std::string N_PhotoVoltaique::get_ElectroMeterFrequency (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::get_ElectroMeterFrequency( )."); - return _electrometerProtocol->get_frequency(); + return _electrometerProtocol->get_frequency(); } // ============================================================================ // N_PhotoVoltaique::set_ElectroMeterFrequency Filter // ============================================================================ void N_PhotoVoltaique::set_ElectroMeterFrequency (std::string freqFilter) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::set_ElectroMeterFrequency( )."); - _electrometerProtocol->set_frequency(freqFilter); + _electrometerProtocol->set_frequency(freqFilter); } // ============================================================================ @@ -157,11 +166,10 @@ void N_PhotoVoltaique::set_ElectroMeterRange (std::string rgStr) std::stringstream range_cmd_to_send; if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::set_ElectroMeterRange( )."); - std::cout << "\t N_PhotoVoltaique::set_ElectroMeterRange val2set = " << rgStr << std::endl; //- switch the novelec type : switch(_MCCE2electroTypeNumber) { @@ -172,15 +180,14 @@ std::stringstream range_cmd_to_send; case 3 : _range = Novelec_MCCE2::check_range_value(rgStr, NType3_rangeValue); break; } - std::cout << "\t N_PhotoVoltaique::set_ElectroMeterRange idx found = " << _range << std::endl; if (_range < 0) - throw electrometer::ElectrometerException("INVALID_PARAMETER", + throw electrometer::ElectrometerException("INVALID_PARAMETER", "This electrometer does not support this range value.", "N_PhotoVoltaique::set_ElectroMeterRange( )."); - //- it is OK + //- it is OK range_cmd_to_send << _range; - std::cout << "\t N_PhotoVoltaique::set_ElectroMeterRange cmd2send = " << range_cmd_to_send.str() << std::endl; + _electrometerProtocol->set_range(range_cmd_to_send.str()); } @@ -192,13 +199,12 @@ std::string N_PhotoVoltaique::get_ElectroMeterRange() std::string rangeStr(""); if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "N_PhotoVoltaique::get_ElectroMeterRange( )."); rangeStr = this->_electrometerProtocol->get_range(); - std::cout << "\t N_PhotoVoltaique::get_ElectroMeterRange rgVal = $" << rangeStr << "$" << std::endl; //- switch the novelec type : switch(_MCCE2electroTypeNumber) { @@ -209,12 +215,11 @@ std::string rangeStr(""); case 3 : _range = Novelec_MCCE2::check_range_value(rangeStr, NType3_rangeValue); break; } - std::cout << "\t N_PhotoVoltaique::get_ElectroMeterRange idx found = " << _range << std::endl; if (_range < 0) - throw electrometer::ElectrometerException("INVALID_PARAMETER", + throw electrometer::ElectrometerException("INVALID_PARAMETER", "Cannot find the applied range value.", "N_PhotoVoltaique::get_ElectroMeterRange( )."); return rangeStr; -} \ No newline at end of file +} diff --git a/src/NovelecProtocol.cpp b/src/NovelecProtocol.cpp index fb85fa7e6720187bc5e6a112bba94a2f586bee1d..60529a59da46359c164d2a5335cb5be6e0293453 100644 --- a/src/NovelecProtocol.cpp +++ b/src/NovelecProtocol.cpp @@ -1,857 +1,821 @@ -// ============================================================================ -// -// = CONTEXT -// TANGO Project - NovelecProtocol Support Library -// -// = FILENAME -// NovelecProtocol.cpp -// -// = AUTHOR -// X. Elattaoui -// -// ============================================================================ - -/* -* NOTE : WARNING !!! -* ------ -* DO AVOID ANY COMMUNICATION BUG, DO NOT END STRINGSTREAMS BY AN 'END OF LINE' -* (i.e. std::endl; ). THE MCCE2 returns bad formatted response !!! -*/ - -// ============================================================================ -// DEPENDENCIES -// ============================================================================ -#include <iostream> -#include <sstream> -#include <string> -#include <helpers/XString.h> -#include "NovelecProtocol.h" -//#include "TangoSerialLink.h" - -//- commands numbers -static const short STATUS_CMD_NUM = 1; -static const short ERRORS_CMD_NUM = 2; -static const short MODE_CMD_NUM = 3; -static const short ELECTROTYPE_CMD_NUM = 4; -static const short POLARITY_CMD_NUM = 5; -static const short FREQUENCY_CMD_NUM = 6; -static const short GAIN_CMD_NUM = 7; -static const short RANGE_CMD_NUM = 8; -static const short RESPONSE_LGTH_CMD_NUM = 17; -static const short CLEAR_ERRORS_CMD_NUM = 18; -static const long PILOTAGE_AND_PROG_RESP_LGTH = 10; -static const long READ_DATA_RESP_LGTH = 24; -//- the specific new line character -static const char END_OF_LINE[] = "\r\n"; -//- modes allowed -static const std::string mode_str[] = {"ERR : UNKNOWN MODE","ZERO V/F","OFFSET","LEAKAGE","TEST","MEASURE"}; -static const std::string range_str[5][8]= { - {"1E-11AcC","3E-11AcC","1E-10AcC","3E-10AcC", "OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"}, - {"1E-10AcC","3E-10AcC","1E-9AcC","3E-9AcC","1E-8AcC","3E-8AcC","1E-7AcC","3E-7AcC"}, - {"1E-8AcC","3E-8AcC","1E-7AcC","3E-7AcC","1E-6AcC","3E-6AcC","1E-5AcC","3E-5AcC"}, - {"1000MOhm","300MOhm","100MOhm","30MOhm","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"}, - {"1000KOhm","300KOhm","100KOhm","30KOhm","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"} -}; -static const std::string frequency_str[]= {"3 Hz","10 Hz","100 Hz","1000 Hz"}; -static const std::string gain_str[] = {"1","10","100"}; - - -// ============================================================================ -// NovelecProtocol::NovelecProtocol -// ============================================================================ -NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress, unsigned short novelecType) -: ElectrometerProtocol(), - _devAdd(devAddress), - _novType(novelecType), - _communication_link(0), - _is_measure_mode_on(false), - _is_explicite_resp_enabled(false) -{ - _commDevName = serial_device_name; - _rangeParameterNum = _novType + 2; - _function = "Not updated"; -} - -// ============================================================================ -// NovelecProtocol::~NovelecProtocol -// ============================================================================ -NovelecProtocol::~NovelecProtocol (void) -{ - std::cout << "NovelecProtocol::~NovelecProtocol <-" << std::endl; -if ( this->_communication_link ) -{ - delete _communication_link; - this->_communication_link = 0; -} - std::cout << "NovelecProtocol::~NovelecProtocol ->" << std::endl; -} - -// ============================================================================ -// NovelecProtocol::build_communicationLink -// ============================================================================ -bool NovelecProtocol::build_communicationLink() -{ - if (_commDevName.empty()) - return false; - - _communication_link = new TangoSerialLink(_commDevName); - - if (!_communication_link) - return false; -std::cout << "NovelecProtocol::build_communicationLink => " << _communication_link << std::endl; - -// this->_tgSerLk = dynamic_cast<TangoSerialLink*>(_communication_link); -// if ( !_tgSerLk ) -// return false; - - return true; -} - -// ============================================================================ -// NovelecProtocol::NovelecProtocol -// ============================================================================ -void NovelecProtocol::init_MCCE2_for_communication(void) -{ -std::stringstream explicite_resp; -std::string tmp("no data"); - -std::cout << "NovelecProtocol::init_MCCE2_for_communication -> _devAdd = " << _devAdd << std::endl; - //- CMD to enable PROG cmds - this->switch_MCCE2_OFF(); //- this command is now called in the MCCE2 device ! -std::cout << "NovelecProtocol::init_MCCE2_for_communication -> switch_MCCE2_OFF" << std::endl; - //- Clear error registers - this->clear_registers(); -std::cout << "NovelecProtocol::init_MCCE2_for_communication -> clear_registers" << std::endl; - - //- send cmd to have an explicite response : - explicite_resp << _devAdd << " PROG " << RESPONSE_LGTH_CMD_NUM << " 1" << END_OF_LINE /* << std::endl */; -// tmp = this->_tgSerLk->write_read(explicite_resp.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(explicite_resp.str(), PILOTAGE_AND_PROG_RESP_LGTH); -std::cout << "NovelecProtocol::init_MCCE2_for_communication -> write_read" << std::endl; - - //- check only the command response - check_command(tmp); -std::cout << "NovelecProtocol::init_MCCE2_for_communication -> check_command" << std::endl; - - //- lock parameters modification - this->switch_MCCE2_ON(); - //- if no error - _is_explicite_resp_enabled = true; -} - -// ============================================================================ -// NovelecProtocol::switch_MCCE2_ON -// ============================================================================ -void NovelecProtocol::switch_MCCE2_ON (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " MEASURE 1 " << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- check only the command response - check_command(tmp); - - _is_measure_mode_on = true; -} - -// ============================================================================ -// NovelecProtocol::switch_MCCE2_OFF -// ============================================================================ -void NovelecProtocol::switch_MCCE2_OFF (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " MEASURE 0 " << END_OF_LINE /* << std::endl */; - - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- check only the command response - check_command(tmp); - - _is_measure_mode_on = false; -} - -// ============================================================================ -// NovelecProtocol::get_mode -// ============================================================================ -std::string NovelecProtocol::get_mode (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << MODE_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - - //- check and extract the response - argout = check_and_extract_data(tmp, MODE_CMD_NUM); - - //- check what is the response mode type - if( !_is_explicite_resp_enabled ) - { - short idx = XString<short>::convertFromString(argout); - _function = mode_str[idx]; - } - else - _function = argout; - - return _function; -} - -// ============================================================================ -// NovelecProtocol::get_value -// ============================================================================ -std::string NovelecProtocol::get_value (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); -std::string value("-1"); -short cmd_num = 13; //- default value for DEBUG !!! - - //- first get mode - get_mode(); - if( (_function.find("OFFSET") != std::string::npos) || (_function.find("V1") != std::string::npos) ) - { - cmd_num = 12; - } - else - if( (_function.find("LEAKAGE") != std::string::npos) || (_function.find("V2") != std::string::npos) ) - cmd_num = 11; - else - std::cout << "\t\t***WARN : Current mode : \"" << get_mode() << "\" has no value available." << std::endl; - - cmd_to_send << _devAdd << " READ " << cmd_num << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - //- check only the command response - value = check_and_extract_data(tmp, cmd_num); - - return value; -} - -// ============================================================================ -// NovelecProtocol::unable_zeroVF_func -// ============================================================================ -void NovelecProtocol::unable_zeroVF_func (void) -{ -std::stringstream cmd_to_send; -std::string cmdNumber(" 1"); //- PROG 1 -> = PROG FUNCTION -std::string tmp("no data"); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- check only the command response - check_command(tmp); - - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::unable_offset_zeroV1_func -// ============================================================================ -void NovelecProtocol::unable_offset_zeroV1_func (void) -{ -std::stringstream cmd_to_send; -std::string cmdNumber(" 2"); //- PROG 1 -> = PROG FUNCTION -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- check only the command response - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::unable_leakage_zeroV2_func -// ============================================================================ -void NovelecProtocol::unable_leakage_zeroV2_func (void) -{ -std::stringstream cmd_to_send; -std::string cmdNumber(" 3"); //- PROG 1 -> = PROG FUNCTION -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- check only the command response - check_command(tmp); - - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::unable_test_func -// ============================================================================ -void NovelecProtocol::unable_test_func (void) -{ -std::stringstream cmd_to_send; -std::string cmdNumber(" 4"); //- PROG 1 -> = PROG FUNCTION -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- check only the command response - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::unable_measure_func -// ============================================================================ -void NovelecProtocol::unable_measure_func (void) -{ -std::stringstream cmd_to_send; -std::string cmdNumber(" 5"); //- PROG 1 -> = PROG FUNCTION -std::string tmp("no data"); - - //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send cmd to have a explicite response : - cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- check only the command response - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_range -// ============================================================================ -std::string NovelecProtocol::get_range (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << RANGE_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); -//std::cout << "NovelecProtocol::get_range -> range brut : " << tmp /* << std::endl */; - //- check and extract the response - argout = check_and_extract_data(tmp, RANGE_CMD_NUM); -std::cout << "\t\t NovelecProtocol::get_range -> range extrait : $" << argout << "$" << std::endl; - - //- check what is the response mode type - short idx = -1; - if( _is_explicite_resp_enabled == false ) - { - idx = XString<short>::convertFromString(argout); - argout = range_str[_novType-1][idx]; -std::cout << "\t\t NovelecProtocol::get_range -> range idx : " << idx << std::endl; - } - - return argout; -} - -// ============================================================================ -// NovelecProtocol::set_range -// ============================================================================ -void NovelecProtocol::set_range (std::string value) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - - //- send command to Novelec device - cmd_to_send << _devAdd << " PROG " << _rangeParameterNum << " " << value << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- the novelec device send ACK/NAK response after a received command - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_polarity -// ============================================================================ -std::string NovelecProtocol::get_polarity (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << POLARITY_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - //- check and extract the response - argout = check_and_extract_data(tmp, POLARITY_CMD_NUM); - - //- check what is the response mode type - if( _is_explicite_resp_enabled == false ) - { - short idx = XString<short>::convertFromString(argout); - if(idx < 0) - argout = "negative"; - else - argout = "positive"; - } - - return argout; -} - -// ============================================================================ -// NovelecProtocol::set_polarity -// ============================================================================ -void NovelecProtocol::set_polarity (std::string newPolarity) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); -unsigned short polarity = 0xFFFF; - - //- check if the MCCE2 is not in MEASURE mode to get/change any settings - if ( newPolarity.find("POSIT") == std::string::npos ) - polarity = 0; //- 0 : positive - else if ( newPolarity.find("NEGAT") == std::string::npos ) - polarity = 1; //- negative - else - { - throw electrometer::ElectrometerException("INVALID_PARAMETER", - "Expected POSITIVE or NEGATIVE in UPPER case.", - "NovelecProtocol::set_polarity( )."); - } - - //- allow parameters modification - this->switch_MCCE2_OFF(); - - //- send command to Novelec device - cmd_to_send << _devAdd << " PROG 2" << " " << newPolarity << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- the novelec device send ACK/NAK response after a received command - check_command(tmp); - - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_frequency -// ============================================================================ -std::string NovelecProtocol::get_frequency (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp(""); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << FREQUENCY_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - - //- check and extract the response - argout = check_and_extract_data(tmp, FREQUENCY_CMD_NUM); - - //- check what is the response mode type - if( _is_explicite_resp_enabled == false ) - { - short idx = XString<short>::convertFromString(argout); - argout = frequency_str[idx]; - } - - return argout; -} - -// ============================================================================ -// NovelecProtocol::set_frequency -// ============================================================================ -void NovelecProtocol::set_frequency (std::string newFrequency) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - - //- send command to Novelec device - cmd_to_send << _devAdd << " PROG 9" << " " << newFrequency << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - //- the novelec device send ACK/NAK response after a received command - check_command(tmp); - - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_gain -// ============================================================================ -std::string NovelecProtocol::get_gain (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << GAIN_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - //- check and extract the response - argout = check_and_extract_data(tmp, GAIN_CMD_NUM); - - //- check what is the response mode type - if( _is_explicite_resp_enabled == false ) - { - short idx = XString<short>::convertFromString(argout); - argout = gain_str[idx]; - } - else - //- erase wildcard char : response received is as this "*10xx" - argout = argout.erase(argout.find('*'),1); - - return argout; -} - -// ============================================================================ -// NovelecProtocol::set_gain -// ============================================================================ -void NovelecProtocol::set_gain (std::string newGain) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send command to Novelec device - cmd_to_send << _devAdd << " PROG 8" << " " << newGain << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- the novelec device send ACK/NAK response after a received command - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_errors -// ============================================================================ -std::string NovelecProtocol::get_errors (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - -//std::cout << "NovelecProtocol::get_errors ..." << std::endl; - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << ERRORS_CMD_NUM << END_OF_LINE /*<< std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); -//std::cout << "NovelecProtocol::write_read -> \"" << tmp << "\"" << std::endl; - //- check and extract the response - argout = check_and_extract_data(tmp, ERRORS_CMD_NUM); -//std::cout << "NovelecProtocol::check_and_extract_data -> \"" << argout << "\"" << std::endl; - - return argout; -} - -// ============================================================================ -// NovelecProtocol::get_electrotype -// ============================================================================ -std::string NovelecProtocol::get_electrotype (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << ELECTROTYPE_CMD_NUM << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - //- check and extract the response - argout = check_and_extract_data(tmp, ELECTROTYPE_CMD_NUM); - - //- check what is the response mode type - if( _is_explicite_resp_enabled == true ) - argout = argout.substr(argout.find(".")+1); - - return argout; -} - -// ============================================================================ -// NovelecProtocol::reset -// ============================================================================ -void NovelecProtocol::reset (void) -{ -std::stringstream cmd_to_send; - - //- send command - cmd_to_send << _devAdd << " RESET" << END_OF_LINE /* << std::endl */; - _communication_link->write(cmd_to_send.str()); - //- there is no response from the device !!! -} - -// ============================================================================ -// NovelecProtocol::local -// ============================================================================ -void NovelecProtocol::local (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send command - cmd_to_send << _devAdd << " LOCAL" << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- check the response - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::remote -// ============================================================================ -void NovelecProtocol::remote (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - // //- check if the MCCE2 is not in MEASURE mode to get/change any settings - //this->is_allowed(); - - //- allow parameters modification - this->switch_MCCE2_OFF(); - //- send command - cmd_to_send << _devAdd << " REMOTE" << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- check the response - check_command(tmp); - //- lock parameters modification - this->switch_MCCE2_ON(); -} - -// ============================================================================ -// NovelecProtocol::get_raw_status -// ============================================================================ -std::string NovelecProtocol::get_raw_status (void) -{ -std::stringstream cmd_to_send; -std::string argout("no data"); -std::string tmp("no data"); - -//std::cout << "NovelecProtocol::get_raw_status ..." << std::endl; - //- send command to Novelec device - cmd_to_send << _devAdd << " READ " << STATUS_CMD_NUM << END_OF_LINE /* << std::endl */; -//std::cout << "NovelecProtocol::cmd_to_send -> \"" << cmd_to_send.str() << "\"" << std::endl; -try -{ - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); -} -catch(Tango::DevFailed& df) -{ -//std::cout << "NovelecProtocol::get_raw_status ...DEVFAILED" << std::endl; -throw df; -} -catch(...) -{ -//std::cout << "NovelecProtocol::get_raw_status ...[...]" << std::endl; -throw; -} - -//std::cout << "NovelecProtocol::write_read -> \"" << tmp << "\"" << std::endl; - //- check and extract the response - argout = check_and_extract_data(tmp, STATUS_CMD_NUM); -//std::cout << "NovelecProtocol::check_and_extract_data -> \"" << argout << "\"" << std::endl; - - return argout; -} - -// ============================================================================ -// NovelecProtocol::clear_registers -// ============================================================================ -void NovelecProtocol::clear_registers (void) -{ -std::stringstream cmd_to_send; -std::string tmp("no data"); - - //- send command - cmd_to_send << _devAdd << " PROG " << CLEAR_ERRORS_CMD_NUM << " 1 " << END_OF_LINE /* << std::endl */; - //tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); - - //- check the response - check_command(tmp); -} - -// ============================================================================ -// NovelecProtocol::is_allowed -// ============================================================================ -void NovelecProtocol::is_allowed (void) -{ - if(this-> _is_measure_mode_on) - throw electrometer::ElectrometerException("COMMAND_NOT_ALLOWED", - "Cannot change parameter(s) when MEASURE mode enabled : call MCCE2_OFF command.", - "NovelecProtocol::check_command( )."); -} - -// ============================================================================ -// NovelecProtocol::check_command -// This method read the device response and check and throw an -// Electrometer Exception if the device response is a NAK. -// Else, it returns the extracted response -// ============================================================================ -void NovelecProtocol::check_command (std::string response) -{ -std::string data; - - //- A correct response is : - // -> "address ACK " : if command well understood - //- An invalid response is: "address NAK ..." - if(response.find("NAK") != std::string::npos) - { - throw electrometer::ElectrometerException("COMMAND_NOT_UNDERSTOOD", - "Bad formatted string command sent -> NAK received !", - "NovelecProtocol::check_command( )."); - } - else - if(response.find("ACK") != std::string::npos) - data = response; - else //- must not exist !!! - throw electrometer::ElectrometerException("INVALID_DATA", - "Invalid string received from Novelec device.", - "NovelecProtocol::check_command( )."); - -} - -// ============================================================================ -// NovelecProtocol::check_and_extract_data -// This method read the device response and check and throw an -// Electrometer Exception if the device response is a NAK. -// Else, it returns the extracted response -// ============================================================================ -std::string NovelecProtocol::check_and_extract_data (std::string response, short cmd_sent) -{ -std::string data; -std::string cmd_sentStr; - - cmd_sentStr = XString<short>::convertToString(cmd_sent); - - //- A correct response is : - // -> "address AWR ReadNum = data " : if there is a returned value - //- An invalid response is: "address NAK ..." - - if(response.find("NAK") != std::string::npos) - { - throw electrometer::ElectrometerException("COMMAND_NOT_UNDERSTOOD", - "Bad formatted string command sent -> NAK received !", - "NovelecProtocol::check_and_extract_data( )."); - } - else - if(response.find("AWR") != std::string::npos) - { - //- check if it is the received answer of the command sent - if(response.find(cmd_sentStr) != std::string::npos) - { - //- extract data in the device response - data = response.substr(response.find("=")+1); - - /* - * check if the response is a short or explicite response - * - * To do so, check if char at idx 18 is a space or a letter : - * if it is a space -> this is a short response - * and must be converted to return the explicite response - * else it is an explicite response and can be returned as this - */ - //- extract char - response = response.substr(18,1); - - //- check what is this char a 'space' or 'letter' - if(response.find(" ") != std::string::npos) - _is_explicite_resp_enabled = false; - else - _is_explicite_resp_enabled = true; - - //- erase first and last space char(s) - data.erase(data.find_last_of(" ")); - size_t pos = data.find(" "); - while ( pos != std::string::npos ) - { - data.erase(pos, 1); - pos = data.find(" "); - } - - /*data.erase(data.find_first_of(" "),1); - data.erase(data.find_last_of(" ")); */ - } - else - throw electrometer::ElectrometerException("SYNCHRONISATION_LOST", - "The received response is not for the command previously sent.", - "NovelecProtocol::check_and_extract_data( )."); - } - else //- must not exist !!! - throw electrometer::ElectrometerException("INVALID_DATA", - "Invalid string received from Novelec device.", - "NovelecProtocol::check_and_extract_data( )."); - - return data; -} +// ============================================================================ +// +// = CONTEXT +// TANGO Project - NovelecProtocol Support Library +// +// = FILENAME +// NovelecProtocol.cpp +// +// = AUTHOR +// X. Elattaoui +// +// ============================================================================ + +/* +* NOTE : WARNING !!! +* ------ +* TO AVOID ANY COMMUNICATION BUG, DO NOT END STRINGSTREAMS BY AN 'END OF LINE' +* (i.e. std::endl; ). THE MCCE2 returns bad formatted response !!! +*/ + +// ============================================================================ +// DEPENDENCIES +// ============================================================================ +#include <iostream> +#include <sstream> +#include <string> +#include <Xstring.h> +#include "NovelecProtocol.h" + +//- commands numbers +static const short STATUS_CMD_NUM = 1; +static const short ERRORS_CMD_NUM = 2; +static const short MODE_CMD_NUM = 3; +static const short ELECTROTYPE_CMD_NUM = 4; +static const short POLARITY_CMD_NUM = 5; +static const short FREQUENCY_CMD_NUM = 6; +static const short GAIN_CMD_NUM = 7; +static const short RANGE_CMD_NUM = 8; +static const short RESPONSE_LGTH_CMD_NUM = 17; +static const short CLEAR_ERRORS_CMD_NUM = 18; +static const long PILOTAGE_AND_PROG_RESP_LGTH = 10; +static const long READ_DATA_RESP_LGTH = 24; +//- the specific new line character +static const char END_OF_LINE[] = "\r\n"; +//- modes allowed +static const std::string mode_str[] = {"ERR : UNKNOWN MODE","ZERO V/F","OFFSET","LEAKAGE","TEST","MEASURE"}; +static const std::string range_str[5][8] = { + {"1E-11AcC","3E-11AcC","1E-10AcC","3E-10AcC", "OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"}, + {"1E-10AcC","3E-10AcC","1E-9AcC","3E-9AcC","1E-8AcC","3E-8AcC","1E-7AcC","3E-7AcC"}, + {"1E-8AcC","3E-8AcC","1E-7AcC","3E-7AcC","1E-6AcC","3E-6AcC","1E-5AcC","3E-5AcC"}, + {"1000MOhm","300MOhm","100MOhm","30MOhm","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"}, + {"1000KOhm","300KOhm","100KOhm","30KOhm","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE","OUT OF RANGE"} +}; +static const std::string frequency_str[]= {"3 Hz","10 Hz","100 Hz","1000 Hz"}; +static const std::string gain_str[] = {"1","10","100"}; + +/* +// ============================================================================ +// NovelecProtocol::NovelecProtocol +// ============================================================================ +NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress, unsigned short novelecType) + : ElectrometerProtocol(), + _devAdd(devAddress), + _novType(novelecType), + _rangeParameterNum(0), + _communication_link(0), + _is_measure_mode_on(false), + _is_explicite_resp_enabled(false) +{ + _commDevName = serial_device_name; + _function = "Not updated"; +} +*/ +// ============================================================================ +// NovelecProtocol::NovelecProtocol +// ============================================================================ +NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress) + : ElectrometerProtocol(), + _devAdd(devAddress), + _novType(0), + _rangeParameterNum(0), + _communication_link(0), + _is_measure_mode_on(false), + _is_explicite_resp_enabled(false) +{ + _commDevName = serial_device_name; + _function = "Not updated"; +} + +// ============================================================================ +// NovelecProtocol::~NovelecProtocol +// ============================================================================ +NovelecProtocol::~NovelecProtocol (void) +{ +// std::cout << "NovelecProtocol::~NovelecProtocol <-" << std::endl; + if ( this->_communication_link ) + { + delete _communication_link; + this->_communication_link = 0; + } +// std::cout << "NovelecProtocol::~NovelecProtocol ->" << std::endl; +} + +// ============================================================================ +// NovelecProtocol::build_communicationLink +// ============================================================================ +bool NovelecProtocol::build_communicationLink() +{ + if (_commDevName.empty()) + return false; + + _communication_link = new TangoSerialLink(_commDevName); + + if (!_communication_link) + return false; + + //- find the connected electrometer type and its ranges + std::string eType = this->check_electrotype(); + this->_novType = XString<short>::convertFromString(eType); + this->_rangeParameterNum = _novType + 2; // NOTE : +2 means => the range command number is the novelec type + 2 ! + + return true; +} + +// ============================================================================ +// NovelecProtocol::NovelecProtocol +// ============================================================================ +void NovelecProtocol::init_MCCE2_for_communication(void) +{ + std::stringstream explicite_resp; + //- CMD to enable PROG cmds + this->switch_MCCE2_OFF(); //- this command is now called in the MCCE2 device ! + + //- Clear error registers + this->clear_registers(); + + //- send cmd to have an explicite response : + explicite_resp << _devAdd << " PROG " << RESPONSE_LGTH_CMD_NUM << " 1" << END_OF_LINE; + std::string tmp = this->_communication_link->write_read(explicite_resp.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); + + //- if no error + _is_explicite_resp_enabled = true; +} + +// ============================================================================ +// NovelecProtocol::check_electrotype +// ============================================================================ +std::string NovelecProtocol::check_electrotype (void) +{ + std::stringstream cmd_to_send; + std::string electroType("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << ELECTROTYPE_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + electroType = check_and_extract_data(tmp, ELECTROTYPE_CMD_NUM); + + //- check what is the response mode type + if( _is_explicite_resp_enabled ) + electroType = electroType.substr(electroType.find(".")+1); + + return electroType; +} + +// ============================================================================ +// NovelecProtocol::get_mode +// ============================================================================ +std::string NovelecProtocol::get_mode (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << MODE_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, MODE_CMD_NUM); + + //- check what is the response mode type + if( !_is_explicite_resp_enabled ) + { + short idx = XString<short>::convertFromString(argout); + _function = mode_str[idx]; + } + else + _function = argout; + + return _function; +} + +// ============================================================================ +// NovelecProtocol::get_value +// ============================================================================ +std::string NovelecProtocol::get_value (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + std::string value("-1"); + short cmd_num = 13; //- default value for DEBUG !!! + + //- first get mode + get_mode(); + + if( (_function.find("OFFSET") != std::string::npos) || (_function.find("V1") != std::string::npos) ) + { + cmd_num = 12; + } + else if( (_function.find("LEAKAGE") != std::string::npos) || (_function.find("V2") != std::string::npos) ) + cmd_num = 11; + else + std::cout << "\t\t***WARN : Current mode : \"" << get_mode() << "\" has no value available." << std::endl; + + cmd_to_send << _devAdd << " READ " << cmd_num << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check only the command response + value = check_and_extract_data(tmp, cmd_num); + + return value; +} + +// ============================================================================ +// NovelecProtocol::switch_MCCE2_ON +// ============================================================================ +void NovelecProtocol::switch_MCCE2_ON (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " MEASURE 1 " << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + _is_measure_mode_on = true; +} + +// ============================================================================ +// NovelecProtocol::switch_MCCE2_OFF +// ============================================================================ +void NovelecProtocol::switch_MCCE2_OFF (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " MEASURE 0 " << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + _is_measure_mode_on = false; +} + +// ============================================================================ +// NovelecProtocol::unable_zeroVF_func +// ============================================================================ +void NovelecProtocol::unable_zeroVF_func (void) +{ + std::stringstream cmd_to_send; + std::string cmdNumber(" 1"); //- PROG 1 -> = PROG FUNCTION + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::unable_offset_zeroV1_func +// ============================================================================ +void NovelecProtocol::unable_offset_zeroV1_func (void) +{ + std::stringstream cmd_to_send; + std::string cmdNumber(" 2"); //- PROG 1 -> = PROG FUNCTION + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::unable_leakage_zeroV2_func +// ============================================================================ +void NovelecProtocol::unable_leakage_zeroV2_func (void) +{ + std::stringstream cmd_to_send; + std::string cmdNumber(" 3"); //- PROG 1 -> = PROG FUNCTION + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::unable_test_func +// ============================================================================ +void NovelecProtocol::unable_test_func (void) +{ + std::stringstream cmd_to_send; + std::string cmdNumber(" 4"); //- PROG 1 -> = PROG FUNCTION + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::unable_measure_func +// ============================================================================ +void NovelecProtocol::unable_measure_func (void) +{ + std::stringstream cmd_to_send; + std::string cmdNumber(" 5"); //- PROG 1 -> = PROG FUNCTION + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send cmd to have a explicite response : + cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check only the command response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_range +// ============================================================================ +std::string NovelecProtocol::get_range (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << RANGE_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, RANGE_CMD_NUM); + + //- check what is the response mode type + if( _is_explicite_resp_enabled == false ) + { + short idx = XString<short>::convertFromString(argout); + argout = range_str[_novType-1][idx]; + } + + return argout; +} + +// ============================================================================ +// NovelecProtocol::set_range +// ============================================================================ +void NovelecProtocol::set_range (std::string value) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send command to Novelec device + cmd_to_send << _devAdd << " PROG " << _rangeParameterNum << " " << value << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- the novelec device send ACK/NAK response after a received command + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_polarity +// ============================================================================ +std::string NovelecProtocol::get_polarity (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << POLARITY_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, POLARITY_CMD_NUM); + + //- check what is the response mode type + if( _is_explicite_resp_enabled == false ) + { + short idx = XString<short>::convertFromString(argout); + if(idx < 0) + argout = "negative"; + else + argout = "positive"; + } + + return argout; +} + +// ============================================================================ +// NovelecProtocol::set_polarity +// ============================================================================ +void NovelecProtocol::set_polarity (std::string newPolarity) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- check if the MCCE2 is not in MEASURE mode to get/change any settings + if ( newPolarity.find("POSIT") == std::string::npos && newPolarity.find("NEGAT") == std::string::npos ) + { + throw electrometer::ElectrometerException("INVALID_PARAMETER", + "Expected POSITIVE or NEGATIVE in UPPER case.", + "NovelecProtocol::set_polarity( )."); + } + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send command to Novelec device + cmd_to_send << _devAdd << " PROG 2" << " " << newPolarity << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- the novelec device send ACK/NAK response after a received command + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_frequency +// ============================================================================ +std::string NovelecProtocol::get_frequency (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp(""); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << FREQUENCY_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, FREQUENCY_CMD_NUM); + + //- check what is the response mode type + if( _is_explicite_resp_enabled == false ) + { + short idx = XString<short>::convertFromString(argout); + argout = frequency_str[idx]; + } + + return argout; +} + +// ============================================================================ +// NovelecProtocol::set_frequency +// ============================================================================ +void NovelecProtocol::set_frequency (std::string newFrequency) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send command to Novelec device + cmd_to_send << _devAdd << " PROG 9" << " " << newFrequency << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- the novelec device send ACK/NAK response after a received command + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_gain +// ============================================================================ +std::string NovelecProtocol::get_gain (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << GAIN_CMD_NUM << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, GAIN_CMD_NUM); + + //- check what is the response mode type + if( _is_explicite_resp_enabled == false ) + { + short idx = XString<short>::convertFromString(argout); + argout = gain_str[idx]; + } + else + //- erase wildcard char : response received is as this "*10xx" + argout = argout.erase(argout.find('*'),1); + + return argout; +} + +// ============================================================================ +// NovelecProtocol::set_gain +// ============================================================================ +void NovelecProtocol::set_gain (std::string newGain) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + //- send command to Novelec device + cmd_to_send << _devAdd << " PROG 8" << " " << newGain << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- the novelec device send ACK/NAK response after a received command + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_errors +// ============================================================================ +std::string NovelecProtocol::get_errors (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << ERRORS_CMD_NUM << END_OF_LINE /*<< std::endl */; + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + + //- check and extract the response + argout = check_and_extract_data(tmp, ERRORS_CMD_NUM); + + return argout; +} + +// ============================================================================ +// NovelecProtocol::reset +// ============================================================================ +void NovelecProtocol::reset (void) +{ + std::stringstream cmd_to_send; + + //- send command + cmd_to_send << _devAdd << " RESET" << END_OF_LINE; + _communication_link->write(cmd_to_send.str()); + //- there is no response from the device !!! +} + +// ============================================================================ +// NovelecProtocol::local +// ============================================================================ +void NovelecProtocol::local (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + //- send command + cmd_to_send << _devAdd << " LOCAL" << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check the response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::remote +// ============================================================================ +void NovelecProtocol::remote (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- allow parameters modification + this->switch_MCCE2_OFF(); + + //- send command + cmd_to_send << _devAdd << " REMOTE" << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check the response + check_command(tmp); + + //- lock parameters modification + this->switch_MCCE2_ON(); +} + +// ============================================================================ +// NovelecProtocol::get_raw_status +// ============================================================================ +std::string NovelecProtocol::get_raw_status (void) +{ + std::stringstream cmd_to_send; + std::string argout("no data"); + std::string tmp("no data"); + + //- send command to Novelec device + cmd_to_send << _devAdd << " READ " << STATUS_CMD_NUM << END_OF_LINE; + + try + { + tmp = this->_communication_link->write_read(cmd_to_send.str(), READ_DATA_RESP_LGTH); + } + catch(Tango::DevFailed& df) + { + throw; + } + catch(...) + { + throw; + } + + //- check and extract the response + argout = check_and_extract_data(tmp, STATUS_CMD_NUM); + + return argout; +} + +// ============================================================================ +// NovelecProtocol::clear_registers +// ============================================================================ +void NovelecProtocol::clear_registers (void) +{ + std::stringstream cmd_to_send; + std::string tmp("no data"); + + //- send command + cmd_to_send << _devAdd << " PROG " << CLEAR_ERRORS_CMD_NUM << " 1 " << END_OF_LINE; + tmp = this->_communication_link->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); + + //- check the response + check_command(tmp); +} + +// ============================================================================ +// NovelecProtocol::is_allowed +// ============================================================================ +void NovelecProtocol::is_allowed (void) +{ + if(this-> _is_measure_mode_on) + throw electrometer::ElectrometerException("COMMAND_NOT_ALLOWED", + "Cannot change parameter(s) when MEASURE mode enabled : call MCCE2_OFF command.", + "NovelecProtocol::check_command( )."); +} + +// ============================================================================ +// NovelecProtocol::check_command +// This method read the device response and check and throw an +// Electrometer Exception if the device response is a NAK. +// Else, it returns the extracted response +// ============================================================================ +void NovelecProtocol::check_command (std::string response) +{ + //- A correct response is : + // -> "address ACK " : if command well understood + //- An invalid response is: "address NAK ..." + if(response.find("NAK") != std::string::npos) + { + throw electrometer::ElectrometerException("COMMAND_NOT_UNDERSTOOD", + "Bad formatted string command sent -> NAK received !", + "NovelecProtocol::check_command( )."); + } + /* else + if(response.find("ACK") != std::string::npos) + data = response; + else //- must not exist !!! + throw electrometer::ElectrometerException("INVALID_DATA", + "Invalid string received from Novelec device.", + "NovelecProtocol::check_command( )."); + */ + +} + +// ============================================================================ +// NovelecProtocol::check_and_extract_data +// This method read the device response and check and throw an +// Electrometer Exception if the device response is a NAK. +// Else, it returns the extracted response +// ============================================================================ +std::string NovelecProtocol::check_and_extract_data (std::string response, short cmd_sent) +{ + std::string data; + std::string cmd_sentStr; + + cmd_sentStr = XString<short>::convertToString(cmd_sent); + + //- A correct response is : + // -> "address AWR ReadNum = data " : if there is a returned value + //- An invalid response is: "address NAK ..." + + if(response.find("NAK") != std::string::npos) + { + throw electrometer::ElectrometerException("COMMAND_NOT_UNDERSTOOD", + "Bad formatted string command sent -> NAK received !", + "NovelecProtocol::check_and_extract_data( )."); + } + else if(response.find("AWR") != std::string::npos) + { + //- check if it is the received answer of the command sent + if(response.find(cmd_sentStr) != std::string::npos) + { + //- extract data in the device response + data = response.substr(response.find("=")+1); + + /* + * check if the response is a short or explicite response + * + * To do so, check if char at idx 18 is a space or a letter : + * if it is a space -> this is a short response + * and must be converted to return the explicite response + * else it is an explicite response it can be returned as this + */ + //- extract char + response = response.substr(18,1); + + //- check what is this char a 'space' or 'letter' + if(response.find(" ") != std::string::npos) + _is_explicite_resp_enabled = false; + else + _is_explicite_resp_enabled = true; + + //- erase first and last space char(s) + data.erase(data.find_last_of(" ")); + size_t pos = data.find(" "); + while ( pos != std::string::npos ) + { + data.erase(pos, 1); + pos = data.find(" "); + } + + /*data.erase(data.find_first_of(" "),1); + data.erase(data.find_last_of(" ")); */ + } + else + throw electrometer::ElectrometerException("SYNCHRONISATION_LOST", + "The received response is not for the command previously sent.", + "NovelecProtocol::check_and_extract_data( )."); + } + else //- must not exist !!! + throw electrometer::ElectrometerException("INVALID_DATA", + "Invalid string received from Novelec device.", + "NovelecProtocol::check_and_extract_data( )."); + + return data; +} diff --git a/src/Novelec_MCCE2.cpp b/src/Novelec_MCCE2.cpp index 04e7eae6d5e0133cfe1184f8ddd89d066288ccf1..1ba93fae72778b41810539efe8ed830f06ee8721 100644 --- a/src/Novelec_MCCE2.cpp +++ b/src/Novelec_MCCE2.cpp @@ -17,7 +17,7 @@ #include <iostream> #include <sstream> #include <string> -#include <helpers/XString.h> +#include <Xstring.h> #include "NovelecProtocol.h" #include "Novelec_MCCE2.h" @@ -25,7 +25,7 @@ // ============================================================================ // Novelec_MCCE2::Novelec_MCCE2 // ============================================================================ -Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address, unsigned short novTypeNumber) +/*Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address, unsigned short novTypeNumber) : AbstractElectrometerClass(comLink_device_name), _rangeLimit(0), _address(address), @@ -35,6 +35,20 @@ Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short a //std::cout << "Novelec_MCCE2::Novelec_MCCE2 ->" << std::endl; } +*/ +// ============================================================================ +// Novelec_MCCE2::Novelec_MCCE2 +// ============================================================================ +Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, unsigned short address) +: AbstractElectrometerClass(comLink_device_name), + _rangeLimit(0), + _address(address), + _MCCE2electroTypeNumber(0) +{ + std::cout << "\t\tNovelec_MCCE2::Novelec_MCCE2 <-" << std::endl; + + std::cout << "\t\tNovelec_MCCE2::Novelec_MCCE2 ->" << std::endl; +} // ============================================================================ // Novelec_MCCE2::~Novelec_MCCE2 @@ -50,21 +64,42 @@ Novelec_MCCE2::~Novelec_MCCE2 (void) // 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); - + _electrometerProtocol = new NovelecProtocol(_device_proxy_name, _address); + if(_electrometerProtocol) - success = _electrometerProtocol->build_communicationLink(); + success = _electrometerProtocol->build_communicationLink(); + + //- find electrometer type : + std::string elecTypeStr(""); + NovelecProtocol* _pNP = dynamic_cast<NovelecProtocol*>(_electrometerProtocol); + if(_pNP) + elecTypeStr = _pNP->check_electrotype(); + + //- get the connected electrometer type : + if(_pNP) + this->_MCCE2electroTypeNumber = _pNP->get_electrometerType(); + + switch(_MCCE2electroTypeNumber) + { + case 1 : + _rangeLimit = 3; + break; + case 2 : + case 3 : + _rangeLimit = 7; + break; + } } 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(), @@ -73,7 +108,7 @@ bool Novelec_MCCE2::init_protocol (void) catch(...) { description = "FAILED to create proxy on : " + _device_proxy_name + ". Caught [...]."; - + Tango::Except::throw_exception ( (const char*)"COMMUNICATION_ERROR", description.c_str(), @@ -86,163 +121,148 @@ bool Novelec_MCCE2::init_protocol (void) // Novelec_MCCE2::get_ElectroMeterPolarity // ============================================================================ std::string Novelec_MCCE2::get_ElectroMeterPolarity (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::get_ElectroMeterPolarity( )."); - return _electrometerProtocol->get_polarity(); + return _electrometerProtocol->get_polarity(); } // ============================================================================ // Novelec_MCCE2::set_ElectroMeterPolarity // ============================================================================ void Novelec_MCCE2::set_ElectroMeterPolarity (std::string polarity) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_ElectroMeterPolarity( )."); - _electrometerProtocol->set_polarity(polarity); + _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", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_Zero_VonF_function( )."); - _electrometerProtocol->unable_zeroVF_func(); + _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", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_Offset_ZeroV1_function( )."); - _electrometerProtocol->unable_offset_zeroV1_func(); + _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", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_Leakage_ZeroV2_function( )."); - _electrometerProtocol->unable_leakage_zeroV2_func(); + _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", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_Test_function( )."); - _electrometerProtocol->unable_test_func(); + _electrometerProtocol->unable_test_func(); } // ============================================================================ // Novelec_MCCE2::set_Measure_function // ============================================================================ void Novelec_MCCE2::set_Measure_function (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::set_Measure_function( )."); - _electrometerProtocol->unable_measure_func(); + _electrometerProtocol->unable_measure_func(); } // ============================================================================ // Novelec_MCCE2::mcce_on // ============================================================================ void Novelec_MCCE2::mcce_on (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::mcce_on( )."); - _electrometerProtocol->switch_MCCE2_ON(); + _electrometerProtocol->switch_MCCE2_ON(); } // ============================================================================ // Novelec_MCCE2::mcce_off // ============================================================================ void Novelec_MCCE2::mcce_off (void) -{ +{ if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::mcce_off( )."); - _electrometerProtocol->switch_MCCE2_OFF(); + _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; + short status = 0; if( !this->_electrometerProtocol ) - throw electrometer::ElectrometerException("INIT_ERROR", + throw electrometer::ElectrometerException("INIT_ERROR", "Novelec protocol initialization failed.", "Novelec_MCCE2::electrometer_status( )."); NovelecProtocol* nproto = dynamic_cast<NovelecProtocol*>(_electrometerProtocol); if( !nproto ) - throw electrometer::ElectrometerException("BAD_ALLOC", + 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) + switch(this->_MCCE2electroTypeNumber) { case 1 : typeStr = "Photovolta�que UHS"; break; @@ -262,22 +282,21 @@ std::string Novelec_MCCE2::electrometer_status (void) //- get Electrometer mode : argout += "Novelec mode : " + _electrometerProtocol->get_mode() + "\n"; - + /***********************************************************************/ - + try { - //- read novelec status from HW + //- read novelec status from HW tmp = _electrometerProtocol->get_raw_status(); -//std::cout << "Novelec_MCCE2::electrometer_status -> tmp = \"" << tmp << "\"" << std::endl; - _status = XString<short>::convertFromString(tmp); -//std::cout << "Novelec_MCCE2::convertFromString -> _status = \"" << _status << "\"" << std::endl; + + status = XString<short>::convertFromString(tmp); } catch(...) { set_electroState(FAULT); - throw electrometer::ElectrometerException("COMMUNICATION_ERROR", + throw electrometer::ElectrometerException("COMMUNICATION_ERROR", "Unable to query the electrmometer status.", "Novelec_MCCE2::electrometer_status( )."); } @@ -286,19 +305,19 @@ std::string Novelec_MCCE2::electrometer_status (void) argout += "------------------------\n"; //- build novelec status - if(_status & 0x10) + if(status & 0x10) argout += "En mesure\n"; else argout += "Hors mesure\n"; - if(_status & 0x20) + if(status & 0x20) argout += "Param�tres par defaut\n"; else argout += "Ram OK\n"; - if(_status & 0x40) + if(status & 0x40) argout += "Param�tre invalide\n"; else argout += "Param�tre OK\n"; - if(_status & 0x80) + if(status & 0x80) { argout += "ERREUR\n"; set_electroState(ALARM); @@ -310,54 +329,61 @@ std::string Novelec_MCCE2::electrometer_status (void) } //- error(s) detail(s) - if(_status & 0x80) - { + if(status & 0x80) + { + short errors = -1; try { //- read novelec error(s) from HW -//std::cout << "Novelec_MCCE2::get_errors ..." << std::endl; tmp = nproto->get_errors(); -//std::cout << "Novelec_MCCE2::convertFromString -> get_errors = \"" << tmp << "\"" << std::endl; - _errors = XString<short>::convertFromString(tmp); -//std::cout << "Novelec_MCCE2::convertFromString -> convertFromString = \"" << _errors << "\"" << std::endl; + errors= XString<short>::convertFromString(tmp); } catch(...) { set_electroState(FAULT); - throw electrometer::ElectrometerException("INTERNAL_ERROR", + throw electrometer::ElectrometerException("INTERNAL_ERROR", "Unable to query the electrmometer errors.", "Novelec_MCCE2::electrometer_status( )."); } argout += "\nError(s) detail(s) :\n"; argout += "------------------------\n"; + bool change_state_to_alarm = true; - if(_errors & 0x01) + if(errors & 0x01) argout += "Param�tre par d�faut\n"; - if(_errors & 0x02) + if(errors & 0x02) argout += "Erreur s�rie\n"; - if(_errors & 0x04) + if(errors & 0x04) argout += "Param�tre invalide\n"; - if(_errors & 0x08) + if(errors & 0x08) + { argout += "Electrom�tre satur�\n"; - if(_errors & 0x10) - argout += "Electrom�tre bloqu�\n"; - if(_errors & 0x20) + change_state_to_alarm = false; + } + if(errors & 0x10) + { + argout += "Electrom�tre bloqu� (Polarity error ?)\n"; + change_state_to_alarm = false; + } + if(errors & 0x20) argout += "HT < limite basse\n"; - if(_errors & 0x40) + if(errors & 0x40) argout += "HT > limite haute\n"; - if(_errors & 0x80) + if(errors & 0x80) argout += "Initialisation\n"; - if(_errors & 0x100) + if(errors & 0x100) argout += "D�faut batterie\n"; - if(_errors & 0x200) + if(errors & 0x200) argout += "D�faut d'alimentation\n"; - if(_errors & 0x400) + if(errors & 0x400) argout += "Type d'�lectrom�tre inconnu\n"; - if(_errors & 0x800) + if(errors & 0x800) argout += "Electrom�tre d�connect�\n"; - - set_electroState(ALARM); + + //- set state according to specifications : if "bloqu�" or "satur�" do not change the state to ALARM !! + if ( change_state_to_alarm ) + set_electroState(ALARM); } return argout; @@ -367,7 +393,7 @@ std::string Novelec_MCCE2::electrometer_status (void) // Novelec_MCCE2::check_range_value // ============================================================================ short Novelec_MCCE2::check_range_value (const std::string& rgToCheck, const std::string* electroRangeList) -{ +{ std::string electroRg(""); for (unsigned int idx = 0; idx <= _rangeLimit; idx++) { diff --git a/src/TangoSerialLink.cpp b/src/TangoSerialLink.cpp index cc32c4dc598a9dfcefaee2871027a80f84a104a5..d5bfcc1da5d0b851212e98e2e80683bc9d5a5301 100644 --- a/src/TangoSerialLink.cpp +++ b/src/TangoSerialLink.cpp @@ -250,12 +250,12 @@ std::string TangoSerialLink::read (long nbCharToRead) throw (Tango::DevFailed) // ============================================================================ std::string TangoSerialLink::write_read (std::string command_to_send, size_t nbChar) throw (Tango::DevFailed) { - if(!_serial_proxy) - create_serial_proxy(); Tango::DeviceData dd_in; Tango::DeviceData dd_out; + + if( !_serial_proxy ) + create_serial_proxy(); - std::string respTmp(""); long flush_in_out = 2; dd_in << flush_in_out;