From b6936edc3c1200bae3befbcfe823349dee3ff2a7 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 21 Jan 2010 11:41:48 +0100 Subject: [PATCH] * switch from DeviceProxy -> AttributProxy --- NEWS | 3 ++ src/AxisAdapter.cpp | 78 ++++++++++++++++++++++------------------------- src/AxisAdapter.h | 17 ++++++----- src/PseudoAxesAdapter.cpp | 2 +- src/PseudoAxisAdapter.cpp | 39 +++++------------------- src/PseudoAxisAdapter.h | 1 - src/TangoHKLAdapter.cpp | 34 ++++++++++----------- src/TangoHKLAdapter.h | 1 - 8 files changed, 73 insertions(+), 102 deletions(-) diff --git a/NEWS b/NEWS index 1033d0b..7db8165 100644 --- a/NEWS +++ b/NEWS @@ -11,3 +11,6 @@ - SetCrystalParameterValues - Simulated * WARNING only one diffractometer Device per Server. + * WARNING the RealAxisProxies property format change : AttributeProxy instead of DeviceProxy + - it will be easier to connect something else than an Axis with a position attribut. + - nevertheless it is still necessary to have a Stop command on the related DeviceProxy. diff --git a/src/AxisAdapter.cpp b/src/AxisAdapter.cpp index 32d7165..8d04c89 100644 --- a/src/AxisAdapter.cpp +++ b/src/AxisAdapter.cpp @@ -12,7 +12,8 @@ namespace Diffractometer_ns { _axis_r_real(axis_r_real), _axis_w_real(axis_w_real) { - _device_name = ""; + _proxy_name = ""; + _proxy_stop_command_name = ""; _proxy = NULL; this->from_HklAxis(); _state = Tango::UNKNOWN; @@ -27,42 +28,38 @@ namespace Diffractometer_ns { return ((HklParameter *)(_axis_r))->name; } - Tango::Group *AxisAdapter::connect(std::string const & device_name) + std::string const AxisAdapter::get_proxy_name(void) const { - Tango::Group *group; - std::string name = this->get_name(); + std::string name = ""; + if(_proxy) + return _proxy->get_device_proxy()->name(); + } - // Create a new Group for the axe. - group = new Tango::Group(name); - if(group){ - group->add(device_name); + bool AxisAdapter::connect(char *proxy_name) + { + bool res = false; - // read positions from proxy; - Tango::GroupAttrReplyList reply; - std::vector positions; - reply = group->read_attribute(AXIS_ATTRIBUTE_POSITION_NAME); - if (reply.has_failed()) { - group->remove_all(); - delete group; - group = NULL; - }else{ - reply[0] >> positions; - _device_name = device_name; - _proxy = group->get_device(1); + try{ + _proxy = new Tango::AttributeProxy(proxy_name); + if(_proxy){ + std::vector positions; + + res = true; + + // set the stop command name for now "Stop" should depend of the type of the Device. + _proxy_stop_command_name = "Stop"; + + // read the read/write position + _proxy->read() >> positions; + _proxy_name = proxy_name; hkl_axis_set_value_unit(_axis_r, positions[0]); hkl_axis_set_value_unit(_axis_w, positions[1]); _read = positions[0]; _write = positions[1]; // now read the range - /* - * here an hack due to the - * get_attribute_config signature - * we need a non const char or - * string etc... - */ std::string attr_name = AXIS_ATTRIBUTE_POSITION_NAME; - Tango::AttributeInfo info = _proxy->get_attribute_config(attr_name); + Tango::AttributeInfo info = _proxy->get_config(); // Check if min and max value have been set char const *token; @@ -74,8 +71,9 @@ namespace Diffractometer_ns { if (!strstr(token, "Not specified")) _max = atof(token); } + }catch(Tango::DevFailed &){ } - return group; + return res; } bool const AxisAdapter::is_ready(void) const @@ -115,24 +113,14 @@ namespace Diffractometer_ns { void AxisAdapter::from_proxy(bool simulated) { if(this->is_ready()){ - Tango::DeviceAttribute attr; std::vector positions; // read the position attribute - attr = _proxy->read_attribute(AXIS_ATTRIBUTE_POSITION_NAME); - attr >> positions; + _proxy->read() >> positions; _read_real = positions[0]; _write_real = positions[1]; - // read the range - /* - * here an hack due to the - * get_attribute_config signature - * we need a non const char or - * string etc... - */ - std::string attr_name = AXIS_ATTRIBUTE_POSITION_NAME; - Tango::AttributeInfo info = _proxy->get_attribute_config(attr_name); + Tango::AttributeInfo info = _proxy->get_config(); // Check if min and max value have been set char const *token; @@ -161,10 +149,16 @@ namespace Diffractometer_ns { { #ifdef WRITE_TO_PROXY_ALLOWED if(this->is_ready()){ - Tango::DeviceAttribute attr(AXIS_ATTRIBUTE_POSITION_NAME, _write_real); + Tango::DeviceAttribute attr(_proxy_name, _write_real); _state = Tango::MOVING; - _proxy->write_attribute(attr); + _proxy->write(attr); } #endif } + + void AxisAdapter::stop(void) + { + if(this->is_ready()) + _proxy->get_device_proxy()->command_inout(_proxy_stop_command_name); + } } diff --git a/src/AxisAdapter.h b/src/AxisAdapter.h index b3892e1..db55308 100644 --- a/src/AxisAdapter.h +++ b/src/AxisAdapter.h @@ -20,8 +20,7 @@ namespace Diffractometer_ns { virtual ~AxisAdapter(void); std::string const get_name(void) const; - - std::string const & get_device_name(void) const {return _device_name;} + std::string const get_proxy_name(void) const; Tango::DevState const & get_state(void) const {return _state;} void set_state(Tango::DevState const & state) {_state = state;} @@ -39,11 +38,17 @@ namespace Diffractometer_ns { void write(double value); void from_HklAxis(void); + + void to_proxy(void); + + void stop(void); + private: TangoHKLAdapter * _hklAdapter; - std::string _device_name; - Tango::DeviceProxy *_proxy; + std::string _proxy_name; + std::string _proxy_stop_command_name; + Tango::AttributeProxy *_proxy; HklAxis *_axis_r; HklAxis *_axis_w; HklAxis *_axis_r_real; @@ -56,13 +61,11 @@ namespace Diffractometer_ns { double _max; Tango::DevState _state; // state of axe - Tango::Group *connect(std::string const & device_name); + bool connect(char *proxy_name); void to_HklAxis(void); void from_proxy(bool simulated); - - void to_proxy(void); }; } diff --git a/src/PseudoAxesAdapter.cpp b/src/PseudoAxesAdapter.cpp index e47c4ec..962b79a 100644 --- a/src/PseudoAxesAdapter.cpp +++ b/src/PseudoAxesAdapter.cpp @@ -164,7 +164,7 @@ namespace Diffractometer_ns AxisAdapter const * axis = _axes[i]; ::compose_state(_state, axis->get_state()); if (axis->get_state() != Tango::STANDBY) - status_extra += "\n" + axis->get_device_name() + " is in " + Tango::DevStateName[axis->get_state()]; + status_extra += "\n" + axis->get_proxy_name() + " is in " + Tango::DevStateName[axis->get_state()]; } } _status += Tango::DevStateName[_state]; diff --git a/src/PseudoAxisAdapter.cpp b/src/PseudoAxisAdapter.cpp index a6b6c26..e3e8d8f 100644 --- a/src/PseudoAxisAdapter.cpp +++ b/src/PseudoAxisAdapter.cpp @@ -13,11 +13,10 @@ namespace Diffractometer_ns size_t len; size_t i, j; char const **names; - std::vector &axes = hklAdapter.get_axes(); + std::vector & axes = hklAdapter.get_axes(); _ready = false; _state = Tango::UNKNOWN; - _group = NULL; _axes.clear(); len = HKL_LIST_LEN(_pseudo_r->engine->mode->axes_names); @@ -39,11 +38,6 @@ namespace Diffractometer_ns PseudoAxisAdapter::~PseudoAxisAdapter(void) { - if(_group){ - _group->remove_all(); - delete _group; - _group = NULL; - } } void PseudoAxisAdapter::update(void) @@ -80,7 +74,7 @@ namespace Diffractometer_ns AxisAdapter const * axis = _axes[i]; ::compose_state(_state, axis->get_state()); if (axis->get_state() != Tango::STANDBY) - extra_status += "\n" + axis->get_device_name() + " is in " + Tango::DevStateName[axis->get_state()]; + extra_status += "\n" + axis->get_proxy_name() + " is in " + Tango::DevStateName[axis->get_state()]; } } extra_status += "\nPseudoAxe status: "; @@ -90,29 +84,15 @@ namespace Diffractometer_ns void PseudoAxisAdapter::to_proxies(void) { - if(this->is_ready()){ - long len = _axes.size(); - std::vector values(len); - - for (long i=0; iis_ready()) + for (size_t i=0; i<_axes.size(); ++i) { + _axes[i]->stop(); _axes[i]->from_HklAxis(); - values[i] = _axes[i]->get_write_real(); _axes[i]->set_state(Tango::MOVING); - } - -#ifdef WRITE_TO_PROXY_ALLOWED - // Launch in one time - try - { - _group->command_inout(AXIS_COMMAND_STOP_NAME); - _group->write_attribute(AXIS_ATTRIBUTE_POSITION_NAME, values, true); - } - catch(...) - { - //TODO remove this try catch when tango group will be updated + _axes[i]->to_proxy(); } #endif - } } bool PseudoAxisAdapter::is_ready(void) @@ -124,11 +104,6 @@ namespace Diffractometer_ns if(!_axes[i]->is_ready()) return _ready; _ready = true; - //create the _group - _group = new Tango::Group("tmp"); - if(_group) - for(i=0; i<_axes.size(); ++i) - _group->add(_axes[i]->get_device_name()); } return _ready; } diff --git a/src/PseudoAxisAdapter.h b/src/PseudoAxisAdapter.h index aea17e2..5cb7b33 100644 --- a/src/PseudoAxisAdapter.h +++ b/src/PseudoAxisAdapter.h @@ -34,7 +34,6 @@ namespace Diffractometer_ns { private: TangoHKLAdapter &_hklAdapter; std::string _devicename; - Tango::Group *_group; HklPseudoAxis *_pseudo_r; HklPseudoAxis *_pseudo_w; double _read; diff --git a/src/TangoHKLAdapter.cpp b/src/TangoHKLAdapter.cpp index ce4ffdf..58ff1fe 100644 --- a/src/TangoHKLAdapter.cpp +++ b/src/TangoHKLAdapter.cpp @@ -87,7 +87,6 @@ namespace Diffractometer_ns // Build Group Tango::GroupReply::enable_exception(true); - _proxies = new Tango::Group("Axis"); // fill the axisAdapter. len = HKL_LIST_LEN(_diffractometer->geometry_r->axes); @@ -142,12 +141,6 @@ namespace Diffractometer_ns // remove all axisAdapter _axes.clear(); - if(_proxies) { - _proxies->remove_all(); - delete _proxies; - _proxies = NULL; - } - if (_lambdaAttributeProxy) delete _lambdaAttributeProxy; @@ -206,11 +199,8 @@ namespace Diffractometer_ns char *last; char *axis_name = strtok_r(line, ":", &last); char *proxy_name = strtok_r(NULL, ":", &last); - if (axis.get_name() == axis_name){ - Tango::Group *group = axis.connect(proxy_name); - if(group) - _proxies->add(group); - } + if (axis.get_name() == axis_name) + axis.connect(proxy_name); free(line); } if (!axis.is_ready()) @@ -425,7 +415,7 @@ namespace Diffractometer_ns // first read from the proxy. duration.Stop(); - if(duration.GetDurationInMs() >= 200 && _proxies) { + if(duration.GetDurationInMs() >= 200) { for(size_t i=0; i<_axes.size(); ++i) _axes[i].from_proxy(!_auto_update_from_proxies); duration.Start(); @@ -459,8 +449,14 @@ namespace Diffractometer_ns void TangoHKLAdapter::update_proxies_from_axis_adapters(void) { - _proxies->command_inout(AXIS_COMMAND_STOP_NAME); - for(size_t i=0; i<_axes.size(); ++i) + size_t i; + + // first stop motion of all axes. + for(i=0; i<_axes.size(); ++i) + _axes[i].stop(); + + // then send write values to the proxies + for(i=0; i<_axes.size(); ++i) _axes[i].to_proxy(); } @@ -515,12 +511,12 @@ namespace Diffractometer_ns try { for(unsigned int i=0; i<_axes.size(); ++i) { AxisAdapter const & axis = _axes[i]; - std::string const & device_name = axis.get_device_name(); + std::string proxy_name = axis.get_proxy_name(); Tango::DevState tmpState = axis.get_state(); ::compose_state(state, tmpState); if (tmpState != Tango::STANDBY) - extra_status += "\n" + device_name + " is in " + Tango::DevStateName[tmpState]; + extra_status += "\n" + proxy_name + " is in " + Tango::DevStateName[tmpState]; } } catch(...) { @@ -1372,7 +1368,9 @@ namespace Diffractometer_ns void TangoHKLAdapter::stop_all_axis(void) { #ifdef WRITE_TO_PROXY_ALLOWED - _proxies->command_inout(AXIS_COMMAND_STOP_NAME, true); + size_t i; + for(i=0; i<_axes.size(); ++i) + _axes[i].stop(); #endif } diff --git a/src/TangoHKLAdapter.h b/src/TangoHKLAdapter.h index 502ff5f..7a173b3 100644 --- a/src/TangoHKLAdapter.h +++ b/src/TangoHKLAdapter.h @@ -255,7 +255,6 @@ namespace Diffractometer_ns { std::vector _axes; std::vector _pseudoAxisAdapters; std::vector _pseudoAxesAdapters; - Tango::Group *_proxies; Tango::AttributeProxy *_lambdaAttributeProxy; bool _wrong_nb_of_axis_proxies; -- 2.11.4.GIT