1 #include <AxisAdapter.h>
4 namespace DiffractometerDevice_ns
{
6 AxisAdapter::AxisAdapter(HklAxis
*read
, HklAxis
*write
)
13 _state
= Tango::UNKNOWN
;
16 AxisAdapter::~AxisAdapter(void)
20 std::string
const AxisAdapter::get_name(void) const
22 return ((HklParameter
*)(_axis_r
))->name
;
25 Tango::Group
*AxisAdapter::connect(std::string
const & device_name
)
28 std::string name
= this->get_name();
30 // Create a new Group for the axe.
31 group
= new Tango::Group(name
);
33 group
->add(device_name
);
35 // read positions from proxy;
36 Tango::GroupAttrReplyList reply
;
37 std::vector
<double> positions
;
38 reply
= group
->read_attribute(AXIS_ATTRIBUTE_POSITION_NAME
);
39 if (reply
.has_failed()) {
44 reply
[0] >> positions
;
45 _device_name
= device_name
;
46 _proxy
= group
->get_device(1);
47 hkl_axis_set_value_unit(_axis_r
, positions
[0]);
48 hkl_axis_set_value_unit(_axis_w
, positions
[1]);
50 _write
= positions
[1];
54 * here an hack due to the
55 * get_attribute_config signature
56 * we need a non const char or
59 std::string attr_name
= AXIS_ATTRIBUTE_POSITION_NAME
;
60 Tango::AttributeInfo info
= _proxy
->get_attribute_config(attr_name
);
62 // Check if min and max value have been set
64 token
= info
.min_value
.c_str();
65 if (!strstr(token
, "Not specified"))
68 token
= info
.max_value
.c_str();
69 if (!strstr(token
, "Not specified"))
76 bool const AxisAdapter::is_ready(void) const
84 void AxisAdapter::write(double value
, bool simulated
)
87 _read
= _write
= value
;
89 } else if (this->is_ready()) {
90 #ifdef WRITE_TO_PROXY_ALLOWED
91 // only write to the proxies
92 Tango::DeviceAttribute
attr(AXIS_ATTRIBUTE_POSITION_NAME
, value
);
93 _proxy
->command_inout(AXIS_COMMAND_STOP_NAME
);
94 _proxy
->write_attribute(attr
);
96 _state
= Tango::MOVING
;
100 void AxisAdapter::from_HklAxis(void)
102 _read
= hkl_axis_get_value_closest_unit(_axis_r
, _axis_r
);
103 _write
= hkl_axis_get_value_closest_unit(_axis_w
, _axis_r
);
104 hkl_axis_get_range_unit(_axis_r
, &_min
, &_max
);
107 void AxisAdapter::to_HklAxis(void)
109 hkl_axis_set_value_unit(_axis_r
, _read
);
110 hkl_axis_set_value_unit(_axis_w
, _write
);
111 hkl_axis_set_range_unit(_axis_r
, _min
, _max
);
112 hkl_axis_set_range_unit(_axis_w
, _min
, _max
);
115 void AxisAdapter::from_proxy(void)
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
= positions
[0];
125 _write
= 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 void AxisAdapter::to_proxy(void)
154 #ifdef WRITE_TO_PROXY_ALLOWED
155 if(this->is_ready()){
156 Tango::DeviceAttribute
attr(AXIS_ATTRBIUTE_POSITION_NAME
, _write
);
157 _state
= Tango::MOVING
;
158 _proxy
->write_attribute(attr
);