Changeset 902


Ignore:
Timestamp:
Jun 11, 2012 3:41:50 PM (10 years ago)
Author:
jemian
Message:

examples and a test case to start off

Location:
specdomain/src/test
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • specdomain/src/test/attributes.mac

    r901 r902  
    11
    22# $Id$
    3 # from Christian Schlepuetz (formatted for RoboDoc)
    4 
    5 #==============================================================================
    6 #%+H* common/shutter
    7 #     ==============
    8 #
    9 # NAME
    10 #   shutter.mac
    11 #
    12 # SUMMARY
    13 #   Commands to control a fast photon shutter.
    14 #
    15 # DESCRIPTION
    16 #   The macro causes the fast photon shutter to be opened immediately prior to
    17 #   any count command, and closed again upon its completion. A configurable
    18 #   delay time assures that the shutter is fully open before issuing the
    19 #   count command.
    20 #   The photon shutter is controlled via an EPICS binary output channel, and
    21 #   the shutter status is optionally monitored via a binary input channel (in
    22 #   which case the delay time is not used, but the monitor signal is used to
    23 #   check for completion of the opening process).
    24 #
    25 # AUTHOR
    26 #   Christian M. Schlepuetz (CS, cschlep)
    27 #
    28 # CREATION DATE
    29 #   2004/11/06
    30 #
    31 # COPYRIGHT
    32 #   Copyright 2006-2011 by the above authors (see AUTHOR/AUTHORS)
    33 #
    34 #   This program is free software: you can redistribute it and/or modify
    35 #   it under the terms of the GNU General Public License as published by
    36 #   the Free Software Foundation, either version 3 of the License, or
    37 #   (at your option) any later version.
    38 #
    39 #   This program is distributed in the hope that it will be useful,
    40 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
    41 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    42 #   GNU General Public License for more details.
    43 #
    44 #   You should have received a copy of the GNU General Public License
    45 #   along with this program.  If not, see http://www.gnu.org/licenses/.
    46 #
    47 # VERSION
    48 #   $Date: 2010-11-04 19:06:06 -0400 (Thu, 04 Nov 2010) $
    49 #   $Author: cschlep $
    50 #   $URL: file:///data/svn/software/spec/trunk/common/shutter.mac $
    51 #   $Revision: 17 $
    52 #
    53 # DEPENDENCIES
    54 #   Chained macro definitions affected by this macro:
    55 #   - user_precount
    56 #   - user_getcounts
    57 #   - cleanup_always
    58 #
    59 # HISTORY
    60 #   2004/11/06 (CS):
    61 #   - modified the first original version to comply with naming and format
    62 #     conventions
    63 #   - implemented help-file support and wrote help texts.
    64 #
    65 #   2010/03/30 (CS):
    66 #   - added the following global variables to make macro more easily portable:
    67 #
    68 #     SHUTTER_CONTROL_PV      # EPICS PV name for the shutter control (bo)
    69 #     SHUTTER_CONTROL_OPEN    # EPICS control value for open shutter
    70 #     SHUTTER_CONTROL_CLOSED  # EPICS control value for closed shutter
    71 #     SHUTTER_STATUS_PV       # EPICE PV name for the shutter status (bi)
    72 #     SHUTTER_STATUS_OPEN     # EPICS status value for open shutter
    73 #     SHUTTER_STATUS_CLOSED   # EPICS status value for closed shutter
    74 #     SHUTTER_IS_ON           # flag for automatic shutter control
    75 #     SHUTTER_SLEEP_TIME      # SPEC sleep time after opening shutter
    76 #
    77 #   2010/07/23 (CS):
    78 #   - added SVN keywords (replacing CVS keywords)
    79 #
    80 #   2011/12/19 (CS):
    81 #   - reformatted code documentation to work with ROBODoc
    82 #   - added shutter_setup with following internal macros:
    83 #     * _shutter_print_setup
    84 #     * _shutter_set_option
    85 #     * _clear_screen
    86 #   - replaced SHUTTER_STATUS* with SHUTTER_MONITOR*
    87 #   - replaced global variables _OPEN with _OPEN_VAL and
    88 #     _CLOSED with _CLOSED_VAL
    89 #
    90 #%-
    91 #==============================================================================
    92 
    93 #==============================================================================
    94 # Define some global variables
    95 # ----------------------------
    96 
    97     global SHUTTER_MAC
    98            SHUTTER_MAC = DOFILE
    99 
    100     # EPICS PV of the binary output which controls the shutter
     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)
    101635    #
    102     global SHUTTER_CONTROL_PV
    103            SHUTTER_CONTROL_PV = "X04SA-ES3-SC:FPS"
    104 
    105     global SHUTTER_CONTROL_OPEN_VAL
    106            SHUTTER_CONTROL_OPEN_VAL = "On"
    107 
    108     global SHUTTER_CONTROL_CLOSED_VAL
    109            SHUTTER_CONTROL_CLOSED_VAL = "Off"
    110 
    111     # EPICS PV of the binary input which monitors the state of the shutter
    112     # if SHUTTER_MONITOR_PV = "", no monitoring is performed
     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>
    113665    #
    114     global SHUTTER_MONITOR_PV
    115            SHUTTER_MONITOR_PV = ""
    116 
    117     global SHUTTER_MONITOR_OPEN_VAL
    118            SHUTTER_MONITOR_OPEN_VAL = "open"
    119 
    120     global SHUTTER_MONITOR_CLOSED_VAL
    121            SHUTTER_MONITOR_CLOSED_VAL = "closed"
    122 
    123     global SHUTTER_IS_ON
    124            SHUTTER_IS_ON = 0
    125 
    126     global SHUTTER_SLEEP_TIME
    127            SHUTTER_SLEEP_TIME = 0.1
    128 
    129 
    130 #==============================================================================
    131 # This macro file contains the following commands:
    132 #==============================================================================
    133 
    134 #------------------------------------------------------------------------------
    135 #%+M* shutter/sh_help, shutter_help
    136 #     ===============
    137 #
    138 # SUMMARY
    139 #   Displays the shutter help text.
    140 #
    141 # USAGE
    142 #   > sh_help
    143 #
    144 # NOTE
    145 #   The help text is generated by simply displaying the text file
    146 #   shutter_mac.txt, which should reside in the same directory as shutter.mac.
    147 #   If the file does not exist, a generic help text is shown.
    148 #%-
    149 
    150 def shutter_help 'sh_help'
    151 
    152 def sh_help '{
    153 #   =======
    154 
    155   unix (sprintf ("dirname %s", SHUTTER_MAC), _1)
    156   ll = length (_1)
    157   if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
    158   file = sprintf ("%s/shutter_mac.txt", _1)
    159   if (file_info (file, "-e")) {
    160     unix (sprintf ("cat %s", file))
    161   } else {
    162     printf("\n  Macros available in file shutter.mac:\n")
    163     printf(  "                           ===========\n")
    164     printf("\n")
    165     printf("  sh_help      - creates this help text\n")
    166     printf("  shop         - opens the fast shutter\n")
    167     printf("  shcl         - closes the fast shutter\n")
    168     printf("  shon         - activate automatic shutter opening and closing\n")
    169     printf("  shoff        - turn automatic shutter opening and closing off\n")
    170     printf("  sh_status    - display whether the shutter is open or closed\n")
    171     printf("  sh_show      - display shutter configuration and status\n")
    172     printf("  sh_setup     - modify the shutter configuration\n")
    173     printf("\n")
    174   }
    175 }'
    176 
    177 
    178 #------------------------------------------------------------------------------
    179 #%+M* shutter/shop, shutter_open
    180 #     ============
    181 #
    182 # USAGE
    183 #   > shop
    184 #
    185 # SUMMARY
    186 #   Open the fast photon shutter
    187 #%-
    188 
    189 def shutter_open 'shop'
    190 
    191 def shop'{
    192 #   ====
    193 
    194     epics_put (SHUTTER_CONTROL_PV, SHUTTER_CONTROL_OPEN_VAL)
    195     if (SHUTTER_MONITOR_PV == ""){
    196         sleep(SHUTTER_SLEEP_TIME)
    197     } else {
    198         while(epics_get(SHUTTER_MONITOR_PV) != SHUTTER_MONITOR_OPEN_VAL){
    199             sleep(0.01)
    200         }
    201     }
    202 }'
    203 
    204 
    205 #------------------------------------------------------------------------------
    206 #%+M* shutter/shcl, shutter_close
    207 #     ============
    208 #
    209 # USAGE
    210 #   > shcl
    211 #
    212 # SUMMARY
    213 #   Close the fast photon shutter
    214 #%-
    215 
    216 def shutter_close 'shcl'
    217 
    218 def shcl'{
    219 #   ====
    220 
    221     epics_put (SHUTTER_CONTROL_PV, SHUTTER_CONTROL_CLOSED_VAL)
    222     if (SHUTTER_MONITOR_PV != ""){
    223         while(epics_get(SHUTTER_MONITOR_PV) != SHUTTER_MONITOR_CLOSED_VAL){
    224             sleep(0.01)
    225         }
    226     }
    227 }'
    228 
    229 
    230 #------------------------------------------------------------------------------
    231 #%+M* shutter/shon, shutter_on
    232 #     ============
    233 #
    234 # SUMMARY
    235 #   Activate automatic shutter opening and closing.
    236 #
    237 # DESCRIPTION
    238 #   If automatic shutter control is enabled, the shutter is opened just before
    239 #   an actual count command is executed and immediately closed again thereafter
    240 #   to prevent unnecessary sample and detector irradiation.
    241 #
    242 # USAGE
    243 #   > shon [<flag>]
    244 #
    245 #   When called with no <flag> argument, shon enables automatic shutter
    246 #   control. <flag> can be one of the following
    247 #     flag = 1 --> enable automatic shutter control (default)
    248 #     flag = 0 --> disable automatic shutter control
    249 #
    250 # NOTES
    251 #   When automatic shutter control is enabled, the fast photon shutter is
    252 #   always closed in a case of any error (this includes also Ctrl-C
    253 #   interrupts).
    254 #%-
    255 
    256 def shutter_on 'shon'
    257 
    258 def shon '{
    259 #   ====
    260 
    261   if($# == 0){
    262     _status = 1
    263   } else if($# == 1){
    264     _status = $1
    265   } else {
    266     printf("Error: wrong number of arguments in \'shon\'. Exiting...\n")
    267     printf("Usage:\n")
    268     printf("  shon <flag>\n")
    269     printf("flag = 1 --> enable\n")
    270     printf("flag = 0 --> disable\n")
    271     exit
    272   }
    273 
    274   if(_status){
    275 
    276     SHUTTER_IS_ON = 1
    277 
    278     # add to user_precount (opening) and user_getcounts (closing)
    279     cdef("user_precount","shop; ","aaa_shutter_user_precount_key",0x10)
    280     cdef("user_getcounts","shcl; ","zzz_shutter_user_getcounts_key",0x20)
    281 
    282     # add shcl to cleanup_always to close in case of errors
    283     cdef("cleanup_always","shcl; ","aaa_shutter_cleanup_key",0x10)
    284     printf("Automatic shutter opening is ON\n")
    285   } else {
    286 
    287     SHUTTER_IS_ON = 0
    288 
    289     # remove from user_precount and getcounts
    290     cdef("user_precount","","aaa_shutter_user_precount_key","delete")
    291     cdef("user_getcounts","","zzz_shutter_user_getcounts_key","delete")
    292     cdef("cleanup_always","","aaa_shutter_cleanup_key","delete")
    293     printf("Automatic shutter opening is OFF\n")
    294   }
    295 
    296 }'
    297 
    298 
    299 #------------------------------------------------------------------------------
    300 #%+M* shutter/shoff, shutter_off
    301 #     =============
    302 #
    303 # USAGE
    304 #   > shoff
    305 #
    306 # SUMMARY
    307 #   Turn automatic shutter opening and closing OFF.
    308 #%-
    309 
    310 def shutter_off 'shoff'
    311 
    312 def shoff '{
    313 #   ======
    314 
    315   shon 0
    316 
    317 }'
    318 
    319 
    320 #------------------------------------------------------------------------------
    321 #%+M* shutter/sh_show, shutter_show
    322 #     ===============
    323 #
    324 # USAGE
    325 #   > sh_show
    326 #
    327 # SUMMARY
    328 #   Display the fast photon shutter setup and status
    329 #
    330 # OUTPUT
    331 #   This is a sample output:
    332 #
    333 #   Shutter setup:
    334 #
    335 #   1) Shutter control PV name                     : X04SA-ES3-SC:FPS
    336 #   2) Control PV value for shutter OPEN           : On
    337 #   3) Control PV value for shutter CLOSED         : Off
    338 #   4) Shutter monitor PV name ("" if none)        :
    339 #   5) Monitor PV value for shutter OPEN           : open
    340 #   6) Monitor PV value for shutter CLOSED         : closed
    341 #   7) Shutter delay time                          : 0.10 sec
    342 #   8) Auto shutter enable(1) / disable(0)         : 0
    343 #
    344 #   Shutter is OPEN
    345 #   Automatic shutter opening is ON
    346 #%-
    347 
    348 def shutter_show 'sh_show'
    349 
    350 def sh_show'{
    351 #   =======
    352 
    353   _shutter_print_setup
    354   sh_status
    355 
    356 }'
    357 
    358 
    359 #------------------------------------------------------------------------------
    360 #%+M* shutter/sh_status, shutter_status
    361 #     =================
    362 #
    363 # USAGE
    364 #   > sh_status
    365 #
    366 # SUMMARY
    367 #   Display the fast photon shutter status (OPEN or CLOSED)
    368 #
    369 # OUTPUT
    370 #   This is a sample output:
    371 #
    372 #   Shutter is OPEN
    373 #   Automatic shutter opening is ON
    374 #%-
    375 
    376 def shutter_status 'sh_status'
    377 
    378 def sh_status'{
    379 #   =========
    380 
    381     if (SHUTTER_MONITOR_PV != ""){
    382         if (epics_get(SHUTTER_MONITOR_PV)==SHUTTER_MONITOR_OPEN_VAL){
    383           printf("Shutter is OPEN\n")
    384         } else {
    385           printf("Shutter is CLOSED\n")
    386         }
    387     } else {
    388         if (epics_get(SHUTTER_CONTROL_PV)==SHUTTER_CONTROL_OPEN_VAL){
    389           printf("Shutter is OPEN\n")
    390         } else {
    391           printf("Shutter is CLOSED\n")
    392         }
    393     }
    394 
    395     if (SHUTTER_IS_ON == 1){
    396       printf("Automatic shutter opening is ON\n")
    397     } else {
    398       printf("Automatic shutter opening is OFF\n")
    399     }
    400 
    401 }'
    402 
    403 
    404 #------------------------------------------------------------------------------
    405 #%+M* shutter/sh_setup, shutter_setup
    406 #     ================
    407 #
    408 # USAGE
    409 #   > sh_setup
    410 #
    411 #   Then modify the dialog options
    412 #
    413 # SUMMARY
    414 #   Modify the shutter configuration.
    415 #%-
    416 
    417 def shutter_setup 'sh_setup'
    418 
    419 def sh_setup '{
    420 #   ========
    421 
    422     local _setup_numitems, _setup_option, _tmp_option, _str1
    423 
    424     # total number of setup items
    425     _setup_numitems = 8
    426 
    427     _clear_screen
    428 
    429     _setup_option = 0
    430     _tmp_option = -1
    431     while (_tmp_option) {
    432         _tmp_option = -1
    433         while (_tmp_option < 0 || _tmp_option > _setup_numitems){
    434             _shutter_print_setup
    435             _str1 = sprintf("Enter 1-%d to change the parameters, 0 to quit",\
    436               _setup_numitems)
    437             _tmp_option = getval(_str1, _setup_option)
    438             if(index(_tmp_option, "q") == 1 || index(_tmp_option, "Q") == 1){
    439               _tmp_option = 0
    440             }
    441         }
    442         _setup_option = _tmp_option
    443         if (_setup_option != 0){
    444             _shutter_set_option _setup_option
    445         }
    446         _setup_option = (_tmp_option + 1)%(_setup_numitems + 1)
    447     }
    448 }'
    449 
    450 
    451 #==============================================================================
    452 # Internal macros
    453 #==============================================================================
    454 
    455 #------------------------------------------------------------------------------
    456 #%+iM* shutter/_shutter_print_setup
    457 #      ============================
    458 #
    459 # SUMMARY
    460 #   Prints the configuration options and current values to screen
    461 #
    462 # NOTE
    463 #   The option numbers must be kept in sync between _shutter_set_option and
    464 #   _shutter_print_setup
    465 #%-
    466 
    467 def _shutter_print_setup '{
    468 #   ====================
    469 
    470     tty_cntl("ho")  # home cursor on left upper corner of screen
    471     tty_cntl("cd")  # clear the rest of the screen
    472 
    473     tty_cntl("so")  # highlight font
    474     printf("Shutter setup:\n")
    475     tty_cntl("se")  # turn off font highlighting
    476 
    477     printf("\n 1) Shutter control PV name              \t: %s", \
    478       SHUTTER_CONTROL_PV)
    479     printf("\n 2) Control PV value for shutter OPEN    \t: %s", \
    480       SHUTTER_CONTROL_OPEN_VAL)
    481     printf("\n 3) Control PV value for shutter CLOSED  \t: %s", \
    482       SHUTTER_CONTROL_CLOSED_VAL)
    483     printf("\n 4) Shutter monitor PV name (\"\" if none) \t: %s", \
    484       SHUTTER_MONITOR_PV)
    485     printf("\n 5) Monitor PV value for shutter OPEN    \t: %s", \
    486       SHUTTER_MONITOR_OPEN_VAL)
    487     printf("\n 6) Monitor PV value for shutter CLOSED  \t: %s", \
    488       SHUTTER_MONITOR_CLOSED_VAL)
    489     printf("\n 7) Shutter delay time                   \t: %.2f sec", \
    490       SHUTTER_SLEEP_TIME)
    491     printf("\n 8) Auto shutter enable(1) / disable(0)  \t: %d", \
    492       SHUTTER_IS_ON)
    493     printf("\n\n")
    494 }'
    495 
    496 #------------------------------------------------------------------------------
    497 #%+iM* shutter/_shutter_set_option
    498 #      ===========================
    499 #
    500 # SUMMARY
    501 #   Sets a new value for a given option
    502 #
    503 # DESCRIPTION
    504 #   Sets a new value for a given option from the options menu that was created
    505 #   with the _shutter_print_setup command.
    506 #
    507 # NOTE
    508 #   The option numbers must be kept in sync between _shutter_set_option and
    509 #   _shutter_print_setup
    510 #%-
    511 
    512 def _shutter_set_option '{
    513 #   ===================
    514 
    515     if ($1==1) {
    516         SHUTTER_CONTROL_PV = getsval("Enter shutter control PV name",\
    517             SHUTTER_CONTROL_PV)
    518     } else if ($1==2) {
    519         SHUTTER_CONTROL_OPEN_VAL = \
    520             getsval("Control PV value for shutter OPEN",\
    521             SHUTTER_CONTROL_OPEN_VAL)
    522     } else if ($1==3) {
    523         SHUTTER_CONTROL_CLOSED_VAL = \
    524             getsval("Control PV value for shutter CLOSED",\
    525             SHUTTER_CONTROL_CLOSED_VAL)
    526     } else if ($1==4) {
    527         _str = "Enter shutter monitor PV name"\
    528                "(leave blank if shutter is not actively monitored)"
    529         SHUTTER_MONITOR_PV = \
    530             getsval(_str, SHUTTER_MONITOR_PV)
    531     } else if ($1==5) {
    532         SHUTTER_MONITOR_OPEN_VAL = \
    533             getsval("Monitor PV value for shutter OPEN",\
    534             SHUTTER_MONITOR_OPEN_VAL)
    535     } else if ($1==6) {
    536         SHUTTER_MONITOR_CLOSED_VAL = \
    537             getsval("Monitor PV value for shutter CLOSED",\
    538             SHUTTER_MONITOR_CLOSED_VAL)
    539     } else if ($1==7) {
    540         SHUTTER_SLEEP_TIME = getsval("Enter shutter delay time [seconds]",\
    541             SHUTTER_SLEEP_TIME)
    542     } else if ($1==8) {
    543         _status = yesno("Enable the automatic shutter control?",\
    544             SHUTTER_IS_ON)
    545         shon _status
    546     }
    547 }'
    548 
    549 #------------------------------------------------------------------------------
    550 #%+iM* shutter/_clear_screen
    551 #      =====================
    552 #
    553 # SUMMARY
    554 #   Clears the terminal screen
    555 #
    556 # DESCRIPTION
    557 #   Clears the screen without losing the screen history or messing up the
    558 #   scrolling capabilities (this has been a problem for certain terminals)
    559 #   by blanking out the entire height of the screen and returning the cursor to
    560 #   the top left corner.
    561 #%-
    562 
    563 def _clear_screen '{
    564 #   =============
    565 
    566   # update the ROWS and COLS variables in case the terminal has been resized
    567   tty_cntl("resized?")
    568 
    569   # print as many newlines as there are ROWS in terminal
    570   cl_text = ""
    571   for (i=0;i<ROWS;i++){
    572     cl_text = cl_text "\n"
    573   }
    574   printf(cl_text)
    575 
    576   # move back to the top of the screen and clear to end of the screen
    577   tty_move(0,0)
    578   tty_cntl("cd")
    579 
    580 }'
    581 
    582 #==============================================================================
    583 # End of $Id$
    584 #==============================================================================
     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
  • specdomain/src/test/index.rst

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r898 r902  
    1 .. $Id: $
     1.. $Id$
    22
    33Welcome to sphinxcontrib-specdomain-acceptancetest's documentation!
     
    1010
    1111   test_doc
     12   autodoc
    1213   
    1314Indices and tables
  • specdomain/src/test/move.mac

    r900 r902  
    11
    22# $Id$
    3 # from Christian Schlepuetz (formatted for RoboDoc)
    4 
    5 #==============================================================================
    6 #%+H* common/move
    7 #     ===========
    8 #
    9 # NAME
    10 #   move.mac
    11 #
    12 # SUMMARY
    13 #   Commands to move motors.
    14 #
    15 # DESCRIPTION
    16 #   Collection of helpful move commands for synchronized motor movements or
    17 #   reciprocal space moves.
    18 #
    19 # AUTHOR
    20 #   C. M. Schlepuetz (CS, cschlep)
    21 #
    22 # CREATION DATE
    23 #   2005/06/06
    24 #
    25 # COPYRIGHT
    26 #   Copyright 2006-2011 by the above authors (see AUTHOR/AUTHORS)
    27 #
    28 #   This program is free software: you can redistribute it and/or modify
    29 #   it under the terms of the GNU General Public License as published by
    30 #   the Free Software Foundation, either version 3 of the License, or
    31 #   (at your option) any later version.
    32 #
    33 #   This program is distributed in the hope that it will be useful,
    34 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
    35 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    36 #   GNU General Public License for more details.
    37 #
    38 #   You should have received a copy of the GNU General Public License
    39 #   along with this program.  If not, see http://www.gnu.org/licenses/.
    40 #
    41 # VERSION
    42 #   $Date: 2011-06-29 12:21:58 -0400 (Wed, 29 Jun 2011) $
    43 #   $Author: cschlep $
    44 #   $URL: file:///data/svn/software/spec/trunk/common/move.mac $
    45 #   $Revision: 28 $
    46 #
    47 # DEPENDENCIES
    48 #   - none
    49 #
    50 # HISTORY
    51 #   2005/06/06 (CS):
    52 #   - created first version of this file
    53 #
    54 #   2010/07/23 (CS):
    55 #   - added SVN keywords
    56 #   - removed all non-general definitions (particular to a certain instrument)
    57 #
    58 #   2011/04/19 (CS):
    59 #   - added "multi-move" commands, which allow to move multiple motors in one
    60 #     command (based on the standard mv command structure):
    61 #     * mmv      # multi-move
    62 #     * ummv     # updated multi-move
    63 #     * mmvr     # relative multi-move
    64 #     * ummvr    # updated relative multi-move
    65 #     * _mmv     # low-level multi-move command
    66 #     * _mmvr    # low-level relative multi-move command
    67 #     * uwmm     # updated display of motor positions
    68 #
    69 #   2011/12/21 (CS):
    70 #   - reformatted code documentation to work with ROBODoc
    71 #%-
    72 #==============================================================================
    73 
    74 
    75 #==============================================================================
    76 # Define some global variables
    77 # ----------------------------
    78 
    79   # Save the name of this macro file.
    80   global  MOVE_MAC
    81           MOVE_MAC = DOFILE
    82 
    83 #==============================================================================
    84 # This macro file contains the following commands:
    85 #==============================================================================
    86 
    87 #------------------------------------------------------------------------------
    88 #%+M* move/move_help
    89 #     ==============
    90 #
    91 # SUMMARY
    92 #   Generates the help text.
    93 #
    94 # NOTE
    95 #   This help text is obtained by displaying the file move_mac.txt, which
    96 #   should reside in the same directory as move.mac. If the file does not
    97 #   exist, a generic help text is shown.
    98 #%-
    99 
    100 def helpmove 'move_help'
    101 def movehelp 'move_help'
    102 
    103 def move_help '{
    104 #   =========
    105 
    106   unix (sprintf ("dirname %s", MOVE_MAC), _1)
    107   ll = length (_1)
    108   if (substr (_1, ll, 1) == "\n") _1 = substr (_1, 1, (ll - 1))
    109   file = sprintf ("%s/move_mac.txt", _1)
    110   if (file_info (file, "-e")) {
    111     unix (sprintf ("cat %s", file))
    112   }
    113   else {
    114     printf ("\n  Macros available in file move.mac ($$Revision: 28 $$):")
    115     printf ("\n                           ========\n")
    116     printf ("\n    mmv         - move multiple motors at once")
    117     printf ("\n    ummv        - multi-move showing updated positions")
    118     printf ("\n    mmvr        - relative move of multiple motors at once")
    119     printf ("\n    ummvr       - relative multi-move showing updated pos.")
    120     printf ("\n    mvhkl       - like \'br\' but displays angles first")
    121     printf ("\n    umvhkl      - like \'ubr\' but displays angles first")
    122     printf ("\n    rtw         - reciprocal space tweak (like \'tw\')")
    123   }
    124 }'
    125 
    126 
    127 
    128 #------------------------------------------------------------------------------
    129 #%+M* move/mmv
    130 #     ========
    131 #
    132 # SUMMARY
    133 #   Multi-move command, moves multiple motors at once
    134 #
    135 # USAGE
    136 #   > mmv <mot1> <pos1> <mot2> <pos2> ...
    137 #
    138 # EXAMPLE
    139 #   > mmv del 10 nu 5 phi 90
    140 #%-
    141 
    142 def mmv '_mmv $*; move_poll'
    143 #   ===
    144 
    145 
    146 #------------------------------------------------------------------------------
    147 #%+M* move/ummv
    148 #     =========
    149 #
    150 # SUMMARY
    151 #   Multi-move command, moves multiple motors at once and displays updated
    152 #   motor positions at regular intervals until move has finished.
    153 #
    154 # USAGE
    155 #   > ummv <mot1> <pos1> <mot2> <pos2> ...
    156 #
    157 # EXAMPLE
    158 #   > ummv del 10 nu 5 phi 90
    159 #%-
    160 
    161 def ummv '_mmv $*; uwmm $*'
    162 #   ====
    163 
    164 
    165 #------------------------------------------------------------------------------
    166 #%+M* move/mmvr
    167 #     =========
    168 #
    169 # SUMMARY
    170 #   Relative multi-move command
    171 #
    172 # DESCRIPTION
    173 #   Moves multiple motors at once by a relative amount
    174 #
    175 # USAGE
    176 #   > mmvr <mot1> <dist1> <mot2> <dist2> ...
    177 #
    178 # EXAMPLE
    179 #   > mmvr del -1 nu -2 phi 3
    180 #%-
    181 
    182 def mmvr '_mmvr $*; move_poll'
    183 #   ====
    184 
    185 
    186 #------------------------------------------------------------------------------
    187 #%+M* move/ummvr
    188 #     ==========
    189 #
    190 # SUMMARY
    191 #   Relative multi-move command
    192 #
    193 # DESCRIPTION
    194 #   Moves multiple motors at once by a relative amount and displays updated
    195 #   motor positions at regular intervals until move has finished.
    196 #
    197 #  USAGE
    198 #    > ummvr <mot1> <dist1> <mot2> <dist2> ...
    199 #
    200 #  EXAMPLE
    201 #    > ummvr del -1 nu -2 phi 3
    202 #%-
    203 
    204 def ummvr '_mmvr $*; uwmm $*'
    205 #   =====
    206 
    207 
    208 #------------------------------------------------------------------------------
    209 #%+M* move/mvhkl
    210 #     ==========
    211 #
    212 # SUMMARY
    213 #   Reciprocal space move with user confirmation
    214 #
    215 # DESCRIPTION
    216 #   Modified version of br which displays the angle positions of the requested
    217 #   hkl-position first and asks for the users confirmation to move there before
    218 #   the movement is started.
    219 #
    220 # USAGE
    221 #   > mvhkl <H> <K> <L>
    222 #
    223 # EXAMPLE
    224 #   > mvhkl 3 1 2
    225 #%-
    226 
    227 def mvhkl '{
    228 #   =====
    229 
    230   local old_A, possible, ok, s
    231 
    232   getangles
    233   old_A = A
    234 
    235   if ($# != 3) {
    236     print "\aUsage:"
    237     print "            mvhkl <H> <K> <L>"
    238     exit
    239   }
    240 
    241   H = $1; K = $2; L = $3
    242 
    243   # calcA returns 0 for success, -1 for unobtainable reflection
    244   possible = !(-(calcA))
    245 
    246   if(possible) {
    247     for (i=0;i<_numgeo;i++) {
    248         s = motor_name(mA[i])
    249         printf ("%7s = %9.4f --> %9.4f\n", s, old_A[mA[i]],  A[mA[i]])
    250     }
    251     ok = yesno ("Move to these values? ", 1)
    252     if (ok) {
    253       br $1 $2 $3
    254     } else{
    255       print "Move cancelled."
    256       exit
    257     }
    258   }
    259 }'
    260 
    261 
    262 #------------------------------------------------------------------------------
    263 #%+M* move/umvhkl
    264 #     ===========
    265 #
    266 # SUMMARY
    267 #   updated reciprocal space move with user confirmation
    268 #
    269 # DESCRIPTION
    270 #   Modified version of ubr which displays the angle positions of the
    271 #   requested hkl-position first and asks for the users confirmation to move
    272 #   there before the movement is started.
    273 #
    274 # USAGE
    275 #   > umvhkl <H> <K> <L>
    276 #%-
    277 
    278 def umvhkl '{
    279 #   ======
    280 
    281   local old_A, possible, ok, s
    282 
    283   getangles
    284   old_A = A
    285 
    286   if ($# != 3) {
    287     print "\aUsage:"
    288     print "            mvhkl <H> <K> <L>"
    289     print "   or       mvhkl <H> <K> <L> auto"
    290     exit
    291   }
    292 
    293   H = $1; K = $2; L = $3
    294 
    295   # calcA returns 0 for success, -1 for unobtainable reflection
    296   possible = !(-(calcA))
    297 
    298   if(possible) {
    299     for (i=0;i<_numgeo;i++) {
    300         s = motor_name(mA[i])
    301         printf ("%7s = %9.4f --> %9.4f\n", s, old_A[mA[i]],  A[mA[i]])
    302     }
    303     ok = yesno ("Move to these values? ", 1)
    304     if (ok) {
    305       ubr $1 $2 $3
    306     } else {
    307       print "Move cancelled."
    308       exit
    309     }
    310   }
    311 }'
    312 
    313 
    314 #------------------------------------------------------------------------------
    315 #%+M* move/rtw
    316 #     ========
    317 #
    318 # SUMMARY
    319 #   Reciprocal space tweak
    320 #
    321 # DESCRIPTION
    322 #   rtw works just like the normal tw command for individual motors, but tweaks
    323 #   in the reciprocal space coordinates H, K, L.
    324 #
    325 # USAGE
    326 #   > rtw <coord1> [<coord2> ...] <delta1> [<delta2> ...] [<count_time>]
    327 #   where <coordN> = "H", "K", or "L"
    328 #
    329 # EXAMPLE
    330 #   > rtw H K 0.1 0.2
    331 #   simultaneously tweaks H in steps of +0.1 and K in steps of +0.2
    332 #%-
    333 
    334 def  rtw'{
    335 #    ====
    336 
    337   local   i, n, m[], dh, dk, dl, p[], t, ct, dir, d0, done, d[],c[],Q_mne[]
    338 
    339   Q_mne[0] = "H"
    340   Q_mne[1] = "K"
    341   Q_mne[2] = "L"
    342 
    343   n = split("$*", m)
    344   if ((n < 2) || (n > 7)) {
    345     print "Usage:  rtw coord1 [coord2 ...] delta1 [delta2 ...] [count_time]"
    346     print "  where coord = H, K, or L"
    347     exit
    348   }
    349 
    350   # check if count_time was given
    351   if (n&1){
    352           ct = m[n-1]
    353   }
    354 
    355   n = int(n/2)
    356   dh = 0; dk = 0; dl = 0;
    357   for (i = 0; i < n; i++) {
    358     if (m[i] == "h" || m[i] == "H"){
    359       d[i] = m[n+i]
    360       c[i] = 0
    361       dh = d[i]
    362     } else if (m[i] == "k" || m[i] == "K"){
    363       d[i] = m[n+i]
    364       c[i] = 1
    365       dk = d[i]
    366     } else if (m[i] == "l" || m[i] == "L"){
    367       d[i] = m[n+i]
    368       c[i] = 2
    369       dl = d[i]
    370     } else{
    371       printf("Bad coordinate for tweak:  %s.\n", m[i])
    372       exit
    373     }
    374   }
    375 
    376   get_angles
    377   rt = "get_angles; printf(\"\n\")\n"
    378   for (i = 0; i < n; i++) {
    379     p[i] = Q[c[i]]
    380     rt = rt sprintf("printf(\"Tweaked %s from %g to %%g\n\",Q[%d])\n",\
    381     Q_mne[c[i]], p[i], c[i])
    382   }
    383   cdef("cleanup_once", rt, "rtweak")
    384 
    385   print "Indicate direction with + (or p) or - (or n) or enter"
    386   print "new step size.  Type something else (or ^C) to quit.\n\n"
    387 
    388   t = "+"
    389   dir = 1
    390   for (;;) {
    391     waitmove; get_angles; calcHKL
    392     if (ct) {
    393       if (!set_sim(-1) && _sleep)
    394         do_sleep _sleep
    395       count_em ct;
    396       if (!TW_UPDATE) {
    397         waitcount
    398         done = 1
    399       } else
    400           done = 0
    401       for (;;) {
    402         get_counts
    403         if (dh != 0){
    404           printf("H = %.4f ",H)
    405         }
    406         if (dk != 0){
    407           printf("K = %.4f ",K)
    408         }
    409         if (dl != 0){
    410           printf("L = %.4f ",L)
    411         }
    412         if (ct < 0)
    413             printf("%s = %g, ", cnt_mne(sec), S[sec])
    414         else if (MON >= 0)
    415             printf("%s = %g, ", cnt_mne(MON), S[MON])
    416         printf("%s = %g, ", cnt_mne(DET), S[det])
    417         tty_cntl("ce")
    418         if (done)
    419             break
    420         sleep(UPDATE)
    421         printf("\r")
    422         done = !chk_count
    423       }
    424     } else {
    425         if (dh != 0){
    426           printf("H = %.4f ",H)
    427         }
    428         if (dk != 0){
    429           printf("K = %.4f ",K)
    430         }
    431         if (dl != 0){
    432           printf("L = %.4f ",L)
    433         }
    434     }
    435 
    436     if (TW_BEEP) beep
    437     t = getval("which way", t)
    438     if (t+0 != 0) {
    439      d0 = fabs(t / d[0])
    440      for (i = 0; i < n; i++)
    441          d[i] *= d0
    442      t = t<0? "-":"+"
    443     }
    444     if (t == "+" || t == "p")
    445             dir = 1
    446     else if (t == "-" || t == "n")
    447             dir = -1
    448     else
    449             break
    450     for (i = 0; i < n; i++){
    451             Q[c[i]] += dir * d[i]
    452     }
    453     calcA
    454     calcHKL
    455     move_em
    456     if (!TW_UPDATE) {
    457       waitmove
    458     } else for (done = 0;;) {
    459       get_angles
    460       for (i = 0; i < n; i++)
    461           printf("%s = %.3f, ", Q_mne[c[i]], Q[c[i]])
    462       tty_cntl("ce")
    463       printf("\r")
    464       if (done)
    465           break
    466       sleep(UPDATE)
    467       done = !chk_move
    468     }
    469   }
    470 
    471   cdef("cleanup_once", "", "rtweak", "delete")
    472   for (i = 0, rt = "\n"; i < n; i++)
    473     rt = rt sprintf("Tweaked %s from %g to %g\n", \
    474             Q_mne[c[i]], p[i], Q[c[i]])
    475   printf(rt)
    476 }'
    477 
    478 
    479 #==============================================================================
    480 # Internal macros
    481 #==============================================================================
    482 
    483 #------------------------------------------------------------------------------
    484 #%+iM* move/_mmv
    485 #
    486 # SUMMARY
    487 #   Low-level multi-move command
    488 #
    489 # DESCRIPTION
    490 #   This is the equivalent to the _mv command for single motor moves.
    491 #
    492 #%-
    493 
    494 def _mmv '{
    495 #   ====
    496 
    497   local _ntokens, _tokens
    498 
    499   _ntokens = split("$*", _tokens)
    500 
    501   if (_ntokens&1){
    502           eprint "Wrong number of arguments!"
    503           eprint " Usage:  (u)mmv <mot1> <pos1> <mot2> <pos2> ..."
    504           exit
    505   }
    506 
    507   for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    508     eval(sprintf("_check0 %s", _tokens[_ii]))
    509   }
    510   waitmove; get_angles;
    511   for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    512     if(motor_num(_tokens[_ii]) < 0) {exit}
    513     A[motor_num(_tokens[_ii])] = _tokens[_ii+1]
    514   }
    515   ifp{
    516     fprintf(PRINTER,"\nmmv ")
    517     for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    518       fprintf(PRINTER,"%s %g", _tokens[_ii], A[motor_num(_tokens[_ii+1])])
    519     }
    520     fprintf(PRINTER,"\n")
    521   }
    522   move_em
    523 }'
    524 
    525 
    526 #------------------------------------------------------------------------------
    527 #%+iM* move/_mmvr
    528 #      ==========
    529 #
    530 # SUMMARY
    531 #   Low-level relative multi-move command
    532 #
    533 # DESCRIPTION
    534 #   This is the equivalent to the _mvr command for single motor moves.
    535 #%-
    536 
    537 def _mmvr '{
    538 #   =====
    539 
    540   local _ntokens, _tokens
    541 
    542   _ntokens = split("$*", _tokens)
    543 
    544   if (_ntokens&1){
    545           eprint "Wrong number of arguments!"
    546           eprint " Usage:  (u)mmvr <mot1> <dist1> <mot2> <dist2> ..."
    547           exit
    548   }
    549 
    550   for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    551     eval(sprintf("_check0 %s", _tokens[_ii]))
    552   }
    553   waitmove; get_angles;
    554   for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    555     if(motor_num(_tokens[_ii]) < 0) {exit}
    556     A[motor_num(_tokens[_ii])] += _tokens[_ii+1]
    557   }
    558   ifp{
    559     fprintf(PRINTER,"\nmmv ")
    560     for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    561       fprintf(PRINTER,"%s %g", _tokens[_ii], A[motor_num(_tokens[_ii+1])])
    562     }
    563     fprintf(PRINTER,"\n")
    564   }
    565   move_em
    566 }'
    567 
    568 
    569 #------------------------------------------------------------------------------
    570 #%+iM* move/uwmm
    571 #      =========
    572 #
    573 # SUMMARY
    574 #   Low-level macro to show updated positions during motor movements.
    575 #
    576 # DESCRIPTION
    577 #   This is the equivalent to the uwm command for single motor moves.
    578 #%-
    579 
    580 def uwmm '{
    581 #   ====
    582 
    583   local _ntokens, _tokens, _str
    584 
    585   _ntokens = split("$*", _tokens)
    586 
    587   if (_ntokens&1){
    588           eprint "Wrong number of arguments!"
    589           eprint " Usage:  uwmm <mot1> <pos1> <mot2> <pos2>...<motN> <posN>"
    590           exit
    591   }
    592 
    593   _str = ""
    594   for(_ii=0; _ii<_ntokens; _ii=_ii+2){
    595     _str += _tokens[_ii]
    596   }
    597   _update(_str)
    598 }'
    599 
    600 
    601 #==============================================================================
    602 # End of $Id$
    603 #==============================================================================
     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
  • specdomain/src/test/test_doc.rst

    • Property svn:eol-style set to native
    • Property svn:keywords set to Id
    r899 r902  
     1.. $Id$
     2
    13===============
    24Acceptance Test
     
    4345================================
    4446
     47.. note:: What should this look like?
     48
    4549Test references to ``specdomain`` objects at the global level:
    4650
     
    5155Single Module 'test_module'
    5256===========================
     57
     58.. note:: What should this look like?
    5359
    5460Test references to ``specdomain`` objects on an individual basis using inline code:
     
    122128
    123129:spec:record:`test_module:#user_address`
     130
Note: See TracChangeset for help on using the changeset viewer.