1 #include "AxisAdapter.h"
2 #include "TangoHKLAdapter.h"
5 namespace Diffractometer_ns
{
7 AxisAdapter::AxisAdapter(TangoHKLAdapter
* hklAdapter
, HklAxis
*axis_r
, HklAxis
*axis_w
,
8 HklAxis
*axis_r_real
, HklAxis
*axis_w_real
) :
9 _hklAdapter(hklAdapter
),
12 _axis_r_real(axis_r_real
),
13 _axis_w_real(axis_w_real
)
18 _state
= Tango::UNKNOWN
;
21 AxisAdapter::~AxisAdapter(void)
25 std::string
const AxisAdapter::get_name(void) const
27 return ((HklParameter
*)(_axis_r
))->name
;
30 Tango::Group
*AxisAdapter::connect(std::string
const & device_name
)
33 std::string name
= this->get_name();
35 // Create a new Group for the axe.
36 group
= new Tango::Group(name
);
38 group
->add(device_name
);
40 // read positions from proxy;
41 Tango::GroupAttrReplyList reply
;
42 std::vector
<double> positions
;
43 reply
= group
->read_attribute(AXIS_ATTRIBUTE_POSITION_NAME
);
44 if (reply
.has_failed()) {
49 reply
[0] >> positions
;
50 _device_name
= device_name
;
51 _proxy
= group
->get_device(1);
52 hkl_axis_set_value_unit(_axis_r
, positions
[0]);
53 hkl_axis_set_value_unit(_axis_w
, positions
[1]);
55 _write
= positions
[1];
59 * here an hack due to the
60 * get_attribute_config signature
61 * we need a non const char or
64 std::string attr_name
= AXIS_ATTRIBUTE_POSITION_NAME
;
65 Tango::AttributeInfo info
= _proxy
->get_attribute_config(attr_name
);
67 // Check if min and max value have been set
69 token
= info
.min_value
.c_str();
70 if (!strstr(token
, "Not specified"))
73 token
= info
.max_value
.c_str();
74 if (!strstr(token
, "Not specified"))
81 bool const AxisAdapter::is_ready(void) const
89 void AxisAdapter::write(double value
)
91 _hklAdapter
->write_axis(*this, value
);
94 void AxisAdapter::from_HklAxis(void)
96 _read
= hkl_axis_get_value_unit(_axis_r
);
97 _write
= hkl_axis_get_value_unit(_axis_w
);
98 _read_real
= hkl_axis_get_value_unit(_axis_r_real
);
99 _write_real
= hkl_axis_get_value_unit(_axis_w_real
);
100 hkl_axis_get_range_unit(_axis_r
, &_min
, &_max
);
103 void AxisAdapter::to_HklAxis(void)
105 hkl_axis_set_value_unit(_axis_r
, _read
);
106 hkl_axis_set_value_unit(_axis_w
, _write
);
107 hkl_axis_set_range_unit(_axis_r
, _min
, _max
);
108 hkl_axis_set_range_unit(_axis_w
, _min
, _max
);
109 hkl_axis_set_value_unit(_axis_r_real
, _read_real
);
110 hkl_axis_set_value_unit(_axis_w_real
, _write_real
);
111 hkl_axis_set_range_unit(_axis_r_real
, _min
, _max
);
112 hkl_axis_set_range_unit(_axis_w_real
, _min
, _max
);
115 void AxisAdapter::from_proxy(bool simulated
)
117 if(this->is_ready()){
118 Tango::DeviceAttribute attr
;
119 std::vector
<double> positions
;
121 // read the position attribute
122 attr
= _proxy
->read_attribute(AXIS_ATTRIBUTE_POSITION_NAME
);
124 _read_real
= positions
[0];
125 _write_real
= positions
[1];
129 * here an hack due to the
130 * get_attribute_config signature
131 * we need a non const char or
134 std::string attr_name
= AXIS_ATTRIBUTE_POSITION_NAME
;
135 Tango::AttributeInfo info
= _proxy
->get_attribute_config(attr_name
);
137 // Check if min and max value have been set
139 token
= info
.min_value
.c_str();
140 if (!strstr(token
, "Not specified"))
143 token
= info
.max_value
.c_str();
144 if (!strstr(token
, "Not specified"))
148 _state
= _proxy
->state();
152 _write
= _write_real
;
154 _read
= hkl_axis_get_value_unit(_axis_r
);
155 _write
= hkl_axis_get_value_unit(_axis_w
);
160 void AxisAdapter::to_proxy(void)
162 #ifdef WRITE_TO_PROXY_ALLOWED
163 if(this->is_ready()){
164 Tango::DeviceAttribute
attr(AXIS_ATTRIBUTE_POSITION_NAME
, _write_real
);
165 _state
= Tango::MOVING
;
166 _proxy
->write_attribute(attr
);