source: specdomain/src/test/move.mac @ 902

Last change on this file since 902 was 902, checked in by jemian, 13 years ago

examples and a test case to start off

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 17.5 KB
Line 
1
2# $Id: move.mac 902 2012-06-11 20:41:50Z jemian $
3# from ESRF (http://www.esrf.eu/blissdb/macros/getsource.py?macname=attributes.mac)
4
5#%TITLE% ATTRIBUTES.MAC
6#%NAME% ATTRIBUTES.MAC - TANGO attribute macro counters.
7#
8#%DESCRIPTION%
9#     The macro set offers the possibility to set-up a TANGO attribute
10#     as macro motor or as macro counter.
11#      Only read/write TANGO attributes can be used as macro motor.
12#     The macro motor controller defined is called "attr_mot" and
13#     The macro counter controller defined is called "attr_ct".
14#
15#%SETUP%
16#Motor and Counter Device Configuration (Not CAMAC)
17# ...
18#SCALERS        DEVICE   ADDR  <>MODE  NUM                                 <>TYPE
19#    YES                         POLL    1                         Software Timer
20#    YES        attr_c      -            2                          Macro Counter
21#
22# take care to set the NUM field to the good number of macro_counters you need.
23#
24#%EXAMPLE%
25#%DL%
26#
27#
28#%DT%  attr_mot_setup tilt id14/eh3-motor/mono_tile/Position %DD%
29#    Set-up the TANGO attribute macro motor with the mnemonic "tilt"
30#
31#%DT%  attr_ct_setup det id14/pindiode/eh3/Intensity %DD%
32#    Set-up the TANGO attribute macro counter with the mnemonic "det"
33#
34#%XDL%
35#
36#%END%
37
38
39# General parameters for attributes macros.
40global ATTR_PAR[]
41#ATTR_PAR["tango_aware"]
42ATTR_PAR["mot_error"] = "ATTR : WARNING, error on reading attribute macro motor."
43ATTR_PAR["ct_error"]  = "ATTR : WARNING, error on reading attribute macro counter."
44
45
46# Macro-COUNTERS parameters.
47global ATTR_CT
48list_test ATTR_CT
49# ATTR_CT[mne]["dev_name"]
50# ATTR_CT[mne]["attr_name"]
51
52
53# Macro-MOTORS parameters.
54global ATTR_MOT
55list_test ATTR_MOT
56# ATTR_MOT[mne]["dev_name"]
57# ATTR_MOT[mne]["attr_name"]
58
59global ESRF_ERR
60
61
62######################################################################
63##############################           #############################
64##############################  General  #############################
65##############################           #############################
66######################################################################
67
68#%UU%
69#%MDESC%
70#    Removes everythings about attributes.mac
71def attr_unsetup '{
72    unglobal ATTR_MOT
73    unglobal ATTR_CT
74    unglobal ATTR_PAR
75
76    # no cdef ?
77}'
78
79
80#%UU%
81#%MDESC%
82#    Displays information about counters managed by attributes macros.
83def attr_show '{
84    attr_ct_show
85    print ""
86    attr_mot_show
87}'
88
89######################################################################
90##########################                  ##########################
91##########################  Macro counters  ##########################
92##########################                  ##########################
93######################################################################
94
95#%UU% <mne> <dev> <attribute>   |  <mne> <dev/attribute>
96#%MDESC%
97# Configures counter <mne> to read <attribute> of tango device <dev>.
98#
99# example:    attr_ct_setup  bpm2x  id22eh2/bpmccd/1   X
100#          or attr_ct_setup  bpm2x  id22eh2/bpmccd/1/X
101#
102# example2: attr_ct_setup sstate sys/Database/2   State
103#           attr_ct_setup toto   id22/refillsim/1/Refill_time
104#
105def attr_ct_setup '{
106    global ATTR_PAR
107    global ATTR_CT
108
109    local _args_strings  _mne  _nbarg
110
111    _nbarg = $#
112
113    _mne = "$1"
114
115    list_test ATTR_CT
116    list_test ATTR_PAR
117
118    list_add(ATTR_CT, _mne)
119
120    # Checks if you spec version can use "tango_get".
121    # ??? what happens in case of an old SPEC ???
122    # test on VERSION ???
123    if (tango_io("sys/Database/2", "State") != -1){
124        ATTR_PAR["tango_aware"] = 1
125    }
126    else {
127        ATTR_PAR["tango_aware"] = 0
128    }
129
130    # Parses arguments to extract device and attribute names.
131    # 2 or 3 arguments ?
132    if (_nbarg == 2){
133        # print "2 parameters given."
134        _args_strings[0] = 0
135        split ("$2", _args_strings, "/")
136
137        list_setpar(ATTR_CT, _mne, "dev_name",                     \
138                 sprintf("%s/%s/%s", _args_strings[0],          \
139                         _args_strings[1], _args_strings[2]))
140
141        list_setpar(ATTR_CT, _mne, "attr_name", _args_strings[3])
142    }
143    else if (_nbarg == 3){
144        # print "3 parameters given."
145        list_setpar(ATTR_CT, _mne, "dev_name", "$2")
146        list_setpar(ATTR_CT, _mne, "attr_name", "$3")
147    }
148    else {
149        print "error : $0 requires 2 or 3 arguments."
150        print "usage -> $0  <mne> <device> <attribute>"
151        print "      or $0  <mne> <device/attribute>"
152        exit
153    }
154
155    # Informative message.
156    printf("Configuring counter ")
157    tty_cntl("md")
158    printf ("%s", "$1")
159    tty_cntl("me")
160    printf (" to reflect attribute ")
161    tty_cntl("md")
162    printf ("%s", ATTR_CT["$1"]["attr_name"])
163    tty_cntl("me")
164    printf (" of device ")
165    tty_cntl("md")
166    printf ("%s", ATTR_CT["$1"]["dev_name"])
167    tty_cntl("me")
168    print "."
169
170    if (cnt_num(_mne) < 0){
171        printf("Warning: counter \"%s\" is not defined\n", _mne)
172    }
173
174}'
175
176#%UU% <mne>
177#%MDESC%
178#    Removes reading of attribute linked to <mne> counter.
179#    ex: attr_ct_unsetup sstate
180def attr_ct_unsetup '{
181    local nb_param
182
183    nb_param =$#
184
185    if (nb_param < 1){
186        print "usage : $0 <counter_mnemonic>"
187    }
188    else{
189        list_remove(ATTR_CT, "$1")
190    }
191}'
192
193#%UU%
194#%MDESC%
195#    Removes reading of all attributes.
196def attr_ct_unsetup_all '{
197    unglobal ATTR_CT
198}'
199
200
201#%UU%
202#%MDESC%
203#    Displays informations about macro counters.
204def attr_ct_show '{
205    local _mne
206
207    print "-------=== macro counters ===------------"
208    print "mnemonic         device       attribute  "
209    print "-----------------------------------------"
210
211    for (i=0; i< list_n(ATTR_CT); i++){
212        _mne = ATTR_CT[i+1]
213        print ATTR_CT[i+1]"      " ATTR_CT[_mne]["dev_name"]"     "\
214            ATTR_CT[_mne]["attr_name"]
215    }
216    print "-----------------------------------------"
217
218}'
219
220
221#%IU%
222#%MDESC%
223#    Main function for macro counter.
224def attr_ct_cmd(cntnum, what, p1, p2) '{
225    global ATTR_CT
226    local _cntr _dev _attr
227
228    _cntr_mne = cnt_mne(cntnum)
229
230    # print "_cntr_mne=" _cntr_mne " \t what=" what
231
232    # "counts" read the attribute value as counter
233    # parameters: none
234    if (cntnum == ".."){
235        # for key applying to all counters
236        #print "--"
237    }
238    else{
239        if (what == "counts") {
240            # print "what == \"counts\""
241            local _ans _num  _dev _attr
242
243            # Tests if _cntr_mne is really an attr_ct macro counter.
244            if (list_check(ATTR_CT, _cntr_mne)){
245                _dev  = list_getpar(ATTR_CT, _cntr_mne, "dev_name")
246                _attr = list_getpar(ATTR_CT, _cntr_mne, "attr_name")
247
248                if(ATTR_PAR["tango_aware"]){
249
250                    _ans = tango_get(_dev, _attr)
251
252                    if (TANGO_ERR){
253                        tty_cntl("md")
254                        print "\n" ATTR_CT_ERROR " " _cntr_mne
255                        printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
256                        print TANGO_ERR_STACK
257                        tty_cntl("me")
258                        exit
259                    }
260                }
261                else{
262                    # print "esrf_io() VERSION"
263                    # esrf_io version.
264                    local _target
265                    ESRF_ERR = -1
266
267                    _target = _dev "/" _attr
268                    _ans    = esrf_io (_target, "DevRead")
269
270                    if (ESRF_ERR) {
271                        tty_cntl("md")
272                        print "\n" ATTR_CT_ERROR " " _cntr_mne " <- " _target "\n"
273                        print "\n" ESRF_ERR_MSG "\n\n"
274                        tty_cntl("me")
275                    }
276                }
277
278                return (_ans)
279            }
280            else{
281                #  print "Counter \"" _cntr_mne "\" not set up in ATTR_CT."
282                return (-1)
283            }
284        }
285    }
286}'
287
288
289# def ct '{
290#    _cols = 0
291#    p "1"
292#    waitmove
293#    p "2"
294#    count_em $*
295#    p "3"
296#    rdef cleanup \'
297#         undef cleanup
298#         onp; show_cnts; offp
299#         user_handlecounts
300#    \'
301#    p "4"
302#    waitcount
303#    p "5"
304#    undef cleanup
305#    p "6"
306#    onp; show_cnts; offp
307#    p "7"
308#    user_handlecounts
309#    p "8"
310# }'
311#
312# 374.CYRIL> ct
313# 1
314# 2
315# what == "counts"
316# what == "counts"
317# 3
318# 4
319# what == "counts"
320# what == "counts"
321# 5
322# 6
323# what == "counts"
324# what == "counts"
325#
326# Thu Jan 22 17:09:38 2009
327#
328#      Seconds = 1.003
329#      Monitor = 0 (0/s)
330#     Detector = 0 (0/s)
331#         toto = -1 (-0.997009/s)
332#       sstate = 0 (0/s)
333# 7
334# 8
335#
336# 375.CYRIL> what == "counts"
337# what == "counts"
338#
339#
340# 375.CYRIL>
341
342
343
344
345######################################################################
346###########################                ###########################
347###########################  Macro motors  ###########################
348###########################                ###########################
349######################################################################
350
351##%UU% <mne> <dev> <attribute>   |  <mne> <dev/attribute>
352#%MDESC%
353# Configures counter <mne> to read <attribute> of tango device <dev>.
354#
355# example:    attr_mot_setup  at1  id22eh2/machin/1   X
356#          or attr_mot_setup  at2  id22eh2/machin/1/X
357#
358# example 2  attr_mot_setup rft1  id22/refillsim/1  Refill_time
359#         or attr_mot_setup rft1  id22/refillsim/1/Refill_time
360#
361def attr_mot_setup '{
362    local _fields  _dev_name   _nbarg
363    local _args_strings  _mne
364
365    # Checks if you spec version can use "tango_put/tango_get".
366    # ??? what happens in case of an old SPEC ???
367    # test on VERSION ???
368    if (tango_io("sys/Database/2", "State") != -1){
369        ATTR_PAR["tango_aware"] = 1
370    }
371    else {
372        ATTR_PAR["tango_aware"] = 0
373    }
374
375    _mne = "$1"
376
377    list_test ATTR_MOT
378    list_test ATTR_PAR
379
380    list_add(ATTR_MOT, _mne)
381
382    _nbarg = $#
383
384
385    # Parses arguments to extract device and attribute names.
386    # 2 or 3 arguments ?
387    if (_nbarg == 2){
388        # print "2 parameters given."
389        _args_strings[0] = 0
390        split ("$2", _args_strings, "/")
391
392        list_setpar(ATTR_MOT, _mne, "dev_name",                     \
393                 sprintf("%s/%s/%s", _args_strings[0],          \
394                         _args_strings[1], _args_strings[2]))
395
396        list_setpar(ATTR_MOT, _mne, "attr_name", _args_strings[3])
397    }
398    else if (_nbarg == 3){
399        # print "3 parameters given."
400        list_setpar(ATTR_MOT, _mne, "dev_name", "$2")
401        list_setpar(ATTR_MOT, _mne, "attr_name", "$3")
402    }
403    else {
404        print "error : $0 requires 2 or 3 arguments."
405        print "usage -> $0  <mne> <device> <attribute>"
406        print "      or $0  <mne> <device/attribute>"
407        exit
408    }
409
410
411    # Informative message.
412    printf("Configuring macro motor ")
413    tty_cntl("md")
414    printf ("%s", "$1")
415    tty_cntl("me")
416    printf (" to reflect attribute ")
417    tty_cntl("md")
418    printf ("%s", ATTR_MOT["$1"]["attr_name"])
419    tty_cntl("me")
420    printf (" of device ")
421    tty_cntl("md")
422    printf ("%s", ATTR_MOT["$1"]["dev_name"])
423    tty_cntl("me")
424    print "."
425
426    if (motor_num(_mne) < 0){
427        printf("Warning: motor \"%s\" is not defined\n", _mne)
428    }
429}'
430
431
432
433#%UU% <mne>
434#%MDESC%
435#    Removes reading of attribute linked to <mne> motor.
436#    ex: attr_mot_unsetup at1
437def attr_mot_unsetup '{
438    local _nb_param
439
440    _nb_param =$#
441
442    if (_nb_param < 1){
443        print "usage : $0 <motor_mnemonic>"
444    }
445    else{
446        list_remove(ATTR_MOT, "$1")
447    }
448}'
449
450#%UU%
451#%MDESC%
452#    Removes reading of all attributes.
453def attr_mot_unsetup_all '{
454    unglobal ATTR_MOT
455}'
456
457#%UU%
458#%MDESC%
459#    Displays informations about attributes macro motors.
460def attr_mot_show '{
461    local _mne
462
463    print "--------==== macro motors ====-----------"
464    print "mnemonic         device       attribute  "
465    print "-----------------------------------------"
466
467    for (i=0; i< list_n(ATTR_MOT); i++){
468        _mne = ATTR_MOT[i+1]
469        print ATTR_MOT[i+1]"      " ATTR_MOT[_mne]["dev_name"]"     "   \
470            ATTR_MOT[_mne]["attr_name"]
471    }
472    print "-----------------------------------------"
473
474}'
475
476
477#%IU%
478#%MDESC%
479#
480def attr_mot_cmd(motnum, what, p1, p2) '{
481
482    local _mot_mne  _dev  _attr
483
484    _mot_mne = motor_mne(motnum)
485
486    # Tests if _mot_mne is really an attr_ macro motor.
487    if (list_check(ATTR_MOT, _mot_mne)){
488        _dev    = list_getpar(ATTR_MOT, _mot_mne, "dev_name")
489        _attr   = list_getpar(ATTR_MOT, _mot_mne, "attr_name")
490        _target = _dev "/" _attr
491    }
492    else{
493        #  print "Motor \"" _mot_mne "\" not set up in ATTR_MOT."
494        return (-1)
495    }
496
497
498
499    if(motnum == ".."){
500        # key applying to all motors
501        # print "--"
502    }
503
504    #-------------------------------------
505    # "position" must return dial position (in integer steps)
506    # parameters: none
507    if (what == "position") {
508        local _pos
509
510        if(ATTR_PAR["tango_aware"]){
511            _pos = tango_get(_dev, _attr)
512
513            if (TANGO_ERR){
514                tty_cntl("md")
515                print "\n" ATTR_MOT_ERROR " " _mot_mne  " " _dev  "/"  _attr
516                printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
517                print TANGO_ERR_STACK
518                tty_cntl("me")
519                exit
520            }
521        }
522        else{
523            _pos = esrf_io (_target, "DevRead")
524
525            if (ESRF_ERR) {
526                tty_cntl("md")
527                print "\n" ATTR_MOT_ERROR " " _mot_mne " <- " _target "\n"
528                print "\n" ESRF_ERR_MSG "\n\n"
529                tty_cntl("me")
530            }
531        }
532        return (_pos)
533    }
534
535    #-------------------------------------
536    # "get_status" called during the motion, must return a bit mask
537    # bits meaning: 0 if motor idle
538    #               2 if motor moving
539    #               4 if negative limit on
540    #               8 if positive limit on
541    # parameters:   none
542    if (what == "get_status"){
543        local _state
544        local _ret
545
546        if(ATTR_PAR["tango_aware"]){
547            _state = tango_io(_dev, "State")
548
549            if (TANGO_ERR){
550                tty_cntl("md")
551                print "\n" ATTR_MOT_ERROR " " _mot_mne  " " _dev  "/"  _attr
552                printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
553                print TANGO_ERR_STACK
554                tty_cntl("me")
555                exit
556            }
557        }
558        else{
559            ESRF_ERR = -1
560            _state = esrf_io (_target, "DevState")
561
562            if (ESRF_ERR){
563                tty_cntl("md")
564                print "\n" MOT_ERROR " " _mot_mne "\n"
565                print "\n" ESRF_ERR_MSG"\n\n"
566                tty_cntl("me")
567            }
568        }
569
570        #
571        # DEVMOVING
572        #
573        if (_state == 9) {
574            _ret |= 2
575            return _ret
576        }
577        #
578        # DEVFAULT
579        #
580        if (_state == 23) {
581            local _status
582
583            print ""
584
585            if(ATTR_PAR["tango_aware"]){
586                _status = tango_io(_dev, "DevStatus")
587            }
588            else{
589                ESRF_ERR = -1
590                print esrf_io (_target, "DevStatus")
591            }
592
593            print "Status= " _status
594
595            print ""
596            return 0
597        }
598
599        return 0
600    }
601
602    #-------------------------------------
603    # "start_one"
604    # parameters: p2 is relative motion, p1 is absolute requested position
605    if (what == "start_one") {
606        if(ATTR_PAR["tango_aware"]){
607
608            tango_put(_dev, _attr, p1)
609
610            if (TANGO_ERR){
611                tty_cntl("md")
612                print "\n" ATTR_MOT_ERROR " " _mot_mne  " " _dev  "/"  _attr
613                printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
614                print TANGO_ERR_STACK
615                tty_cntl("me")
616                exit
617            }
618        }
619        else{
620            ESRF_ERR = -1
621
622            esrf_io (_target, "DevWrite", p1)
623            if (ESRF_ERR) {
624                tty_cntl("md")
625                print "\n" MOT_ERROR " " _mot_mne "\n"
626                print "\n" ESRF_ERR_MSG"\n\n"
627                tty_cntl("me")
628            }
629        }
630    }
631
632    #-------------------------------------
633    # "set_position" called on "set_dial motor newpos"
634    # parameters: p1 is the new position (in steps)
635    #
636    if (what == "set_position") {
637        if(ATTR_PAR["tango_aware"]){
638            tango_put(_dev, _attr, p1)
639
640            if (TANGO_ERR){
641                tty_cntl("md")
642                print "\n" ATTR_MOT_ERROR " " _mot_mne  " " _dev  "/"  _attr
643                printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
644                print TANGO_ERR_STACK
645                tty_cntl("me")
646                exit
647            }
648        }
649        else{
650            ESRF_ERR = -1
651
652            esrf_io (_target, "DevWrite", p1)
653
654            if (ESRF_ERR) {
655                tty_cntl("md")
656                print "\n" MOT_ERROR " " _mot_mne "\n"
657                print "\n" ESRF_ERR_MSG"\n\n"
658                tty_cntl("me")
659            }
660        }
661    }
662
663    #-------------------------------------
664    # "abort_one" called on <Ctrl-C>
665    #
666    if (what == "abort_one") {
667        if(ATTR_PAR["tango_aware"]){
668            tango_put(_dev, "DevAbort")
669
670            if (TANGO_ERR){
671                tty_cntl("md")
672                print "\n" ATTR_MOT_ERROR " " _mot_mne  " " _dev  "/"  _attr
673                printf ("TANGO_ERR_MSG = \"%s\" \n\n", TANGO_ERR)
674                print TANGO_ERR_STACK
675                tty_cntl("me")
676                exit
677            }
678        }
679        else{
680            ESRF_ERR = -1
681            esrf_io (_target, "DevAbort")
682            if (ESRF_ERR) {
683                tty_cntl("md")
684                print "\n" MOT_ERROR " " _mot_mne "\n"
685                print "\n" ESRF_ERR_MSG"\n\n"
686                tty_cntl("me")
687            }
688        }
689    }
690}'
691
692
693#%MACROS%
694#%IMACROS%
695#%AUTHOR%
696
Note: See TracBrowser for help on using the repository browser.