From 92705e7007e65121c9567d2c9e489a1d3d54fe17 Mon Sep 17 00:00:00 2001 From: Xavier Elattaoui <xavier.elattaoui@synchrotron-soleil.fr> Date: Tue, 10 Apr 2012 08:52:30 +0000 Subject: [PATCH] Bug fixed : the MCCE2 returns a bad formatted response ; this is due to the std::endl added at the end of stringstreams used to send commands !! So, if the std::endl is not added, the electronic communicates correctly (TAKE CARE !!). --- include/NovelecProtocol.h | 3 + include/TangoSerialLink.h | 18 ++++- pom.xml | 2 +- src/NovelecProtocol.cpp | 151 +++++++++++++++++++++++--------------- src/Novelec_MCCE2.cpp | 6 ++ src/TangoSerialLink.cpp | 72 ++++++++++++++++++ 6 files changed, 191 insertions(+), 61 deletions(-) diff --git a/include/NovelecProtocol.h b/include/NovelecProtocol.h index 386ea73..76b36d1 100644 --- a/include/NovelecProtocol.h +++ b/include/NovelecProtocol.h @@ -16,6 +16,7 @@ #include "ElectrometerProtocol.h" #include "ElectrometerException.h" +#include "TangoSerialLink.h" /** * \addtogroup Standard Commands Protocol @@ -119,6 +120,8 @@ private : //- check if the MCCE2 is not in MEASURE mode to get/change any settings void is_allowed(); + TangoSerialLink* _tgSerLk; //- to use SerialLink specific methods ! + //- if true, parameters cannot be changed ! bool _is_measure_mode_on; diff --git a/include/TangoSerialLink.h b/include/TangoSerialLink.h index c8e7535..59a5f8c 100644 --- a/include/TangoSerialLink.h +++ b/include/TangoSerialLink.h @@ -54,19 +54,33 @@ public : void write(std::string cmd) throw (Tango::DevFailed); /** - * \brief Gets hardware response as string. + * \brief Gets hardware response as string. (mode LINE) * * \throws Tango::DevFailed */ std::string read(void) throw (Tango::DevFailed); /** - * \brief Performs a write read operation as string. + * \brief Gets hardware response as string. (read nbCharToRead) + * + * \throws Tango::DevFailed + */ + std::string read(long nbCharToRead) throw (Tango::DevFailed); + + /** + * \brief Performs a write read operation as string. (read in mode LINE) * * \throws Tango::DevFailed */ std::string write_read(std::string cmd) throw (Tango::DevFailed); + /** + * \brief Performs a write read operation as string. (read nb char) + * + * \throws Tango::DevFailed + */ + std::string write_read(std::string cmd, long nbChar) throw (Tango::DevFailed); + private : /** * \brief Initialization. diff --git a/pom.xml b/pom.xml index b818bae..e2d5ade 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.3-SNAPSHOT</version> + <version>2.5.3</version> <packaging>nar</packaging> <name>Electrometers library</name> <description>Electrometers library</description> diff --git a/src/NovelecProtocol.cpp b/src/NovelecProtocol.cpp index 45583c0..62a7c47 100644 --- a/src/NovelecProtocol.cpp +++ b/src/NovelecProtocol.cpp @@ -11,6 +11,13 @@ // // ============================================================================ +/* +* 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 // ============================================================================ @@ -32,6 +39,8 @@ 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 string END_OF_LINE = "\r\n"; //- modes allowed @@ -52,7 +61,8 @@ static const std::string gain_str[] = {"1","10","100"}; NovelecProtocol::NovelecProtocol (std::string& serial_device_name, unsigned short devAddress, unsigned short novelecType) : ElectrometerProtocol(), _devAdd(devAddress), - _novType(novelecType) + _novType(novelecType), + _tgSerLk(0) { _commDevName = serial_device_name; _rangeParameterNum = _novType + 2; @@ -84,6 +94,10 @@ bool NovelecProtocol::build_communicationLink() if (!_communication_link) return false; + this->_tgSerLk = dynamic_cast<TangoSerialLink*>(_communication_link); + if ( !_tgSerLk ) + return false; + return true; } @@ -95,22 +109,22 @@ 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; +//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; +//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; +//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 = _communication_link->write_read(explicite_resp.str()); - std::cout << "NovelecProtocol::init_MCCE2_for_communication -> write_read" << std::endl; + 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); +//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; +//std::cout << "NovelecProtocol::init_MCCE2_for_communication -> check_command" /* << std::endl */; //- if no error _is_explicite_resp_enabled = true; @@ -125,8 +139,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check only the command response check_command(tmp); @@ -143,9 +157,9 @@ 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; + cmd_to_send << _devAdd << " MEASURE 0 " << END_OF_LINE /* << std::endl */; - tmp = _communication_link->write_read(cmd_to_send.str()); + tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); //- check only the command response check_command(tmp); @@ -163,8 +177,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check and extract the response argout = check_and_extract_data(tmp, MODE_CMD_NUM); @@ -203,8 +217,8 @@ short cmd_num = 13; //- default value for DEBUG !!! 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check only the command response value = check_and_extract_data(tmp, cmd_num); @@ -226,8 +240,8 @@ std::string tmp("no data"); //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()); + 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); //- check only the command response check_command(tmp); @@ -250,8 +264,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check only the command response check_command(tmp); //- lock parameters modification @@ -273,8 +287,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check only the command response check_command(tmp); @@ -298,8 +312,8 @@ std::string tmp("no data"); this->switch_MCCE2_OFF(); //- 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()); + 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); //- check only the command response check_command(tmp); //- lock parameters modification @@ -321,8 +335,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check only the command response check_command(tmp); //- lock parameters modification @@ -339,19 +353,19 @@ 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 = _communication_link->write_read(cmd_to_send.str()); -std::cout << "NovelecProtocol::get_range -> range brut : " << tmp << std::endl; + 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); +//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 << "NovelecProtocol::get_range -> range extrait : " << argout << std::endl; +//std::cout << "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]; + argout = range_str[_novType-1][idx]; } return argout; @@ -372,8 +386,8 @@ std::string tmp("no data"); this->switch_MCCE2_OFF(); //- 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()); + 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); //- the novelec device send ACK/NAK response after a received command check_command(tmp); //- lock parameters modification @@ -390,8 +404,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check and extract the response argout = check_and_extract_data(tmp, POLARITY_CMD_NUM); @@ -423,8 +437,8 @@ std::string tmp("no data"); this->switch_MCCE2_OFF(); //- 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()); + 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); //- the novelec device send ACK/NAK response after a received command check_command(tmp); @@ -442,8 +456,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check and extract the response argout = check_and_extract_data(tmp, FREQUENCY_CMD_NUM); @@ -473,8 +487,8 @@ std::string tmp("no data"); this->switch_MCCE2_OFF(); //- 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()); + 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); //- the novelec device send ACK/NAK response after a received command check_command(tmp); @@ -492,8 +506,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check and extract the response argout = check_and_extract_data(tmp, GAIN_CMD_NUM); @@ -524,8 +538,8 @@ 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 << std::endl; - tmp = _communication_link->write_read(cmd_to_send.str()); + 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); //- the novelec device send ACK/NAK response after a received command check_command(tmp); @@ -542,11 +556,14 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); +//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; } @@ -561,8 +578,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check and extract the response argout = check_and_extract_data(tmp, ELECTROTYPE_CMD_NUM); @@ -581,7 +598,7 @@ void NovelecProtocol::reset (void) std::stringstream cmd_to_send; //- send command - cmd_to_send << _devAdd << " RESET" << END_OF_LINE << std::endl; + cmd_to_send << _devAdd << " RESET" << END_OF_LINE /* << std::endl */; _communication_link->write(cmd_to_send.str()); //- there is no response from the device !!! } @@ -600,8 +617,8 @@ std::string tmp("no data"); //- allow parameters modification this->switch_MCCE2_OFF(); //- send command - cmd_to_send << _devAdd << " LOCAL" << END_OF_LINE << std::endl; - tmp = _communication_link->write_read(cmd_to_send.str()); + cmd_to_send << _devAdd << " LOCAL" << END_OF_LINE /* << std::endl */; + tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); //- check the response check_command(tmp); @@ -623,8 +640,8 @@ std::string tmp("no data"); //- allow parameters modification this->switch_MCCE2_OFF(); //- send command - cmd_to_send << _devAdd << " REMOTE" << END_OF_LINE << std::endl; - tmp = _communication_link->write_read(cmd_to_send.str()); + cmd_to_send << _devAdd << " REMOTE" << END_OF_LINE /* << std::endl */; + tmp = this->_tgSerLk->write_read(cmd_to_send.str(), PILOTAGE_AND_PROG_RESP_LGTH); //- check the response check_command(tmp); @@ -641,11 +658,29 @@ 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; - tmp = _communication_link->write_read(cmd_to_send.str()); + 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); +} +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; } @@ -659,8 +694,8 @@ 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 = _communication_link->write_read(cmd_to_send.str()); + 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); //- check the response check_command(tmp); diff --git a/src/Novelec_MCCE2.cpp b/src/Novelec_MCCE2.cpp index bbacdb8..e45e6b0 100644 --- a/src/Novelec_MCCE2.cpp +++ b/src/Novelec_MCCE2.cpp @@ -218,12 +218,15 @@ std::string Novelec_MCCE2::electrometer_status (void) { //- 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; } catch(...) { set_electroState(FAULT); argout = "Unable to query the electrometer status."; + throw; return argout; //throw electrometer::ElectrometerException("COMMUNICATION_ERROR", @@ -264,8 +267,11 @@ std::string Novelec_MCCE2::electrometer_status (void) 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; } catch(...) { diff --git a/src/TangoSerialLink.cpp b/src/TangoSerialLink.cpp index 04cc86b..088a178 100644 --- a/src/TangoSerialLink.cpp +++ b/src/TangoSerialLink.cpp @@ -149,6 +149,7 @@ void TangoSerialLink::write (std::string command_to_send) throw (Tango::DevFail //- try dd_in << argin; this->_serial_proxy->command_inout("DevSerWriteString", dd_in); + //std::cout << "TangoSerialLink::write -> argin = *\"" << argin << "\"*" << std::endl; } catch(Tango::DevFailed& df ) { @@ -190,6 +191,36 @@ std::string TangoSerialLink::read (void) throw (Tango::DevFailed) return this->response ; } +// ============================================================================ +// TangoSerialLink::read +// ============================================================================ +std::string TangoSerialLink::read (long nbCharToRead) throw (Tango::DevFailed) +{ + + if(!_serial_proxy) + create_serial_proxy(); + Tango::DeviceData dd_in; + Tango::DeviceData dd_out; + + try + { + dd_in << nbCharToRead; + //- try get the specified nb characters + dd_out = this->_serial_proxy->command_inout("DevSerReadNChar", dd_in); + dd_out >> this->response; + //std::cout << "TangoSerialLink::read -> nb_char = " << nbCharToRead << " and resp : \"" << this->response << "\"" << std::endl; + } + catch(Tango::DevFailed& df ) + { + Tango::Except::re_throw_exception (df, + (const char*)"COMMUNICATION_ERROR", + (const char*)"Unable to perform a read operation", + (const char*)"TangoSerialLink::read(nChar)"); + } + + return this->response ; +} + // ============================================================================ // TangoSerialLink::write_read // ============================================================================ @@ -216,3 +247,44 @@ std::string TangoSerialLink::write_read (std::string command_to_send) throw (Tan return this->read(); } +// ============================================================================ +// TangoSerialLink::write_read : read N char +// ============================================================================ +std::string TangoSerialLink::write_read (std::string command_to_send, long nbChar) throw (Tango::DevFailed) +{ + if(!_serial_proxy) + create_serial_proxy(); + Tango::DeviceData dd_in; + Tango::DeviceData dd_out; + + std::string respTmp(""); + long flush_in_out = 2; + dd_in << flush_in_out; + + //- Flush buffers ( In & Out = 2 ) + this->_serial_proxy->command_inout("DevSerFlush", dd_in); + + //omni_thread::sleep(0, 200000000); //200 milliseconds + write(command_to_send); + + //- sleep a little bit to let the adapter(RS232/485) to switch mode + //omni_thread::sleep(0, 100000000); //100 milliseconds + + //- wait till characters are available in the input buffer (max 30 retries !) + size_t nbRetries = 0; + Tango::DevLong nbCharReceived = 0; + dd_out = this->_serial_proxy->command_inout("DevSerGetNChar"); + dd_out >> nbCharReceived; + while ( !nbCharReceived && nbRetries < 50 ) + { + dd_out = this->_serial_proxy->command_inout("DevSerGetNChar"); + dd_out >> nbCharReceived; + nbRetries++; +//std::cout << "TangoSerialLink::write_read -> nbRetries = " << nbRetries << " & nbCharReceived = " << nbCharReceived << std::endl; + } + +//std::cout << "END WHILE -> nbRetries = " << nbRetries << " & nbCharReceived = " << nbCharReceived << std::endl; + // now read response from HW + return this->read(nbChar); +} + -- GitLab