#%TITLE% WAGOCTAUX.MAC
#%NAME% %B%wagoctaux.mac%B% - Auxilary macros to change gains and calibrate
#wago counters.
#%DESCRIPTION%B% - The counters are read from a Wago ADC, using the WagoCt
#device server. They are configured in SPEC as VCT6 counters only, with factor
#of 1000. The gains (if any) are connected to WAGO relay modules and are
#controlled using the same WagoCt device servers.
#%END%
#%UU% [ctmne gain_factor scale_factor offset]
#%MDESC%
def wagoaux_setup '{
local inp[] nb_gf nb_s nb gf
global W_CTMNE W_GAINF W_SCALEF W_OFFSET W_CTDEV
if ($# == 0) {
ctmne = getval("Counter mnemonic (i.e. i0):", W_CTMNE[ctmne])
W_CTMNE[ctmne] = ctmne
nb_gf = yesno("Do you have different gain factors for each gain?:",0)
if (!nb_gf) {
W_GAINF[W_CTMNE[ctmne]][0] = getval ("Gain factor (i.e. 100):", \
W_GAINF[W_CTMNE[ctmne]][0])
gf = W_GAINF[W_CTMNE[ctmne]][0]
for (nb_gf = 0; nb_gf < 3; nb_gf++)
W_GAINF[W_CTMNE[ctmne]][nb_gf] = pow(gf,(nb_gf+1))
} else {
for (nb_gf = 0; nb_gf < 3; nb_gf++) {
W_GAINF[W_CTMNE[ctmne]][nb_gf] = \
getval ("Gain factor (i.e. 100):", W_GAINF[W_CTMNE[ctmne]][nb_gf])
}
}
nb_s = \
yesno("Do you have different scale factors for different energies?:",0)
if (!nb_s) {
W_SCALEF[W_CTMNE[ctmne]] = getval ("Scale factor:", W_SCALEF[W_CTMNE[ctmne]])
W_OFFSET[W_CTMNE[ctmne]] = getval ("Scale offset:", W_OFFSET[W_CTMNE[ctmne]])
} else {
#to be discussed
}
} else {
nb = split("$*", inp) - 1
ctmne = inp [0]
W_CTMNE[ctmne] = ctmne
nb_gf = inp[1]
if (nb_gf > 3) {
for (gf = 0; gf < 3; gf++)
W_GAINF[W_CTMNE[ctmne]][gf] = pow(nb_gf,(gf+1))
nb_gf = 1
} else {
for (nb_gf = 0; nb_gf < 3; nb_gf++) {
W_GAINF[W_CTMNE[ctmne]][nb_gf] = inp[nb_gf + 2]
}
}
if ((nb - nb_gf) == 2) {
W_SCALEF[W_CTMNE[ctmne]] = inp[nb_gf + 1]
W_OFFSET[W_CTMNE[ctmne]] = inp[nb_gf + 2]
} else {
#to be discussed
}
}
W_CTDEV[W_CTMNE[ctmne]] = counter_par(W_CTMNE[W_CTMNE[ctmne]],"device_id")
}'
#%UU% [ctmne gain]
#%MDESC% Set the %B%gain%B% (1-3) for a counter %B%ctmne%B% or show all
#gains if no parameter is given.
def wcgain '{
if ($# != 2 ) {
print "Usage: wcgain [ ctmne gain ]"
wcshowgain()
} else {
if ($2 < 1 || $2 > 3) {
eprint ("Values for wago gain must be 1, 2 or 3!\n")
} else if ("$1" in W_CTMNE) {
wcsetgain("$1", $2)
} else
eprint ("Unknown wago counter. Define it with \"wagoaux_setup\".\n")
}
}'
#%IU% (ctmne,gain)
#%MDESC% Set the %B%gain%B% value (1-3) for %B%ctmne%B% counter. Return
#0 if OK, -1 if error setting.
def wcsetgain(ctmne, gain) '{
if (gain < 1 || gain > 3)
return (-1)
return(esrf_io(W_CTDEV[ctmne], "DevSetChanGain", int(gain)))
}'
#%IU% (ctmne)
#%MDESC% Return the gain (1-3) for %B%ctmne%B% counter, -1 if error reading.
def wcreadgain(ctmne) '{
return(esrf_io(W_CTDEV[ctmne],"DevReadChanGain"))
}'
#%IU% (ctmne,ctval)
#%MDESC% Return the counter %B%ctmne%B% value %B%ctval%B% calculated
#as photons.
def wc_photon_scale(ctmne,ctval) '{
if (ctval != 0) {
gain = wcreadgain(ctmne)
gain_scale_factor = W_GAINF[ctmne][gain-1]
printf("Gain is %s, scale up by factor %d.\n",gain,gain_scale_factor)
ctval *= gain_scale_factor
scaled_value = ctval*W_SCALEF[ctmne] + W_OFFSET[ctmne]
} else {
scaled_value = 0
}
return(scaled_value)
}'
#%IU% ()
#%MDESC% show all current gain values.
def wcshowgain() '{
local ctmne
tty_cntl("md")
printf ("Current WAGO Gains:\n")
tty_cntl("me")
for (ctmne in W_CTMNE) {
printf("% 8s - %s\n", ctmne, wcreadgain(ctmne))
}
}'
#%IU% (ctmne,ctval)
#%MDESC% Set autogain mode (0=no autogain, 1=autogain) for the %B%ctmne%B%
#counter. Return gain mode if OK, -1 if error.
def setAutoGain(ctmne,ctval) '{
global W_GAINAUTO
local ret
if (ctval != 0 && ctval != 1) {
eprintf("Wrong mode value %g")
eprintf("allowed values are 0 (manual) or 1 (automatic) gain set\n")
return(-1)
}
ret = esrf_io(W_CTDEV[ctmne],"DevSetMode", ctval)
if (ret == -1)
return(-1)
W_GAINAUTO[ctmne] = ctval
return(ctval)
}'
#%IU% (ctmne)
#%MDESC% Get autogain mode (0=no autogain, 1=autogain, -1 if error)
#for the %B%ctmne%B% counter. With no ctmne, all the configured counters
#are read.
def getAutoGain(ctmne) '{
global W_GAINAUTO
local cntm
if (ctmne == 0) {
for (cntm in W_CTMNE) {
W_GAINAUTO[cntm] = esrf_io(W_CTDEV[cntm],"DevGetMode")
}
} else {
W_GAINAUTO[ctmne] = esrf_io(W_CTDEV[ctmne],"DevGetMode")
}
}'
#%IU% ()
#%MDESC%
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% A.Beteva
#$Revision: 1.2 $ $Date: 2013/08/19 12:07:00 $
#%END%
#%LOG%
#$Log: wagoctaux.mac,v $
#Revision 1.2 2013/08/19 12:07:00 beteva
#adedd set/get AutoGain
#
#Revision 1.1 2007/09/12 07:57:59 beteva
#Initial revision
|