diff --git a/src/TangoEthernetLink.cpp b/src/TangoEthernetLink.cpp index 575954937ec79b61a454a8e7156131de676198a0..f1fa362becb98e1d520417637ff3aede5d167dd9 100644 --- a/src/TangoEthernetLink.cpp +++ b/src/TangoEthernetLink.cpp @@ -55,17 +55,17 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed) try { - //- try - this->_ethernet_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str()); + if (_ethernet_proxy==0) + this->_ethernet_proxy = new Tango::DeviceProxy(_communication_Device_name.c_str()); _ethernet_proxy->ping(); _is_ethernet_proxy_ok = true; } catch(Tango::DevFailed& df ) { - if( this->_ethernet_proxy ) + if(_ethernet_proxy ) { - delete this->_ethernet_proxy; - this->_ethernet_proxy = 0; + delete _ethernet_proxy; + _ethernet_proxy = 0; } _is_ethernet_proxy_ok = false; description = "Unable to create proxy on : " + _communication_Device_name; @@ -77,10 +77,10 @@ void TangoEthernetLink::check_proxy (void) throw (Tango::DevFailed) } catch(...) { - if( this->_ethernet_proxy ) + if( _ethernet_proxy ) { - delete this->_ethernet_proxy; - this->_ethernet_proxy = 0; + delete _ethernet_proxy; + _ethernet_proxy = 0; } _is_ethernet_proxy_ok = false; description = "Unable to create proxy on : " + _communication_Device_name + "\nmemory allocation failed."; @@ -105,33 +105,8 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa Tango::DeviceData dd_in; Tango::DevString argin = 0; - try - { - argin = new char [command_to_send.size() + 1]; - strcpy(argin, command_to_send.c_str()); - } - catch(Tango::DevFailed& df ) - { - if( argin ) - { - delete [] argin; - argin = 0; - } - description = "Unable to write command : " + command_to_send + + "\nmemory allocation failed."; - Tango::Except::re_throw_exception (df, - (const char*)"ALLOCATION_ERROR", - description.c_str(), - (const char*)"TangoEthernetLink::write"); - } - catch(...) - { - description = "Unable to write command : " + command_to_send + "\nmemory allocation failed."; - Tango::Except::throw_exception ( - (const char*)"ALLOCATION_ERROR", - description.c_str(), - (const char*)"TangoEthernetLink::write"); - } - + argin = new char [command_to_send.size() + 1]; + strcpy(argin, command_to_send.c_str()); try { //- try @@ -171,6 +146,10 @@ void TangoEthernetLink::write (std::string command_to_send) throw (Tango::DevFa description.c_str(), (const char*)"TangoEthernetLink::write"); } + if( argin ) + { + delete [] argin; + } } @@ -189,7 +168,6 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed) try { - dd_out = _ethernet_proxy->command_inout("Read"); dd_out >> response; } @@ -217,42 +195,10 @@ std::string TangoEthernetLink::read (void) throw (Tango::DevFailed) std::string TangoEthernetLink::write_read (std::string command_to_send, size_t nbChar) throw (Tango::DevFailed) { std::string resp; - - check_proxy(); - if(!_is_ethernet_proxy_ok) - return ""; - - Tango::DeviceData dd_in; - Tango::DevString argin = 0; - - Tango::DeviceData dd_out; - std::string response(""); - - try - { - argin = new char [command_to_send.size() + 1]; - strcpy(argin, command_to_send.c_str()); - dd_in << argin; - dd_out = _ethernet_proxy->command_inout("WriteRead", dd_in); - dd_out >> response; - } - catch(Tango::DevFailed& df ) - { - Tango::Except::re_throw_exception (df, - (const char*)"COMMUNICATION_ERROR", - (const char*)"Unable to perform a read operation", - (const char*)"TangoEthernetLink::read"); - } - catch(...) - { - Tango::Except::throw_exception ( - (const char*)"COMMUNICATION_ERROR", - (const char*)"Unable to perform a read operation", - (const char*)"TangoEthernetLink::read"); - } - - return response ; - + write(command_to_send); + //- sleep a little bit to let the adapter(RS232/485) to switch mode + omni_thread::sleep(0, 100000000); //100 milliseconds + return read(); }