esrf

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

#%TITLE% lna_utils.mac
#%NAME%
#   Macros for LNA card from ISG. LNA=Liquid Nitrogen Auto-refill
#
#%DESCRIPTION%
#  These macros allow :
#%UL%
#  %LI%to monitor value of LNA resistor in a spec ct %LI%
#  %LI%to send an email  in case of refilling %LI%
#%XUL%
#
#%END%

def lna_watch '{
    global LNA_PAR[]

    while (1) {
        answer = isgdevice_comm(LNA_PAR["address"] , "?REFSTAT")
        
        if (answer == "ACTIVE") {
            print "active"
        }
        
        if (answer == "ABORT") {
            print "abort"
        }
        
        sleep (0.5)
    }

}'

def lna_setup '{

    global LNA_PAR[]

    # LNA_PAR["address"]
    # LNA_PAR["on"]
    # LNA_PAR["key"]
    # LNA_PAR["mnelo"]
    # LNA_PAR["mnehi"]
    # LNA_PAR["mail"]["on"]
    # LNA_PAR["mail"]["last"]

    LNA_PAR["address"] = "$1"
    LNA_PAR["key"]  = "lna"

    LNA_PAR["mnelo"] = "lnalo"
    LNA_PAR["mnehi"] = "lnahi"
   
    LNA_PAR["address"] = "lna1"

    cdef("user_getcounts", "lna_getcounts", LNA_PAR["key"])

}'

def lna_unsetup '{
    global LNA_PAR[]

    lna_off

    cdef("", "", LNA_PAR["key"], "delete")
}'

def lna_on '{
    global LNA_PAR[]

    LNA_PAR["on"] = 1 
 
}'

def lna_off '{
    global LNA_PAR[]

    LNA_PAR["on"] = 0
    S[cnt_num(LNA_PAR["mnelo"])] = 0
    S[cnt_num(LNA_PAR["mnehi"])] = 0
}'

def lna_getcounts '{
    global LNA_PAR[]

    local val npar pars[]

    val  = isgdevice_comm(LNA_PAR["address"], "?RMEAS")
    npar = split(val, pars)

    if (npar == 2) {
        S[cnt_num(LNA_PAR["mnelo"])] = pars[0] + 0.
        S[cnt_num(LNA_PAR["mnehi"])] = pars[1] + 0.
        lna_checklevel(S[lnalo])
    }
    else {
        S[cnt_num(LNA_PAR["mnelo"])] = 0.
        S[cnt_num(LNA_PAR["mnehi"])] = 0.
        print "ERROR: cannot read lna"
    }
}'

def lna_mailon '{
    global LNA_PAR[]
    
    LNA_PAR["mail"]["on"]   = 1
    LNA_PAR["mail"]["last"] = 0
}'

def lna_mailoff '{
    global LNA_PAR[]

    LNA_PAR["mail"]["on"] = 0
}'

def lna_checklevel(value) '{
    global LNA_PAR[]

    if (LNA_PAR["mail"]["on"]) {
        if (value > 1.29) {
            if ((time() - LNA_PAR["mail"]["last"]) > 2000.) {
                u echo "13elt detector is being filled" | mailx -s "13elt_Refill" isa@terre-adelie.org, bleuet@esrf.fr
                LNA_PAR["mail"]["last"] = time()
            }
     	}
    }
}'

#%MACROS%
#%IMACROS%
#%TOC% 
#%AUTHOR% E.Papillon,C.Guilloud, BLISS group