From 789d56f2ef4504cb5285fa927cd3c1d49269048c Mon Sep 17 00:00:00 2001 From: Xavier Elattaoui <xavier.elattaoui@synchrotron-soleil.fr> Date: Tue, 10 Mar 2009 10:29:14 +0000 Subject: [PATCH] xavier: range values ordered set_range added --- include/AbstractElectrometerClass.h | 9 ++++++-- include/N_PhotoConducteur.h | 5 +++++ include/N_PhotoVoltaique.h | 7 +++++- include/Novelec_MCCE2.h | 13 ++++++++++- src/AbstractElectrometerClass.cpp | 14 +++++++++++- src/N_PhotoConducteur.cpp | 30 +++++++++++++++++++++++-- src/N_PhotoVoltaique.cpp | 34 ++++++++++++++++++++++++++--- src/Novelec_MCCE2.cpp | 17 +++++++++++++++ 8 files changed, 119 insertions(+), 10 deletions(-) diff --git a/include/AbstractElectrometerClass.h b/include/AbstractElectrometerClass.h index 0f34ce8..18650bb 100644 --- a/include/AbstractElectrometerClass.h +++ b/include/AbstractElectrometerClass.h @@ -9,9 +9,13 @@ // // $Author: xavela $ // -// $Revision: 1.14 $ +// $Revision: 1.15 $ // // $Log: not supported by cvs2svn $ +// Revision 1.14 2009/01/19 12:00:25 xavela +// xavier : +// - MCCE2 (Novelec part) : methods to change the active channel to communicate with. +// // Revision 1.13 2008/06/20 14:36:24 xavela // xavier : // - DDC status show only errors if any @@ -197,6 +201,7 @@ public: virtual std::string get_ElectroMeterFrequency (void); virtual std::string get_ElectroMeterGain (void); virtual unsigned short get_ElectroChannel (void); + virtual void set_ElectroMeterRange (std::string rang); virtual void set_ElectroMeterPolarity (std::string pola); virtual void set_ElectroMeterFrequency (std::string freq); virtual void set_ElectroMeterGain (std::string gain); @@ -238,7 +243,7 @@ protected : void set_electroState(ElectroState newState) { electrometerState = newState; }; - short _range; + short _range; std::string _rangeStr; std::string _mode; std::string _device_proxy_name; diff --git a/include/N_PhotoConducteur.h b/include/N_PhotoConducteur.h index 0871b40..80d8e2c 100644 --- a/include/N_PhotoConducteur.h +++ b/include/N_PhotoConducteur.h @@ -48,6 +48,11 @@ public: void range_up (void); void range_down (void); + /** + * \brief Checks and Sets the new range value. + */ + void set_range(std::string range_str); + /** * \brief getters and setters. */ diff --git a/include/N_PhotoVoltaique.h b/include/N_PhotoVoltaique.h index d98d152..746fbc1 100644 --- a/include/N_PhotoVoltaique.h +++ b/include/N_PhotoVoltaique.h @@ -47,7 +47,12 @@ public: */ void range_up (void); void range_down (void); - + + /** + * \brief Checks and Sets the new range value. + */ + void set_range(std::string range_str); + /** * \brief getters and setters. */ diff --git a/include/Novelec_MCCE2.h b/include/Novelec_MCCE2.h index 6cecc12..16c01dd 100644 --- a/include/Novelec_MCCE2.h +++ b/include/Novelec_MCCE2.h @@ -54,6 +54,11 @@ public: void set_Test_function (void); void set_Measure_function (void); + /** + * \brief Sets the new range value + */ + virtual void set_range(std::string range_str) = 0; + /** * \brief Commands to start/stop the data acquisition * @@ -70,8 +75,14 @@ public: std::string electrometer_status (void); protected : - short _rangeLimit; //- define the range limit for each novelec type + unsigned short _rangeLimit; //- define the range limit for each novelec type + unsigned short _MCCE2electroTypeNumber; //- the mcce2 electrometer type number (to check rang value) + /** + * \brief Checks the new range value + */ + short check_range_value(const std::string& rgToCheck, const std::string* electroRangeList); + }; /** @} */ //- end addtogroup diff --git a/src/AbstractElectrometerClass.cpp b/src/AbstractElectrometerClass.cpp index 906567b..960ed64 100644 --- a/src/AbstractElectrometerClass.cpp +++ b/src/AbstractElectrometerClass.cpp @@ -11,9 +11,13 @@ // // $Author: xavela $ // -// $Revision: 1.15 $ +// $Revision: 1.16 $ // // $Log: not supported by cvs2svn $ +// Revision 1.15 2009/01/19 12:00:25 xavela +// xavier : +// - MCCE2 (Novelec part) : methods to change the active channel to communicate with. +// // Revision 1.14 2008/06/20 14:36:23 xavela // xavier : // - DDC status show only errors if any @@ -631,6 +635,14 @@ std::string AbstractElectrometerClass::get_ElectroMeterGain (void) return _electrometerProtocol->get_gain( ); } +// ============================================================================ +// AbstractElectrometerClass::set_ElectroMeterRange +// ============================================================================ +void AbstractElectrometerClass::set_ElectroMeterRange (std::string rang) +{ + _electrometerProtocol->set_range(rang); +} + // ============================================================================ // AbstractElectrometerClass::set_ElectroMeterPolarity // ============================================================================ diff --git a/src/N_PhotoConducteur.cpp b/src/N_PhotoConducteur.cpp index bb4203d..f843917 100644 --- a/src/N_PhotoConducteur.cpp +++ b/src/N_PhotoConducteur.cpp @@ -24,8 +24,8 @@ /* * Valid Range values for a N_PhotoConducteur */ -static const std::string NType_4_rangeValue[] = {"100 MOhms","30 MOhms","10 MOhms","3 MOhms"}; -static const std::string NType_5_rangeValue[] = {"1000 KOhms","300 KOhms","100 KOhms","30 KOhms"}; +static const std::string NType4_rangeValue[] = {"3","10","30","100"}; //- MOhms +static const std::string NType5_rangeValue[] = {"30","100","300","1000"}; //- KOhms // ============================================================================ @@ -123,3 +123,29 @@ void N_PhotoConducteur::set_ElectroMeterGain (std::string gain) "N_PhotoConducteur::set_ElectroMeterGain( )."); _nproto->set_gain(gain); } + +// ============================================================================ +// N_PhotoConducteur::set_range +// ============================================================================ +void N_PhotoConducteur::set_range (std::string rgStr) +{ +short range_idx = -1; +std::stringstream range_cmd_to_send; + + //- switch the novelec type : + switch(_MCCE2electroTypeNumber) + { + case 4 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType4_rangeValue); + break; + case 5 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType5_rangeValue); + break; + } + + if (range_idx < 0) + throw electrometer::ElectrometerException("INVALID_PARAMETER", + "This electrometer does not support this range value.", + "N_PhotoConducteur::set_range( )."); + //- it is OK + range_cmd_to_send << range_idx << std::endl; + _electrometerProtocol->set_range(range_cmd_to_send.str()); +} diff --git a/src/N_PhotoVoltaique.cpp b/src/N_PhotoVoltaique.cpp index 457a6d7..7c65820 100644 --- a/src/N_PhotoVoltaique.cpp +++ b/src/N_PhotoVoltaique.cpp @@ -24,9 +24,9 @@ /* * Valid Range values for a N_PhotoVoltaique */ -static const std::string NType1_rangeValue[] = {"1e-11 A","3e-11 A","1e-10 A","3e-10 A"}; -static const std::string NType2_rangeValue[] = {"1e-10 A","3e-10 A","1e-9 A","3e-9 A","1e-8 A","3e-8 A","1e-7 A","3e-7 A"}; -static const std::string NType3_rangeValue[] = {"1e-8 A","3e-8 A","1e-7 A","3e-7 A","1e-6 A","3e-6 A","1e-5 A","3e-5 A"}; +static const std::string NType1_rangeValue[] = {"3e-11","1e-11","3e-10","1e-10"}; +static const std::string NType2_rangeValue[] = {"3e-10","1e-10","3e-9","1e-9","3e-8","1e-8","3e-7","1e-7"}; +static const std::string NType3_rangeValue[] = {"3e-8","1e-8","3e-7","1e-7","3e-6","1e-6","3e-5","1e-5"}; // ============================================================================ @@ -134,3 +134,31 @@ void N_PhotoVoltaique::set_ElectroMeterFrequency (std::string freqFilter) _nproto->set_frequency(freqFilter); } +// ============================================================================ +// N_PhotoVoltaique::set_range +// ============================================================================ +void N_PhotoVoltaique::set_range (std::string rgStr) +{ +short range_idx = -1; +std::stringstream range_cmd_to_send; + + //- switch the novelec type : + switch(_MCCE2electroTypeNumber) + { + case 1 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType1_rangeValue); + break; + case 2 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType2_rangeValue); + break; + case 3 : range_idx = Novelec_MCCE2::check_range_value(rgStr, NType3_rangeValue); + break; + } + + if (range_idx < 0) + throw electrometer::ElectrometerException("INVALID_PARAMETER", + "This electrometer does not support this range value.", + "N_PhotoVoltaique::set_range( )."); + //- it is OK + range_cmd_to_send << range_idx << std::endl; + _electrometerProtocol->set_range(range_cmd_to_send.str()); +} + diff --git a/src/Novelec_MCCE2.cpp b/src/Novelec_MCCE2.cpp index 17d661b..482a575 100644 --- a/src/Novelec_MCCE2.cpp +++ b/src/Novelec_MCCE2.cpp @@ -27,6 +27,7 @@ // ============================================================================ Novelec_MCCE2::Novelec_MCCE2 (std::string& comLink_device_name, short address, short novTypeNumber) : AbstractElectrometerClass(comLink_device_name), + _MCCE2electroTypeNumber(novTypeNumber), _rangeLimit(0) { //std::cout << "Novelec_MCCE2::Novelec_MCCE2 <-" << std::endl; @@ -266,3 +267,19 @@ std::string Novelec_MCCE2::electrometer_status (void) return argout; } + +// ============================================================================ +// Novelec_MCCE2::check_range_value +// ============================================================================ +short Novelec_MCCE2::check_range_value (const std::string& rgToCheck, const std::string* electroRangeList) +{ + for (unsigned int idx = 0; idx < _rangeLimit; idx++) + { + if(electroRangeList[idx].find(rgToCheck) != std::string::npos) + //- value is in the list + return idx; + } + + //- new range value not found in the electrometer range list ! + return -1; +} -- GitLab