1 //===================================================================
3 // The following table gives the correspondence
4 // between commands and method name.
6 // Command name | Method name
7 // ----------------------------------------
9 // Status | dev_status()
12 // MotorOFF | motor_off()
13 // MotorON | motor_on()
14 // MotorInit | motor_init()
15 // ComputeNewOffset | compute_new_offset()
16 // Backward | backward()
17 // Forward | forward()
18 // DefinePosition | define_position()
19 // InitializeReferencePosition | initialize_reference_position()
20 // GetModeParameters | get_mode_parameters()
21 // SetModeParameters | set_mode_parameters()
23 //===================================================================
26 #include <PseudoAxis.h>
27 #include <PseudoAxisClass.h>
28 #include <PogoHelper.h>
30 #include <TangoExceptionsHelper.h>
33 #include <TangoExceptionsHelper.h>
34 #include <PseudoAxis.h>
35 #include <PseudoAxisClass.h>
36 #include <PogoHelper.h>
39 #include <DeviceProxyHelper.h>
41 #include <hkl/hkl-pseudoaxis.h>
44 #include "PseudoAxis.h"
45 #include "PseudoAxisClass.h"
46 #include "TangoHKLAdapterFactory.h"
48 namespace PseudoAxis_ns
51 //+----------------------------------------------------------------------------
53 // method : PseudoAxis::PseudoAxis(string &s)
55 // description : constructor for simulated PseudoAxis
57 // in : - cl : Pointer to the DeviceClass object
60 //-----------------------------------------------------------------------------
61 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,string
&s
)
62 :Tango::Device_4Impl(cl
,s
.c_str())
67 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,const char *s
)
68 :Tango::Device_4Impl(cl
,s
)
73 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,const char *s
,const char *d
)
74 :Tango::Device_4Impl(cl
,s
,d
)
78 //+----------------------------------------------------------------------------
80 // method : PseudoAxis::delete_device()
82 // description : will be called at device destruction or at init command.
84 //-----------------------------------------------------------------------------
85 void PseudoAxis::delete_device()
87 DEBUG_STREAM
<< "PseudoAxis::delete_device() entering... " << std::endl
;
89 // no need to release the memory this is done by ~TangoHKLAdapter()
94 //+----------------------------------------------------------------------------
96 // method : PseudoAxis::init_device()
98 // description : will be called at device initialization.
100 //-----------------------------------------------------------------------------
101 void PseudoAxis::init_device()
103 DEBUG_STREAM
<< "PseudoAxis::init_device() entering... " << std::endl
;
105 // Initialise variables to default values
106 //--------------------------------------------
107 this->get_device_property();
112 // initialize the config
114 _config
.initialized
= false;
115 _config
.state
= Tango::FAULT
;
116 _config
.status
= "Not yet initialized";
119 //+----------------------------------------------------------------------------
121 // method : PseudoAxis::get_device_property()
123 // description : Read the device properties from database.
125 //-----------------------------------------------------------------------------
126 void PseudoAxis::get_device_property()
128 DEBUG_STREAM
<< "PseudoAxis::get_device_property() entering... " << std::endl
;
130 // Initialize your default values here (if not done with POGO).
131 //------------------------------------------------------------------
133 // Read device properties from database.(Automatic code generation)
134 //------------------------------------------------------------------
135 Tango::DbData dev_prop
;
136 dev_prop
.push_back(Tango::DbDatum("DiffractometerProxy"));
137 dev_prop
.push_back(Tango::DbDatum("PseudoAxisName"));
139 // Call database and extract values
140 //--------------------------------------------
141 if (Tango::Util::instance()->_UseDb
==true)
142 get_db_device()->get_property(dev_prop
);
143 Tango::DbDatum def_prop
, cl_prop
;
144 PseudoAxisClass
*ds_class
=
145 (static_cast<PseudoAxisClass
*>(get_device_class()));
148 // Try to initialize DiffractometerProxy from class property
149 cl_prop
= ds_class
->get_class_property(dev_prop
[++i
].name
);
150 if (cl_prop
.is_empty()==false) cl_prop
>> diffractometerProxy
;
152 // Try to initialize DiffractometerProxy from default device value
153 def_prop
= ds_class
->get_default_device_property(dev_prop
[i
].name
);
154 if (def_prop
.is_empty()==false) def_prop
>> diffractometerProxy
;
156 // And try to extract DiffractometerProxy value from database
157 if (dev_prop
[i
].is_empty()==false) dev_prop
[i
] >> diffractometerProxy
;
159 // Try to initialize PseudoAxisName from class property
160 cl_prop
= ds_class
->get_class_property(dev_prop
[++i
].name
);
161 if (cl_prop
.is_empty()==false) cl_prop
>> pseudoAxisName
;
163 // Try to initialize PseudoAxisName from default device value
164 def_prop
= ds_class
->get_default_device_property(dev_prop
[i
].name
);
165 if (def_prop
.is_empty()==false) def_prop
>> pseudoAxisName
;
167 // And try to extract PseudoAxisName value from database
168 if (dev_prop
[i
].is_empty()==false) dev_prop
[i
] >> pseudoAxisName
;
172 // End of Automatic code generation
173 //------------------------------------------------------------------
178 //+------------------------------------------------------------------
180 * method: PseudoAxe::dev_state
182 * description: method to execute "State"
183 * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
190 //+------------------------------------------------------------------
191 Tango::DevState
PseudoAxis::dev_state()
193 DEBUG_STREAM
<< "PseudoAxis::dev_state(): entering... !" << endl
;
195 if (!_hklAdapter
|| !_buffer
)
196 this->set_state(Tango::FAULT
);
198 this->set_state(_config
.state
);
199 this->set_status(_config
.status
);
201 return this->device_state
;
204 //+------------------------------------------------------------------
206 * method: PseudoAxe::dev_status
208 * description: method to execute "Status"
209 * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
216 //+------------------------------------------------------------------
217 Tango::ConstDevString
PseudoAxis::dev_status()
219 DEBUG_STREAM
<< "PseudoAxis::dev_status(): entering... !" << endl
;
222 this->device_state
= Tango::FAULT
;
223 if (diffractometerProxy
== "")
224 this->device_status
= "Please set a correct \"diffractometerProxy\" propertie";
226 this->device_status
= "The Diffractometer device " + diffractometerProxy
+ " is not ready or do not existe!\n";
227 this->device_status
+= "Please start the Diffractometer or check the \"diffractometerProxy\" Propertie";
231 this->device_state
= Tango::FAULT
;
232 if (pseudoAxisName
== "")
233 this->device_status
= "Please set a correct \"pseudoAxisName\" : ";
235 this->device_status
= "Cannot find the pseudoAxe \"" + pseudoAxisName
+ "\" in the " + diffractometerProxy
+ " Diffractometer device : ";
237 this->device_status
+= "Set \"pseudoAxisName\" propertie with one of these possible values : ";
238 std::vector
<std::string
> const names
= _hklAdapter
->pseudo_axis_get_names();
239 std::vector
<std::string
>::const_iterator iter
= names
.begin();
240 std::vector
<std::string
>::const_iterator end
= names
.end();
241 this->device_status
+= " " + *iter
;
244 this->device_status
+= ", " + *iter
;
248 this->set_state(_config
.state
);
249 this->set_status(_config
.status
);
252 return this->device_status
.c_str();
255 //+----------------------------------------------------------------------------
257 // method : PseudoAxis::always_executed_hook()
259 // description : method always executed before any command is executed
261 //-----------------------------------------------------------------------------
262 void PseudoAxis::always_executed_hook()
264 DEBUG_STREAM
<< "PseudoAxis::always_executed_hook() entering... " << std::endl
;
265 // here we are looking for the intance of the related Diffractometer to get the right hkladapter instance.
267 _hklAdapter
= Diffractometer_ns::TangoHKLAdapterFactory::instance()->get_diffractometer_adapter(diffractometerProxy
);
269 if(_hklAdapter
&& !_buffer
)
270 _buffer
= _hklAdapter
->pseudo_axis_buffer_new(pseudoAxisName
.c_str());
273 //+----------------------------------------------------------------------------
275 // method : PseudoAxis::read_attr_hardware
277 // description : Hardware acquisition for attributes.
279 //-----------------------------------------------------------------------------
280 void PseudoAxis::read_attr_hardware(vector
<long> &attr_list
)
282 DEBUG_STREAM
<< "PseudoAxis::read_attr_hardware(vector<long> &attr_list) entering... "<< endl
;
283 // Add your own code here
285 _config
= _buffer
->get_config();
287 //+----------------------------------------------------------------------------
289 // method : PseudoAxis::read_initialized
291 // description : Extract real attribute values for initialized acquisition result.
293 //-----------------------------------------------------------------------------
294 void PseudoAxis::read_initialized(Tango::Attribute
&attr
)
296 DEBUG_STREAM
<< "PseudoAxis::read_initialized(Tango::Attribute &attr) entering... "<< endl
;
297 // Add your own code here
300 attr
.set_value(&_config
.initialized
);
303 //+----------------------------------------------------------------------------
305 // method : PseudoAxis::write_initialized
307 // description : Write initialized attribute values to hardware.
309 //-----------------------------------------------------------------------------
310 void PseudoAxis::write_initialized(Tango::WAttribute
&attr
)
312 DEBUG_STREAM
<< "PseudoAxis::write_initialized(Tango::WAttribute &attr) entering... "<< endl
;
313 attr
.get_write_value(attr_initialized_write
);
315 _buffer
->set_initialized(attr_initialized_write
);
317 // need to after the internals before initializing the pseudo
319 _hklAdapter
->update();
322 //+----------------------------------------------------------------------------
324 // method : PseudoAxis::read_mode
326 // description : Extract real attribute values for mode acquisition result.
328 //-----------------------------------------------------------------------------
329 void PseudoAxis::read_mode(Tango::Attribute
&attr
)
331 DEBUG_STREAM
<< "PseudoAxis::read_mode(Tango::Attribute &attr) entering... "<< endl
;
334 attr
.set_value(&_config
.mode
);
337 //+----------------------------------------------------------------------------
339 // method : PseudoAxis::write_mode
341 // description : Write mode attribute values to hardware.
343 //-----------------------------------------------------------------------------
344 void PseudoAxis::write_mode(Tango::WAttribute
&attr
)
346 DEBUG_STREAM
<< "PseudoAxis::write_mode(Tango::WAttribute &attr) entering... "<< endl
;
347 attr
.get_write_value(attr_mode_write
);
349 _buffer
->set_mode(attr_mode_write
);
352 //+----------------------------------------------------------------------------
354 // method : PseudoAxis::read_modeNames
356 // description : Extract real attribute values for modeNames acquisition result.
358 //-----------------------------------------------------------------------------
359 void PseudoAxis::read_modeNames(Tango::Attribute
&attr
)
361 DEBUG_STREAM
<< "PseudoAxis::read_modeNames(Tango::Attribute &attr) entering... "<< endl
;
363 Matrix
<char *> const & img
= _config
.mode_names
;
364 attr
.set_value(img
.data
, img
.xdim
);
368 //+----------------------------------------------------------------------------
370 // method : PseudoAxis::write_IsInitialised
372 // description : Write IsInitialised attribute values to hardware.
374 //-----------------------------------------------------------------------------
375 void PseudoAxis::write_IsInitialised(Tango::WAttribute
&attr
)
377 DEBUG_STREAM
<< "PseudoAxis::write_IsInitialised(Tango::WAttribute &attr) entering... "<< endl
;
378 // Add your own code here
379 attr
.get_write_value(attr_IsInitialised_write
);
381 _buffer
->set_initialized(attr_IsInitialised_write
);
383 // need to after the internals before initializing the pseudo
385 _hklAdapter
->update();
389 //+----------------------------------------------------------------------------
391 // method : PseudoAxis::read_position
393 // description : Extract real attribute values for position acquisition result.
395 //-----------------------------------------------------------------------------
396 void PseudoAxis::read_position(Tango::Attribute
&attr
)
398 DEBUG_STREAM
<< "PseudoAxis::read_position(Tango::Attribute &attr) entering... "<< endl
;
399 // Add your own code here
402 Tango::WAttribute
& attrw
= dev_attr
->get_w_attr_by_name(attr
.get_name().c_str());
403 attr
.set_value(&_config
.position_r
);
404 attrw
.set_write_value(_config
.position_w
);
408 //+----------------------------------------------------------------------------
410 // method : PseudoAxis::write_position
412 // description : Write position attribute values to hardware.
414 //-----------------------------------------------------------------------------
415 void PseudoAxis::write_position(Tango::WAttribute
&attr
)
417 DEBUG_STREAM
<< "PseudoAxis::write_position(Tango::WAttribute &attr) entering... "<< endl
;
418 // Add your own code here
420 attr
.get_write_value(attr_position_write
);
422 _buffer
->set_position(attr_position_write
);
425 //+----------------------------------------------------------------------------
427 // method : PseudoAxis::read_offset
429 // description : Extract real attribute values for offset acquisition result.
431 //-----------------------------------------------------------------------------
432 void PseudoAxis::read_offset(Tango::Attribute
&attr
)
434 DEBUG_STREAM
<< "PseudoAxis::read_offset(Tango::Attribute &attr) entering... "<< endl
;
435 // Add your own code here
437 attr
.set_value(&_config
.offset
);
440 //+----------------------------------------------------------------------------
442 // method : PseudoAxis::write_offset
444 // description : Write offset attribute values to hardware.
446 //-----------------------------------------------------------------------------
447 void PseudoAxis::write_offset(Tango::WAttribute
&attr
)
449 DEBUG_STREAM
<< "PseudoAxis::write_offset(Tango::WAttribute &attr) entering... "<< endl
;
450 // Add your own code here
451 attr
.get_write_value(attr_offset_write
);
453 _buffer
->set_offset(attr_offset_write
);
456 //+----------------------------------------------------------------------------
458 // method : PseudoAxis::read_relativeMove
460 // description : Extract real attribute values for relativeMove acquisition result.
462 //-----------------------------------------------------------------------------
463 void PseudoAxis::read_relativeMove(Tango::Attribute
&attr
)
465 DEBUG_STREAM
<< "PseudoAxis::read_relativeMove(Tango::Attribute &attr) entering... "<< endl
;
466 // Add your own code here
467 attr
.set_value(&attr_relativeMove_write
);
470 //+----------------------------------------------------------------------------
472 // method : PseudoAxis::write_relativeMove
474 // description : Write relativeMove attribute values to hardware.
476 //-----------------------------------------------------------------------------
477 void PseudoAxis::write_relativeMove(Tango::WAttribute
&attr
)
479 DEBUG_STREAM
<< "PseudoAxis::write_relativeMove(Tango::WAttribute &attr) entering... "<< endl
;
480 // Add your own code here
481 attr
.get_write_value(attr_relativeMove_write
);
482 double new_position
= _config
.position_r
+ attr_relativeMove_write
;
484 // Write to the "position" attribute to move the axe.
485 Tango::DeviceProxyHelper
moi(this->device_name
, this);
486 moi
.write_attribute("position", new_position
);
490 //+----------------------------------------------------------------------------
492 // method : PseudoAxis::read_IsInitialised
494 // description : Extract real attribute values for IsInitialised acquisition result.
496 //-----------------------------------------------------------------------------
497 void PseudoAxis::read_IsInitialised(Tango::Attribute
&attr
)
499 DEBUG_STREAM
<< "PseudoAxis::read_IsInitialised(Tango::Attribute &attr) entering... "<< endl
;
500 // Add your own code here
503 attr
.set_value(&_config
.initialized
);
506 //+------------------------------------------------------------------
508 * method: PseudoAxis::motor_off
510 * description: method to execute "MotorOFF"
515 //+------------------------------------------------------------------
516 void PseudoAxis::motor_off()
518 DEBUG_STREAM
<< "PseudoAxis::motor_off(): entering... !" << endl
;
520 // Add your own code to control device here
523 //+------------------------------------------------------------------
525 * method: PseudoAxis::motor_on
527 * description: method to execute "MotorON"
532 //+------------------------------------------------------------------
533 void PseudoAxis::motor_on()
535 DEBUG_STREAM
<< "PseudoAxis::motor_on(): entering... !" << endl
;
537 // Add your own code to control device here
542 //+------------------------------------------------------------------
544 * method: PseudoAxis::compute_new_offset
546 * description: method to execute "ComputeNewOffset"
547 * The so smart program computes the offset to goal the user position.
549 * @param argin The new user position
552 //+------------------------------------------------------------------
553 void PseudoAxis::compute_new_offset(Tango::DevDouble argin
)
555 DEBUG_STREAM
<< "PseudoAxis::compute_new_offset(): entering... !" << endl
;
557 // Add your own code to control device here
559 Tango::DevDouble offset
= _buffer
->compute_new_offset(argin
);
560 Tango::DeviceProxyHelper
moi(this->device_name
, this);
561 moi
.write_attribute("offset", offset
);
565 //+------------------------------------------------------------------
567 * method: PseudoAxis::stop
569 * description: method to execute "Stop"
570 * Stop the pseudoAxes and all related axes.
574 //+------------------------------------------------------------------
575 void PseudoAxis::stop()
577 DEBUG_STREAM
<< "PseudoAxis::stop(): entering... !" << endl
;
579 // Add your own code to control device here
585 //+------------------------------------------------------------------
587 * method: PseudoAxis::motor_init
589 * description: method to execute "MotorInit"
594 //+------------------------------------------------------------------
595 void PseudoAxis::motor_init()
597 DEBUG_STREAM
<< "PseudoAxis::motor_init(): entering... !" << endl
;
600 // Add your own code to control device here
602 _buffer
->set_initialized(true);
604 _hklAdapter
->update();
607 //+------------------------------------------------------------------
609 * method: PseudoAxis::backward
611 * description: method to execute "Backward"
612 * dummy command for V2 interface
616 //+------------------------------------------------------------------
617 void PseudoAxis::backward()
619 DEBUG_STREAM
<< "PseudoAxis::backward(): entering... !" << endl
;
621 // Add your own code to control device here
625 //+------------------------------------------------------------------
627 * method: PseudoAxis::forward
629 * description: method to execute "Forward"
630 * dummy command for V2 interface
634 //+------------------------------------------------------------------
635 void PseudoAxis::forward()
637 DEBUG_STREAM
<< "PseudoAxis::forward(): entering... !" << endl
;
639 // Add your own code to control device here
643 //+------------------------------------------------------------------
645 * method: PseudoAxis::define_position
647 * description: method to execute "DefinePosition"
648 * dummy command for V2 interface
653 //+------------------------------------------------------------------
654 void PseudoAxis::define_position(Tango::DevDouble argin
)
656 DEBUG_STREAM
<< "PseudoAxis::define_position(): entering... !" << endl
;
658 // Add your own code to control device here
662 //+------------------------------------------------------------------
664 * method: PseudoAxis::initialize_reference_position
666 * description: method to execute "InitializeReferencePosition"
667 * dummy command for V2 interface
671 //+------------------------------------------------------------------
672 void PseudoAxis::initialize_reference_position()
674 DEBUG_STREAM
<< "PseudoAxis::initialize_reference_position(): entering... !" << endl
;
676 // Add your own code to control device here
681 //+------------------------------------------------------------------
683 * method: PseudoAxis::get_mode_parameters
685 * description: method to execute "GetModeParameters"
686 * this command return for the current mode, its parameters.
688 * @return parameters names and values
691 //+------------------------------------------------------------------
692 Tango::DevVarDoubleStringArray
*PseudoAxis::get_mode_parameters()
694 // POGO has generated a method core with argout allocation.
695 // If you would like to use a static reference without copying,
696 // See "TANGO Device Server Programmer's Manual"
697 // (chapter : Writing a TANGO DS / Exchanging data)
698 //------------------------------------------------------------
699 Tango::DevVarDoubleStringArray
*argout
= new Tango::DevVarDoubleStringArray();
700 argout
->dvalue
.length(1);
701 argout
->dvalue
[0] = 0.0;
702 argout
->svalue
.length(1);
703 argout
->svalue
[0] = CORBA::string_dup("dummy");
704 DEBUG_STREAM
<< "PseudoAxis::get_mode_parameters(): entering... !" << endl
;
706 // Add your own code to control device here
708 _buffer
->get_mode_parameters(argout
);
713 //+------------------------------------------------------------------
715 * method: PseudoAxis::set_mode_parameters
717 * description: method to execute "SetModeParameters"
719 * @param argin The parameters to set
722 //+------------------------------------------------------------------
723 void PseudoAxis::set_mode_parameters(const Tango::DevVarDoubleStringArray
*argin
)
725 DEBUG_STREAM
<< "PseudoAxis::set_mode_parameters(): entering... !" << endl
;
727 // Add your own code to control device here
729 _buffer
->set_mode_parameters(argin
);
736 //+------------------------------------------------------------------
738 * method: PseudoAxis::on
740 * description: method to execute "On"
741 * Activate the pseudoAxis and all related motors.
745 //+------------------------------------------------------------------
746 void PseudoAxis::on()
748 DEBUG_STREAM
<< "PseudoAxis::on(): entering... !" << endl
;
750 // Add your own code to control device here