PiMercury.h 24.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
//=============================================================================
//
// file :        PiMercury.h
//
// description : Include for the PiMercury class.
//
// project :	Pi Mercury
//
// $Author: graziano $
//
// $Revision: 1.14 $
//
// $Log: PiMercury.h,v $
// Revision 1.14  2017-05-16 13:54:34  graziano
// tango 9
//
// Revision 1.12  2016-08-23 12:06:21  graziano
// changed ChannelXOut to Out0X and added In01 ... In04
//
// Revision 1.11  2015-08-24 09:38:45  graziano
// added Out01 - Out04 attributes
//
// Revision 1.10  2013-10-11 10:15:32  graziano
// Device_4Impl and support for new C863_10
//
// Revision 1.9  2013-07-09 08:08:33  graziano
// added command LoadConfig
//
// Revision 1.7  2012-01-12 08:45:48  graziano
// added support for multiple devices
//
// Revision 1.6  2009/08/21 13:40:51  graziano
// New libbufferrt
//
// Revision 1.5  2009/05/27 09:35:04  graziano
// check in rt_mode if the buffer is updating, otherwise set an error message in the status string
//
// Revision 1.4  2009/04/24 07:52:19  graziano
// bug fixing
//
// Revision 1.3  2009/04/23 09:07:02  graziano
// development of rt_mode using kernel module
//
// Revision 1.2  2009/04/14 12:40:26  graziano
// added rt_mode, scan mode, ...
//
// Revision 1.1  2008/11/19 10:28:46  graziano
// first version
//
//
// copyleft :    European Synchrotron Radiation Facility
//               BP 220, Grenoble 38043
//               FRANCE
//
//=============================================================================
//
//  		This file is generated by POGO
//	(Program Obviously used to Generate tango Object)
//
//         (c) - Software Engineering Group - ESRF
//=============================================================================
#ifndef _PIMERCURY_H
#define _PIMERCURY_H

#include <tango.h>
#include <sys/time.h>
#include <stdint.h>
#ifndef _SERVER_RT
#include "buffer.h"
#endif
//using namespace Tango;

/**
 * @author	$Author: graziano $
 * @version	$Revision: 1.14 $
 */

 //	Add your own constants definitions here.
 //-----------------------------------------------
 //defines from Serial.h
#define SL_RAW        0     /* raw read/write mode */
#define SL_NCHAR      1     /* character read/write mode */
#define SL_LINE       2     /* line read mode */
#define SL_RETRY      3     /* retry read mode */

#define ADDRESS_SELECTION_CODE			"\x1"		//ascii char 0x1 (ctrl^A)
#define VERSION_GET						"VE"		//get version
#define TELL_BOARD						"TB"		//tell board address, resp= B:
#define TELL_POSITION					"TP"		//tell position, resp= P:
#define TELL_TARGET_POSITION			"TT"		//tell target position, resp= T:
#define TELL_VELOCITY					"TV"		//tell velocity, resp= V:
#define TELL_PROGRAMMED_VELOCITY		"TY"		//tell programmed velocity, resp= Y:
#define TELL_PROGRAMMED_ACCELERATION	"TL"		//tell programmed acceleration, resp= L:
#define TELL_STATUS						"TS"		//tell status, resp= S:
#define TELL_CHANNEL					"TC"		//

#define SET_VELOCITY					"SV"		//
#define SET_ACCELERATION				"SA"		//
#define SET_LIMIT_ON					"LN"		//
#define SET_LIMIT_OFF					"LF"		//
#define SET_LIMIT_HIGH					"LH"		//
#define SET_LIMIT_LOW					"LL"		//
#define SET_CHANNEL_ON				"CN"		//
#define SET_CHANNEL_OFF				"CF"		//

#define CMD_STOP						"ST"		//
#define CMD_ABORT						"AB"		//
#define CMD_GO_HOME						"GH"		//
#define CMD_SET_HOME					"DH"		//define current position as 0
#define CMD_MOV_ABSOLUTE				"MA"		//
#define CMD_MOV_RELATIVE				"MR"		//
#define CMD_ON							"MN"		//
#define CMD_OFF							"MF"		//
#define CMD_BRAKE_ON					"BN"		//
#define CMD_BRAKE_OFF					"BF"		//
#define CMD_FIND_EDGE					"FE"		//
#define CMD_WAIT_STOP					"WS"		//
#define CMD_WAIT_ON						"WN"		//
#define CMD_WAIT_OFF					"WF"		//

#define IDN_11_GET							"*IDN?"		//get version
#define VERSION_11_GET						"VER?"		//get version
#define TELL_11_POSITION					"POS?"		//tell position, resp= P:
#define TELL_11_TARGET_POSITION			"MOV?"		//tell target position, resp= T:
#define TELL_11_VELOCITY					"VEL?"		//tell velocity, resp= V:
#define TELL_11_PROGRAMMED_VELOCITY		"VEL?"		//tell programmed velocity, resp= Y:
#define TELL_11_PROGRAMMED_ACCELERATION	"ACC?"		//tell programmed acceleration, resp= L:
#define TELL_11_STATUS						"SRG?"	//"\x4"		//tell status
#define TELL_11_MOTION_STATUS				"\x5"		//tell motion status
#define TELL_11_ON_TARGET					"ONT?"
#define TELL_11_LIMIT_HIGH					"TMX?"
#define TELL_11_LIMIT_LOW					"TMN?"
#define TELL_11_ERR							"ERR?"
#define TELL_11_REFERENCED					"FRF?"
#define TELL_11_AXIS_CONFIG					"SPA?"
#define TELL_11_CHANNEL					"DIO?"		//

#define SET_11_VELOCITY						"VEL"		//
#define SET_11_ACCELERATION				"ACC"		//
#define SET_11_DECELERATION				"DEC"		//
#define SET_11_LIMIT_ON						"LN"		//
#define SET_11_LIMIT_OFF						"LF"		//
#define SET_11_LIMIT_HIGH					"LH"		//
#define SET_11_LIMIT_LOW					"LL"		//
#define SET_11_CHANNEL_ON				"DIO"		//
#define SET_11_CHANNEL_OFF				"DIO"		//

#define CMD_11_STOP						"HLT"		//stop with deceleration
#define CMD_11_ABORT						"STP"		//stop
#define CMD_11_GO_HOME					"GOH"		//
#define CMD_11_SET_HOME					"POS"		//define current position as 0
#define CMD_11_MOV_ABSOLUTE				"MOV"		//
#define CMD_11_MOV_RELATIVE				"MVR"		//
#define CMD_11_SVO							"SVO"		//servo loop ON/OFF
#define CMD_11_BRAKE						"BRA"		//
#define CMD_11_FIND_EDGE					"FRF"		//find reference
#define CMD_11_FIND_EDGE_POS				"FPL"		//find reference
#define CMD_11_FIND_EDGE_NEG				"FNL"		//find reference
#define CMD_11_WAIT_STOP					"WS"		//
#define CMD_11_WAIT_ON						"WN"		//
#define CMD_11_WAIT_OFF					"WF"		//
#define CMD_11_REBOOT						"RBT"

/*
RON?	//find reference mode
FRF
FPL
FNL
*/

/* STATES:
bool[0]=Ready
bool[1]=On target
bool[2]=Reference drive active
bool[3]=Joystick ON
bool[4]=Macro running
bool[5]=Motor OFF
bool[6]=Brake ON
bool[7]=Drive current active
bool[8]=Limit negative
bool[9]=Reference signal
bool[10]=Limit positive
bool[11]=no function
bool[12]=Digital input 1
bool[13]=Digital input 2
bool[14]=Digital input 3
bool[15]=Digital input 4
bool[16]=No Error
bool[17]=RS-232 timeout
bool[18]=RS-232 overflow
bool[19]=Macro storage full
bool[20]=Macro out of range
bool[21]=Wrong macro command
bool[22]=Command error
*/
#define STAT_SIZE		40

//bits beginning from position 0
#define STAT_BIT_ON_TARGET	2
#define STAT_BIT_REFERENCED	3
#define STAT_BIT_OFF		7
#define STAT_BIT_WAIT		9
#define STAT_BIT_DIRECTION	18
#define STAT_BIT_BRAKE		27
#define STAT_POS_LIMIT		34
#define STAT_NEG_LIMIT		35


#define STAT_BIT_REFERENCING	38	//TODO: fictitious
#define STAT_BIT_ON_REFERENCE	39	//TODO: fictitious

#define C_863			0	//C_863.10
#define C_862			1
#define C_863_11		2	//C_863.11
#define MAX_ERRORS		0x0A

static char* errors[][3] = {
/*0*/	{"No error","No error","No error"},
/*1*/	{"RS-232 timeout","Command not found","Parameter syntax error"},
/*2*/	{"RS-232 overflow","First command character was not a letter","Unknown command"},
/*3*/	{"Macro storage full","","Command length out of limits or command buffer overrun"},
/*4*/	{"Macro out of range","","Error while scanning"},
/*5*/	{"Macro wrong command","Character following command was not a digit","Unallowable move attempted on unreferenced axis, or move attempted with servo off"},
/*6*/	{"Wrong command","Value too large","Parameter for SGA not valid"},
/*7*/	{"Hard stop","Value too small","Position out of limits"},
/*8*/	{"","Continuation character was not a comma","Velocity out of limits"},
/*9*/	{"Position following error","Command buffer overflow","Attempt to set pivot point while U,V and W not all 0"},
/*A*/	{"Move attempt while servo OFF","Macro storage overflow","Controller was stopped by command"},
/*11*/	{"Move attempt while joysticj ON","","Parameter for SST or for one of the embedded scan algorithms out of range"}
};

#ifdef _SERVER_RT
#define GET_RT_LAST_VALUES			0
#define GET_RT_VALUES_TIME			1
#define GET_RT_VALUES_BUNCH			2
#define GET_RT_LAST_TIMES			3
#endif

class mercurythread;

namespace PiMercury_ns
{

/**
 * Class Description:
 * Tango Device for Pi Mercury Motion Controller (models C-663, C-862, C-863)
 */

/*
 *	Device States Description:
*  Tango::ON :
*  Tango::OFF :
*  Tango::MOVING :
*  Tango::STANDBY :
*  Tango::FAULT :
 */


class PiMercury: public TANGO_BASE_CLASS
{
public :
	//	Add your own data members here
	//-----------------------------------------


	//	Here is the Start of the automatic code generation part
	//-------------------------------------------------------------	
/**
 *	@name attributes
 *	Attributs member data.
 */
//@{
		Tango::DevDouble	*attr_Position_read;
		Tango::DevDouble	attr_Position_write;
		Tango::DevDouble	*attr_Acceleration_read;
		Tango::DevDouble	attr_Acceleration_write;
		Tango::DevDouble	*attr_Speed_read;
		Tango::DevDouble	attr_Speed_write;
		Tango::DevDouble	*attr_TargetPosition_read;
		Tango::DevString	*attr_Error_read;
		Tango::DevBoolean	*attr_RtMode_read;
		Tango::DevBoolean	attr_RtMode_write;
		Tango::DevDouble	*attr_ScanSpeed_read;
		Tango::DevDouble	attr_ScanSpeed_write;
		Tango::DevBoolean	*attr_Stat_read;
		Tango::DevDouble	*attr_Limits_read;
		const Tango::DevDouble	*attr_Limits_write;
		Tango::DevString	*attr_AxisConfig_read;
		Tango::DevBoolean	*attr_Out01_read;
		Tango::DevBoolean	attr_Out01_write;
		Tango::DevBoolean	*attr_Out02_read;
		Tango::DevBoolean	attr_Out02_write;
		Tango::DevBoolean	*attr_Out03_read;
		Tango::DevBoolean	attr_Out03_write;
		Tango::DevBoolean	*attr_Out04_read;
		Tango::DevBoolean	attr_Out04_write;
		Tango::DevBoolean	*attr_In01_read;
		Tango::DevBoolean	*attr_In02_read;
		Tango::DevBoolean	*attr_In03_read;
		Tango::DevBoolean	*attr_In04_read;
//@}

/**
 *	@name Device properties
 *	Device properties member data.
 */
//@{
/**
 *	Number of the Axis on the motion controller
 */
	Tango::DevLong	axisNumber;
/**
 *	This is the Motion controller software forward limit
 *	Stops any movement passing that limit
 */
	Tango::DevLong	axisForwardLimit;
/**
 *	This is the Motion controller software backward limit
 *	Stops any movement passing that limit
 */
	Tango::DevLong	axisBackwardLimit;
/**
 *	the serial device used for communications with Pi Mercury Motion controller
 */
	string	serialdevice;
/**
 *	Serial port timeout in ms
 */
	Tango::DevLong	serial_timeout;
/**
 *	Sleep time in ms between serial write of a command and serial read of the response
 */
	Tango::DevDouble	wr_sleep;
/**
 *	Sleep time in ms between threads
 */
	Tango::DevDouble	th_sleep;
/**
 *	the ratio between hardware units and user units
 */
	Tango::DevDouble	positionRatio;
/**
 *	Max speed (counts/s)
 */
	Tango::DevLong	defaultMaxSpeed;
/**
 *	Default Min speed (counts/s)
 */
	Tango::DevLong	defaultMinSpeed;
/**
 *	Default acceleration (counts/s2)
 */
	Tango::DevLong	defaultAcceleration;
/**
 *	Max allowed speed (counts/s)
 */
	Tango::DevLong	maxAllowedSpeed;
/**
 *	Size of the circular buffer of the real time mode
 */
	Tango::DevLong	rtArraySize;
/**
 *	Digital input channel used for trigger, values = 1,2,3,4
 */
	Tango::DevLong	channelTrigger;
/**
 *	Sleep time in ms reading positions in real time mode
 */
	Tango::DevLong	rt_Sleep;
/**
 *	Offset between home position and default edge position.
 *	This value is used in the homing procedure (GoHome command)
 */
	Tango::DevDouble	homeEdgeOffset;
/**
 *	Device used to communicate with the RT module (/dev/mercury)
 */
	string	rTMercurydevice;
/**
 *	Device used to communicate with the rt buffer (/dev/buffer0)
 */
	string	rTBufferdevice;
/**
 *	Use GCS syntax for C-863.11
 */
	Tango::DevBoolean	useGCS;
/**
 *	Configuration file for the axis ()
 */
	string	axisConfFile;
/**
 *	Firmware version C-863.10 > 2.40
 */
	Tango::DevBoolean	c_863_10_new;
/**
396
397
398
 *	-1: use Reference Switch for homing
 *	0: no Reference Switch, find edge in positive dir
 *	1: no Reference Switch, find edge in negative dir
399
 */
400
	Tango::DevLong	referenceSwitch;
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
//@}

/**@name Constructors
 * Miscellaneous constructors */
//@{
/**
 * Constructs a newly allocated Command object.
 *
 *	@param cl	Class.
 *	@param s 	Device Name
 */
	PiMercury(Tango::DeviceClass *cl,string &s);
/**
 * Constructs a newly allocated Command object.
 *
 *	@param cl	Class.
 *	@param s 	Device Name
 */
	PiMercury(Tango::DeviceClass *cl,const char *s);
/**
 * Constructs a newly allocated Command object.
 *
 *	@param cl	Class.
 *	@param s 	Device name
 *	@param d	Device description.
 */
	PiMercury(Tango::DeviceClass *cl,const char *s,const char *d);
//@}

/**@name Destructor
 * Only one desctructor is defined for this class */
//@{
/**
 * The object desctructor.
 */	
	~PiMercury() {delete_device();};
/**
 *	will be called at device destruction or at init command.
 */
	void delete_device();
//@}

	
/**@name Miscellaneous methods */
//@{
/**
 *	Initialize the device
 */
	virtual void init_device();
/**
 *	Always executed method befor execution command method.
 */
	virtual void always_executed_hook();

//@}

/**
 * @name PiMercury methods prototypes
 */

//@{
/**
 *	Hardware acquisition for attributes.
 */
	virtual void read_attr_hardware(vector<long> &attr_list);
/**
 *	Extract real attribute values for Position acquisition result.
 */
	virtual void read_Position(Tango::Attribute &attr);
/**
 *	Write Position attribute values to hardware.
 */
	virtual void write_Position(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Acceleration acquisition result.
 */
	virtual void read_Acceleration(Tango::Attribute &attr);
/**
 *	Write Acceleration attribute values to hardware.
 */
	virtual void write_Acceleration(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Speed acquisition result.
 */
	virtual void read_Speed(Tango::Attribute &attr);
/**
 *	Write Speed attribute values to hardware.
 */
	virtual void write_Speed(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for TargetPosition acquisition result.
 */
	virtual void read_TargetPosition(Tango::Attribute &attr);
/**
 *	Extract real attribute values for Error acquisition result.
 */
	virtual void read_Error(Tango::Attribute &attr);
/**
 *	Extract real attribute values for RtMode acquisition result.
 */
	virtual void read_RtMode(Tango::Attribute &attr);
/**
 *	Write RtMode attribute values to hardware.
 */
	virtual void write_RtMode(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for ScanSpeed acquisition result.
 */
	virtual void read_ScanSpeed(Tango::Attribute &attr);
/**
 *	Write ScanSpeed attribute values to hardware.
 */
	virtual void write_ScanSpeed(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Stat acquisition result.
 */
	virtual void read_Stat(Tango::Attribute &attr);
/**
 *	Extract real attribute values for Limits acquisition result.
 */
	virtual void read_Limits(Tango::Attribute &attr);
/**
 *	Write Limits attribute values to hardware.
 */
	virtual void write_Limits(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for AxisConfig acquisition result.
 */
	virtual void read_AxisConfig(Tango::Attribute &attr);
/**
 *	Extract real attribute values for Out01 acquisition result.
 */
	virtual void read_Out01(Tango::Attribute &attr);
/**
 *	Write Out01 attribute values to hardware.
 */
	virtual void write_Out01(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Out02 acquisition result.
 */
	virtual void read_Out02(Tango::Attribute &attr);
/**
 *	Write Out02 attribute values to hardware.
 */
	virtual void write_Out02(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Out03 acquisition result.
 */
	virtual void read_Out03(Tango::Attribute &attr);
/**
 *	Write Out03 attribute values to hardware.
 */
	virtual void write_Out03(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for Out04 acquisition result.
 */
	virtual void read_Out04(Tango::Attribute &attr);
/**
 *	Write Out04 attribute values to hardware.
 */
	virtual void write_Out04(Tango::WAttribute &attr);
/**
 *	Extract real attribute values for In01 acquisition result.
 */
	virtual void read_In01(Tango::Attribute &attr);
/**
 *	Extract real attribute values for In02 acquisition result.
 */
	virtual void read_In02(Tango::Attribute &attr);
/**
 *	Extract real attribute values for In03 acquisition result.
 */
	virtual void read_In03(Tango::Attribute &attr);
/**
 *	Extract real attribute values for In04 acquisition result.
 */
	virtual void read_In04(Tango::Attribute &attr);
/**
 *	Read/Write allowed for Position attribute.
 */
	virtual bool is_Position_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Acceleration attribute.
 */
	virtual bool is_Acceleration_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Speed attribute.
 */
	virtual bool is_Speed_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for TargetPosition attribute.
 */
	virtual bool is_TargetPosition_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Error attribute.
 */
	virtual bool is_Error_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for RtMode attribute.
 */
	virtual bool is_RtMode_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for ScanSpeed attribute.
 */
	virtual bool is_ScanSpeed_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Stat attribute.
 */
	virtual bool is_Stat_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Limits attribute.
 */
	virtual bool is_Limits_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for AxisConfig attribute.
 */
	virtual bool is_AxisConfig_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Out01 attribute.
 */
	virtual bool is_Out01_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Out02 attribute.
 */
	virtual bool is_Out02_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Out03 attribute.
 */
	virtual bool is_Out03_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for Out04 attribute.
 */
	virtual bool is_Out04_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for In01 attribute.
 */
	virtual bool is_In01_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for In02 attribute.
 */
	virtual bool is_In02_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for In03 attribute.
 */
	virtual bool is_In03_allowed(Tango::AttReqType type);
/**
 *	Read/Write allowed for In04 attribute.
 */
	virtual bool is_In04_allowed(Tango::AttReqType type);
/**
 *	Execution allowed for Forward command.
 */
	virtual bool is_Forward_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for Backward command.
 */
	virtual bool is_Backward_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for Stop command.
 */
	virtual bool is_Stop_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for Abort command.
 */
	virtual bool is_Abort_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for Brake command.
 */
	virtual bool is_Brake_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for GoHome command.
 */
	virtual bool is_GoHome_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for GetVersion command.
 */
	virtual bool is_GetVersion_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for MotorON command.
 */
	virtual bool is_MotorON_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for MotorOFF command.
 */
	virtual bool is_MotorOFF_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for SetHome command.
 */
	virtual bool is_SetHome_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for LimitSwitchEnable command.
 */
	virtual bool is_LimitSwitchEnable_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for FindEdge command.
 */
	virtual bool is_FindEdge_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for LimitSwitchLevel command.
 */
	virtual bool is_LimitSwitchLevel_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for GetPosition command.
 */
	virtual bool is_GetPosition_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for CheckTrigger command.
 */
	virtual bool is_CheckTrigger_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for StartScan command.
 */
	virtual bool is_StartScan_allowed(const CORBA::Any &any);
/**
 *	Execution allowed for LoadConfig command.
 */
	virtual bool is_LoadConfig_allowed(const CORBA::Any &any);
/**
 * move forward for argin offset
 *	@param	argin	relative movement in user units
 *	@exception DevFailed
 */
	void	forward(Tango::DevDouble);
/**
 * move backward for argin offset
 *	@param	argin	relative movement in user units
 *	@exception DevFailed
 */
	void	backward(Tango::DevDouble);
/**
 * Stop the motor smootly
 *	@exception DevFailed
 */
	void	stop();
/**
 * Stop the motor immediately
 *	@exception DevFailed
 */
	void	abort();
/**
 * Activate or deactivate the active-low motor brake output line
 *	@param	argin	1=Brake ON, 2=Brake OFF
 *	@exception DevFailed
 */
	void	brake(Tango::DevBoolean);
/**
 * Move to home position
 *	@exception DevFailed
 */
	void	go_home();
/**
 * Return firmware version
 *	@return	
 *	@exception DevFailed
 */
	Tango::DevString	get_version();
/**
 * Sets the motor current back to the hold value.
 *	@exception DevFailed
 */
	void	motor_on();
/**
 * Shuts off the motor current.
 *	@exception DevFailed
 */
	void	motor_off();
/**
 * Set current position as home
 *	@exception DevFailed
 */
	void	set_home();
/**
 * Enable or disable software limit switch operation
 *	@param	argin	0=OFF 1=ON
 *	@exception DevFailed
 */
	void	limit_switch_enable(Tango::DevBoolean);
/**
 * Move the motor until a transition on the reference line is detected.
 *	Argin=starting search direction:
 *	0=start in positive dir
 *	1= start in negative dir
 *	2=start in positive dir if reference line is high
 *	4=start in positive dir if reference line is low
 *	@param	argin	direction: 0=start in positive dir, 1= start in negative dir, 2=start in positive dir if reference line is high, 3=start in positive dir if reference line is low
 *	@exception DevFailed
 */
	void	find_edge(Tango::DevLong);
/**
 * Sets the controller to expect both limit switch to be active-low or active-high
 *	@param	argin	0=LOW 1=HIGH
 *	@exception DevFailed
 */
	void	limit_switch_level(Tango::DevBoolean);
/**
 * Mode 0 (return last n values):
 *	long[0] = 0
 *	long[1] = number of values to be returned
 *	
 *	Mode 1 (return interval between timestamps):
 *	long[0] = 1
 *	long[1] = seconds of start timestamp
 *	long[2] = useconds of start timestamp
 *	long[3] = seconds of stop timestamp
 *	long[4] = useconds of stop timestamp
 *	
 *	Mode 2 (return interval between bunch numbers):
 *	long[0] = 2
 *	long[1] = start bunch
 *	long[2] = stop bunch
 *	@param	argin	mode and interval
 *	@return	array of positions
 *	@exception DevFailed
 */
	Tango::DevVarDoubleArray	*get_position(const Tango::DevVarLongArray *);
/**
 * Chek for trigger trying to wait with timeout for high level or for low level, if timeout return error
 *	@return	true=ok
 *	@exception DevFailed
 */
	Tango::DevBoolean	check_trigger(/*Tango::DevLong*/);
/**
 * Start scanning mode: move from start position to end position and repeat if if wanted
 *	@param	argin	start pos, stop pos, repeat
 *	@exception DevFailed
 */
	void	start_scan(const Tango::DevVarDoubleArray *);
/**
 * LoadConfig: load config file for C863.11 controllers	
 *	@exception DevFailed
 */
	void	load_config();

/**
 *	Read the device properties from database
 */
	 void get_device_property();
//@}

	//	Here is the end of the automatic code generation part
	//-------------------------------------------------------------	



protected :	
	//	Add your own data members here
	//-----------------------------------------
	int timeoutHiPrio;
	int timeoutLowPrio;
	string version;
	bool err_connection;
	bool exiting_rt_mode;
	mercurythread *readloop;
	
	void write_serial(const char *, long);
//	void write_serial(string);
	void read_serial(char */*, long*/);	
	

	Tango::DevString tmp_ptr;
	
	//double *rt_pos_array;
	typedef struct {
		double *pos;
		Tango::TimeVal *ts;
		unsigned int *bunch;
	} rt_pos_array_t;
	rt_pos_array_t rt_pos_array;
	int rt_pos_array_index;
	//string temp_rt_resp;
	char temp_rt_resp[128];
	bool checking_trigger;
	
	long vsize;
	
	int fd_buffer;
	int fd_mercury;
	
	void string_explode(string str, string separator, vector<string>* results);
	int serial_line;
	int load_conf_file(string filename);
	char conf_array[1024][256];
	
public:
	Tango::DeviceProxy *devserial;	
	int abortflag;  // flag used to abort reading loop
	bool stat[STAT_SIZE];
	//double position_tmp, position_moving;
	//bool position_valid;
	bool moving;
	int step_factor;
	int direction;		//1 = forward, -1 = backward
	Tango::DevState old_state;
	string old_status;
	omni_mutex *mutex;
	
	bool scan_mode;
	double speed_save;		//save speed before scan_mode
	double scan_start_pos;
	double scan_end_pos;
	bool scan_repeat;
	int scan_dir;		//1=toward end_pos, -1 = toward start_pos
	
	char   error_attr[1024];
	unsigned char c_86x_type;
	
	int WriteReadMercury(string cmd, string value, string &argout, bool has_resp);
	int RTReadMercury();
	int tv_compare(Tango::TimeVal ts1, Tango::TimeVal ts2);
	int check_timeout(timeval, int);	
	void abort_sleep(double time);
	bool rtmode;
	int homing;		//0=not homing, 1=finding edge, 2=moving offset, 
	bool init_homing;
	bool abort_rt_sleep;
	Tango::TimeVal ts_homing;		//beginning of homing
	struct _buffer *buf;
	Tango::TimeVal last_rt_read;	//beginning of homing
	bool referenced;
	
	map<string,string> cmd_map;
};

}	// namespace_ns

#endif	// _PIMERCURY_H