esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% FlexCurrent_mh.mac
#$Revision: 1.1 $
#%NAME% Macros for a the use of the FlexCurrent (orion:10000/sr/comploop/...)
# device as a macro motor and/or macro counter.
#%DESCRIPTION%
# The macros provide users with an interface between SPEC and the FlexCurrent
# (orion:10000/sr/comploop/...  device.
#%INTERNALS%
# You may declare a motor and a counter, even for the same
# device! The macro motor/counter macros can handle that.
#%BR% %BR%Now declare a %B%motor\0controller%B%:
#%BR% %BR%
#%PRE%
#MOTORS\0\0\0DEVICE\0\0\0\0\0\0ADDR\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0NUM\0\0\0\0\0\0\0<>TYPE%BR%
#\0\0\0YES\0\0\0FLEXCURRENT\0//orion:10000/sr/comploop/id18_0\0\0\0\01\0Macro\0Motors
#%PRE%
# %BR%
#Then create the macro motor:
#%BR% %BR%Unit is always 0 !
#%PRE%
#Number:\0<>Controller\0\0\0\0\0\0\0\00:\0MAC_MOT%BR%
#Unit/[Module/]Channel%BR%
#Name\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0<FlexCurren%BR%
#Mnemonic\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0flex%BR%
#%BR%
#Steps\0per\0degree/mm\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01000 <<< precision is 100 steps%BR%
#Sign\0of\0user\0*\0dial\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01%BR%
#Backlash\0[steps]\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00%BR%
#Steady-state\0rate\0[Hz]\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01%BR%
#Base\0rate\0[Hz]\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01%BR%
#Acceleration\0time\0[msec]\0\0\0\0\0\0\0\0\0\0\0\0\01%BR%
#Motor\0accumulator\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00%BR%
#Restrictions\0<>\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0NONE%BR%
#%BR%
#Dial\0=\0accumulator\0/\0steps%BR%
#\0\0High\0limit\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01000.0000%BR%
#\0\0Current\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00.0000%BR%
#\0\0Low\0limit\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00.0000%BR%
#User\0=\0sign\0*\0dial\0+\0offset%BR%
#\0\0Offset\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00.0000%BR%
#\0\0`High'\0limit\0\0\0\0\0\0\0\0\0\0\0\0\0\0\01000.0000%BR%
#\0\0Current\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00.0000%BR%
#\0\0`Low'\0limit\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00.0000%BR%
#%PRE%
#%BR% %BR% %BR%
# Then hit 'm' twice. Set the following for your motor:
#%PRE%
#Hardware\0read\0mode\0<>\0\0\0\0\0\0\0\0PR\0+\0AL\0+\0NQ
#%PRE%
#%BR% %BR%If needed, declare a %B%counter\0controller%B%:
#%BR% %BR%
#%PRE%
#SCALERS\0\0DEVICE\0\0\0\0\0\0\0ADDR\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0NUM\0\0\0\0\0\0\0\0\0<>TYPE%BR%
#\0\0\0YES\0\0\0FLEXCURRENT\0\0//orion:10000/sr/comploop/id18_0\0\0\01\0\0Macro\0Counter
#%PRE%%BR%
#%BR% %BR%
# The %B%counter%B% is then configured as :
#%PRE%
#Number\0\0\0\0\0Name\0\0Mnemonic\0\0<>Device\0\0Unit\0\0Chan\0\0\0<>Use\0As\0\0Scale\0Factor%BR%
#\0\0\0\0\00\0\0\0\0Cflex\0\0\0\0\0Cflex\0\0\0MAC_CNT\0\0\0\0\00\0\0\0\0\00\0\0\0\0counter\0\0\0\0\0\0\0\0\0\0\0\0\01%BR%
#%PRE%%BR%
#%BR% %BR%
#%END%
#%HISTORY%
#$Log: FlexCurrent_mh.mac,v $
#Revision 1.1  2016/12/02 12:07:16  guilloud
#changed TANGO_ERR test.
#
#Revision 1.0  2012/05/11 11:30:23  witsch
#Initial revision
#

need spec_utils
if (!(whatis("__flexcdebug")  & 2)) rdef __flexcdebug \'#$*\'


#%UU%
#%MDESC% toggle debug mode for the present macros.
def flexc_debug '{
    if ((whatis("__flexcdebug")>>16) <= 5) { # just a # sign -> off
        rdef __flexcdebug "eprint"
        print "flexc debug is ON"
    } else {
        rdef __flexcdebug \'#$*\'
        print "flexc debug is OFF"
    }
}
'

def __FlexC_tango_catch_error '{
    if (TANGO_ERR != "0") {
        tty_cntl("md")
        __errstr = macname " - " func "- ERROR: " what "(" addr ", " attr ")"
        __flexc_error(__errstr)
        __flexcdebug  TANGO_ERR
        tty_cntl("me")
    }
}
'

#%IU%(mesg)
#%MDESC% Attempts to write indentical error message only once in a while
def __flexc_error(errstr) '{
    global __FlexCERR[]
    local expiry, now, str
    str = "FlexC: " errstr
    expiry  =   5   # seconds before message is redisplayed
    now     = time()
    if (errstr in __FlexCERR) {
        if ((time() - __FlexCERR[errstr]) > expiry) {
            __FlexCERR[errstr] = now
            cprint(str, 0, 7)
        }
    } else {
        __FlexCERR[errstr] = now
        cprint(str, 0, 7)
    }
    local x
    for (x in __FlexCERR) {
        if ((time() - __FlexCERR[x]) > 20) {
            delete __FlexCERR[x]
        }
    }
}
'



#%IU%(mne, type, unit, mod, chan)
#%MDESC%
# Called by spec
def FLEXCURRENT_config(mne, type, unit, mod, chan) '{
    __flexcdebug "Configuring FlexCurrent", mne, type, unit, mod, chan

    if (type == "ctrl") {
        # check if device can be reached.
        local macname, func, attr, what, __errstr
        macname =   "FlexCurrent_mh.mac"
        func    =   "FLEXCURRENT_config()"
        what    =   "tango_get"
        attr    =   "State"
        addr    =   FLEXCURRENT_ADDR
        __flexcdebug "tango_get(\"" addr "\", \"" attr "\")"
        TANGO_ERR   = "-1"
        state   =   tango_get(addr, attr)
        # __FlexC_tango_catch_error # not wanted here !
        if (state == -1) {
            eprint "FlexCurrent controller", addr, "unusable!"
            return ".error."
        }
    }
}
'

#%IU%
#%MDESC%
# Called by spec
def FLEXCURRENT_cmd(mne, cmd, p1, p2, p3) '{
    __flexcdebug "Command FlexCurrent", mne, cmd, p1, p2, p3
    local macname, func, attr, what, __errstr
    macname =   "FlexCurrent_mh.mac"
    func    =   "FLEXCURRENT_cmd()"
    attr    =   "Current"
    addr    =   FLEXCURRENT_ADDR
    if (mne != "..") {
        if (cmd == "start_one") {
            # start counter, when it is one
            if (p2 == 0) {
                return
            }
            # move 
            what    =   "tango_put"
            __flexcdebug "tango_put(\"" addr "\", \"" attr "\")"
            TANGO_ERR   = "-1"
            tango_put(addr, attr, p1)
            __FlexC_tango_catch_error
            return
        }
        else if ((cmd == "position") || (cmd == "counts")) {
            local pos
            what    =   "tango_get"
            __flexcdebug "tango_get(\"" addr "\", \"" attr "\",", p1 ")"
            TANGO_ERR   = "-1"
            pos     =   tango_get(addr, attr)
            __FlexC_tango_catch_error
            __flexcdebug pos
            # return position
            return(pos)
        }
        else if (cmd == "count") {
            return 
        }
    }
}
'



#%MACROS%
#%IMACROS%
#%INTERNALS%
#%AUTHOR% H. Witsch, BLISS - ESRF, 
#$Revision: 1.1 $, $Date: 2016/12/02 12:07:16 $
#%TOC%