diff --git a/include/NovelecProtocol.h b/include/NovelecProtocol.h index 9f89837d6e4ae87efed023177a05c589b03d716f..386ea736925d2fd8d668010db17b0679a9b436e4 100644 --- a/include/NovelecProtocol.h +++ b/include/NovelecProtocol.h @@ -116,6 +116,10 @@ protected : std::string check_and_extract_data (std::string resp_to_check, short command_sent); private : + //- check if the MCCE2 is not in MEASURE mode to get/change any settings + void is_allowed(); + + //- if true, parameters cannot be changed ! bool _is_measure_mode_on; //- if true, explicite response mode is enabled diff --git a/pom.xml b/pom.xml index 9cfb636b9d548b2708e81f717eea2a8b595e095c..89060403c2f1b61cbbe02ffa8f19cbde98b2237c 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.0</version> + <version>2.5.1</version> <packaging>nar</packaging> <name>Electrometers library</name> <description>Electrometers library</description> diff --git a/src/NovelecProtocol.cpp b/src/NovelecProtocol.cpp index 955707623f3249598792d6dd18d2ade02dedb9f2..749e8673b23c13865fb0d3c7124ca9b9b6aaf633 100644 --- a/src/NovelecProtocol.cpp +++ b/src/NovelecProtocol.cpp @@ -123,7 +123,8 @@ std::string tmp("no data"); //- send cmd to have a explicite response : cmd_to_send << _devAdd << " MEASURE 1 " << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); - //- check only the command response + + //- check only the command response check_command(tmp); _is_measure_mode_on = true; @@ -142,10 +143,10 @@ std::string tmp("no data"); tmp = _communication_link->write_read(cmd_to_send.str()); - //- check only the command response + //- check only the command response check_command(tmp); - _is_measure_mode_on = false; + _is_measure_mode_on = false; } // ============================================================================ @@ -157,6 +158,9 @@ std::stringstream cmd_to_send; std::string argout("no data"); std::string tmp("no data"); + //- check if the MCCE2 is not in MEASURE mode to get/change any settings + this->is_allowed(); + //- send command to Novelec device cmd_to_send << _devAdd << " READ " << MODE_CMD_NUM << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -215,7 +219,10 @@ std::stringstream cmd_to_send; std::string cmdNumber(" 1"); //- PROG 1 -> = PROG FUNCTION std::string tmp("no data"); - //- send cmd to have a explicite response : + //- check if the MCCE2 is not in MEASURE mode to get/change any settings + this->is_allowed(); + + //- send cmd to have a explicite response : cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); //- check only the command response @@ -231,6 +238,9 @@ 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(); + //- send cmd to have a explicite response : cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -247,6 +257,9 @@ 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(); + //- send cmd to have a explicite response : cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -263,6 +276,9 @@ 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(); + //- send cmd to have a explicite response : cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -279,6 +295,9 @@ 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(); + //- send cmd to have a explicite response : cmd_to_send << _devAdd << " PROG 1 " << cmdNumber << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -320,6 +339,9 @@ 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(); + //- send command to Novelec device cmd_to_send << _devAdd << " PROG " << _rangeParameterNum << " " << value << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -364,6 +386,9 @@ 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 + this->is_allowed(); + //- send command to Novelec device cmd_to_send << _devAdd << " PROG 2" << " " << newPolarity << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -405,6 +430,9 @@ 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(); + //- send command to Novelec device cmd_to_send << _devAdd << " PROG 9" << " " << newFrequency << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -448,6 +476,9 @@ 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(); + //- send command to Novelec device cmd_to_send << _devAdd << " PROG 8" << " " << newGain << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -517,6 +548,9 @@ 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(); + //- send command cmd_to_send << _devAdd << " LOCAL" << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -533,6 +567,9 @@ 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(); + //- send command cmd_to_send << _devAdd << " REMOTE" << END_OF_LINE << std::endl; tmp = _communication_link->write_read(cmd_to_send.str()); @@ -575,6 +612,17 @@ std::string tmp("no data"); 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 @@ -588,12 +636,6 @@ std::string data; //- A correct response is : // -> "address ACK " : if command well understood //- An invalid response is: "address NAK ..." - - if(_is_measure_mode_on) - throw electrometer::ElectrometerException("COMMAND_NOT_ALLOWED", - "Cannot change parameter(s) when MEASURE mode enabled.", - "NovelecProtocol::check_command( )."); - if(response.find("NAK") != std::string::npos) { throw electrometer::ElectrometerException("COMMAND_NOT_UNDERSTOOD",