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
)
16 _proxy_stop_command_name
= "Stop";
17 _proxy_on_command_name
= "On";
20 _state
= Tango::UNKNOWN
;
23 AxisAdapter::~AxisAdapter(void)
27 std::string
const AxisAdapter::get_name(void) const
29 return ((HklParameter
*)(_axis_r
))->name
;
32 std::string
const AxisAdapter::get_proxy_name(void) const
37 bool AxisAdapter::connect(char *proxy_name
)
41 _proxy_name
= proxy_name
;
43 _proxy
= new Tango::AttributeProxy(proxy_name
);
45 std::vector
<double> positions
;
49 // read the read/write position
50 _proxy
->read() >> positions
;
51 hkl_axis_set_value_unit(_axis_r
, positions
[0]);
52 hkl_axis_set_value_unit(_axis_w
, positions
[1]);
54 _write
= positions
[1];
57 std::string attr_name
= AXIS_ATTRIBUTE_POSITION_NAME
;
58 Tango::AttributeInfo info
= _proxy
->get_config();
60 // Check if min and max value have been set
62 token
= info
.min_value
.c_str();
63 if (!strstr(token
, "Not specified"))
66 token
= info
.max_value
.c_str();
67 if (!strstr(token
, "Not specified"))
70 }catch(Tango::DevFailed
&){
71 _state
= Tango::FAULT
;
76 bool const AxisAdapter::is_ready(void) const
84 void AxisAdapter::write(double value
)
86 _hklAdapter
->write_axis(*this, value
);
89 void AxisAdapter::from_HklAxis(void)
91 _read
= hkl_axis_get_value_unit(_axis_r
);
92 _write
= hkl_axis_get_value_unit(_axis_w
);
93 _read_real
= hkl_axis_get_value_unit(_axis_r_real
);
94 _write_real
= hkl_axis_get_value_unit(_axis_w_real
);
95 hkl_axis_get_range_unit(_axis_r
, &_min
, &_max
);
98 void AxisAdapter::to_HklAxis(void)
100 hkl_axis_set_value_unit(_axis_r
, _read
);
101 hkl_axis_set_value_unit(_axis_w
, _write
);
102 hkl_axis_set_range_unit(_axis_r
, _min
, _max
);
103 hkl_axis_set_range_unit(_axis_w
, _min
, _max
);
104 hkl_axis_set_value_unit(_axis_r_real
, _read_real
);
105 hkl_axis_set_value_unit(_axis_w_real
, _write_real
);
106 hkl_axis_set_range_unit(_axis_r_real
, _min
, _max
);
107 hkl_axis_set_range_unit(_axis_w_real
, _min
, _max
);
110 void AxisAdapter::from_proxy(bool simulated
)
113 if(this->is_ready()){
114 std::vector
<double> positions
;
116 // read the position attribute
117 _proxy
->read() >> positions
;
118 _read_real
= positions
[0];
119 _write_real
= positions
[1];
121 Tango::AttributeInfo info
= _proxy
->get_config();
123 // Check if min and max value have been set
125 token
= info
.min_value
.c_str();
126 if (!strstr(token
, "Not specified"))
129 token
= info
.max_value
.c_str();
130 if (!strstr(token
, "Not specified"))
134 _state
= _proxy
->state();
138 _write
= _write_real
;
140 _read
= hkl_axis_get_value_unit(_axis_r
);
141 _write
= hkl_axis_get_value_unit(_axis_w
);
145 catch(Tango::DevFailed
&)
147 _state
= Tango::FAULT
;
151 void AxisAdapter::to_proxy(void)
153 #ifdef WRITE_TO_PROXY_ALLOWED
155 if(this->is_ready()){
156 Tango::DeviceAttribute
attr(_proxy_name
, _write_real
);
157 _state
= Tango::MOVING
;
161 catch(Tango::DevFailed
&)
163 _state
= Tango::FAULT
;
168 void AxisAdapter::stop(void)
170 // let the error propagate if stop failed.
172 _proxy
->get_device_proxy()->command_inout(_proxy_stop_command_name
);
175 void AxisAdapter::on(void)
179 _proxy
->get_device_proxy()->command_inout(_proxy_on_command_name
);
181 catch (Tango::DevFailed
&)
183 _state
= Tango::FAULT
;
184 // do nothing if the command is not present.