#%TITLE% cnttim.mac
#%NAME%
# Macros to work with Lecroy 1151 and CAEN gategen device
# server as counters in spec. OBSOLETE
#
#%CATEGORY% Counting, Obsolete
#
#%DESCRIPTION%
# Lecroy 1151 and CAEN gategenerator combination as pseudocounters
#
# Not intented for direct use by the user
# If everything is installed properly the user has to configure a
# counter with the name cnttim<channel number> (example cnttim3)
# and the Lecroy will be used for this counter
#
#
# cnttimsetup [gategen_device] [gategen_number 1 or 2]
# [counter_device] [max_number of counters]
# Internals:
# New version which allows also uct and updated scans
# ^c is catched and the counter and gategen stopped
#
# JK 2.94
#
#%END%
def cnttim_init '
'
def cnttimsetup '
global COUNTER_NO COUNTER_MAXNO
if ($#==4) {
gatesetup $1 $2
cntsetup $3 $4
}
else {
gatesetup
cntsetup
}
cnttim_init
'
# Counter functions
#
def cntsetup '
global COUNTERDEV COUNTER_MAXNO COUNT_S
if ($#) {
COUNTERDEV="$1"
} else {
COUNTERDEV=getval("How is your counter device called",COUNTERDEV)
}
if ($#>1) {
COUNTER_MAXNO="$2"
} else {
COUNTER_MAXNO=getval("Maximal number of Counters",COUNTER_MAXNO)
}
for (i=0;i<COUNTER_MAXNO;i++) {
local ppstring
esrf_io(sprintf("%s/%1d",COUNTERDEV,i+1),"DevCntClearChannel")
ppstring = sprintf("cnttim%d cnt_precount none cnt_getcounts cnt_cleanup none %d",i+1,i+1)
cpseudosdef ppstring
}
'
def cnt_getcounts '
cntread $2
S[$1]=COUNT_S
if (!GATERUNS) COUNTERRUNS[$2]=0
'
def cnt_cleanup '
global COUNTERRUNS GATERUNS
if (COUNTERRUNS[$2]) {
printf ("Resetting the counter %s\n","$1")
cntreset $2
COUNTERRUNS[$2]=0
}
'
def cnt_precount '
global COUNTERRUNS
COUNTERRUNS[$2]=1
esrf_io(sprintf("%s/%1d",COUNTERDEV,$2),"DevCntClearChannel")
'
def cntread '
if ($#) {
COUNTER_NO=$1
}
COUNT_S=esrf_io(sprintf("%s/%1d",COUNTERDEV,COUNTER_NO),"DevCntReadChannel",0)
'
def cntreset '
esrf_io(sprintf("%s/%1d",COUNTERDEV,$1),"DevCntReset")
'
# ---------------------------------------------------------
# Gategenerator functions
def gate_postcount '
#$1
global GATERUNS GATESTARTTIME
gatepreset COUNT_TIME
gatestart
GATESTARTTIME=time()
if (!GATERUNS) {
USER_COUNTERSRUN ++ ; GATERUNS=1
}
'
def gate_getcounts '
global GATERUNS GATESTARTTIME
S[$1]=time()-GATESTARTTIME
if (!(esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenStatus")&1)) {
S[$1]=COUNT_TIME
if (GATERUNS) {
USER_COUNTERSRUN -- ; GATERUNS=0
}
}
'
def gate_cleanup '
#$1
global GATERUNS GATESTARTTIME
if (GATERUNS) {
GATERUNS=0 ; USER_COUNTERSRUN--
printf ("Stopping the Gate Gen %s/%1d, please wait ...\n",GATEDEV,GATE_NO)
gatestop
gatewait
S[$1]=time()-GATESTARTTIME
}
'
def gatesetup '
global GATEDEV GATE_NO
if ($#) {
GATEDEV="$1"
} else {
GATEDEV=getval("How is your Gategen device called",GATEDEV)
}
if ($#) {
GATE_NO=$2+0
} else {
GATE_NO=getval("Use gategen 1 or 2 ",GATE_NO)
}
#cpseudodef countername precount postcount getcounts cleanup config user1 user2
cpseudodef sec "" "gate_postcount" "gate_getcounts" "gate_cleanup" "" "" ""
gateinvalpreset
GATERUNS=0 ; USER_COUNTERSRUN = 0
'
def gatewait '
sleep(COUNTERSPOLLTIME)
while (esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenStatus")&1) {
sleep(COUNTERSPOLLTIME)
}
'
def gatestart '
global GATE_NO
if ($#) {
GATE_NO=$1
}
esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenStartChannel")
'
def gatestop '
global GATE_NO
if ($#) {
GATE_NO=$1
}
esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenStopChannel")
gateinvalpreset
'
def gatepreset '
global GATE_NO GATE_PRESET GATE_OLDPRESET
if ($# == 2) {
GATE_NO=$2
}
if ($# > 0) {
GATE_PRESET=$1
}
if (GATE_OLDPRESET[GATE_NO] != GATE_PRESET) {
esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenPresetChannel",GATE_PRESET)
GATE_OLDPRESET[GATE_NO]=GATE_PRESET
}
'
def gateinvalpreset '
global GATE_OLDPRESET
GATE_OLDPRESET[0]=-1
GATE_OLDPRESET[1]=-1
'
def gatereset '
global GATE_NO
if ($#) {
GATE_NO=$1
}
esrf_io(sprintf("%s/%1d",GATEDEV,GATE_NO),"DevGategenReset")
gateinvalpreset
'
#%MACROS%
#%IMACROS%
#%TOC%
|