#$Log: xbpmOxCy.mac,v $
#Revision 1.1 2006/04/20 15:28:23 beteva
#Initial revision
#
#%TITLE% xbpmOxCy.mac
#%NAME% %B%xbpmOxCy.mac%B%
#%DESCRIPTION% Set of macros to control and read the XBPM, using the
#Cyberstart/Oxford control unit (ICPLUS). The %B%RS232%B% serial interface
#allows remote reading and programming of the controller. The serial line
#parameters are:%BR%
# - 8 bits;%BR%
# - no parity;%BR%
# - 1 stop bit;%BR%
# - 19200 bauds.
#%SETUP% The serial line cable is connected to a RocketPort serial line
#interface. A serial line device server, on top of which a linux device server
#XbpmOxCy should run. The macro calles the XbpmOxCy device server commands
#only. The serial line %B%should%B%%B%not%B% be configured in SPEC!
#%END%
#%UU% [dev root raw]
#%MDESC%Setup the reading of the device %B%dev%B% in %B%root%B% counters
#mnemonic and %B%raw%B% counts reading (raw=1) or not (raw=0). There shoud be
#at least two counters defined in the spec - cx and cy (where c is the root
#mnemonic), for the X and Y position of the beam. If reading of the raw counts
#is chosen, than 5 more counters (c1, c2, c3, c4 and csum) shoud be configured.
def oxbpm_setup '{
global OXBPM_PROPS OXBPM_NB OXBPM_OK
local i j inp mnem
OXBPM_OK = 0
if ($# == 0) {
OXBPM_NB = getval("How many devices do you want to configure?:", OXBPM_NB)
for (i=0; i<OXBPM_NB; i++) {
OXBPM_PROPS[i]["dev"] = \
getval("Controller device name (e.g. id29/oxbpm/1):",\
OXBPM_PROPS[i]["dev"])
OXBPM_PROPS[i]["root"] = getval("BPM root name:", OXBPM_PROPS[i]["root"])
OXBPM_PROPS[i]["raw"] = yesno("Do you want to read the raw counts",1)
}
} else {
OXBPM_NB = split("$*",inp)/3
unglobal OXBPM_PROPS
global OXBPM_PROPS
for (i=0; i<OXBPM_NB; i++) {
OXBPM_PROPS[i]["dev"] = inp[3*i]
OXBPM_PROPS[i]["root"] = inp[3*i+1]
OXBPM_PROPS[i]["raw"] = inp[3*i+2]
}
}
for (i=0; i<OXBPM_NB; i++) {
esrf_io(OXBPM_PROPS[i]["dev"],"timeout",10)
mnem[i][0] = sprintf("%sx",OXBPM_PROPS[i]["root"])
mnem[i][1] = sprintf("%sy",OXBPM_PROPS[i]["root"])
if ((OXBPM_PROPS[i]["cx"] = cnt_num(mnem[i][0])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][0])
if ((OXBPM_PROPS[i]["cy"] = cnt_num(mnem[i][1])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][1])
if (OXBPM_PROPS[i]["raw"] == 1) {
for (j=1; j<5; j++)
mnem[i][j+1] = sprintf("%s%d",OXBPM_PROPS[i]["root"],j)
if ((OXBPM_PROPS[i]["c1"] = cnt_num(mnem[i][2])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][2])
if ((OXBPM_PROPS[i]["c2"] = cnt_num(mnem[i][3])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][3])
if ((OXBPM_PROPS[i]["c3"] = cnt_num(mnem[i][4])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][4])
if ((OXBPM_PROPS[i]["c4"] = cnt_num(mnem[i][5])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][5])
mnem[i][6] = sprintf("%ssum",OXBPM_PROPS[i]["root"])
if ((OXBPM_PROPS[i]["csum"] = cnt_num(mnem[i][6])) == -1)
eprintf ("Counter %s not configures, setup failed\n", mnem[i][6])
}
}
}'
#%UU% [nb]
#%MDESC% Add the reading of the %B%nb%B% XBPM (nb starts from 0) in
#the user_getcounts, according to the raw counts read or not. If no input
#parameter, all the configures XBPMs will be added.
def oxbpm_on '{
local i
if ($# == 0) {
for (i=0; i<OXBPM_NB; i++) {
if (OXBPM_PROPS[i]["raw"] == 1)
cdef ("user_getcounts",sprintf("oxbpm_getcnt(%d);",i), OXBPM_PROPS[i]["root"])
else
cdef ("user_getcounts",sprintf("oxbpm_getcounts(%d);",i), OXBPM_PROPS[i]["root"])
}
} else {
i = $1
if (OXBPM_PROPS[i]["raw"] == 1)
cdef ("user_getcounts",sprintf("oxbpm_getcnt(%d);",i), OXBPM_PROPS[i]["root"])
else
cdef ("user_getcounts",sprintf("oxbpm_getcounts(%d);",i), OXBPM_PROPS[i]["root"])
}
}'
#%UU% [nb]
#%MDESC% Remove the reading of the %B%nb%B% XBPM (nb starts from 0)
#from the user_getcounts. If no input parameter, all the configures XBPMs
#will be removed.
def oxbpm_off '{
local i
if ($# == 0) {
for (i=0; i<OXBPM_NB; i++)
cdef ("","", OXBPM_PROPS[i]["root"],"delete")
} else {
i = $1
cdef ("","", OXBPM_PROPS[i]["root"],"delete")
}
}'
#%UU% (nb)
#%MDESC% Read the raw counts and the X and Y for the XBPM %B%nb%B% (nb
#starting from 0).
#X and Y are calculated as (i1-i2)/(i1+i2); (i3-i4)/(i3+i4) or
#(i1+i2-i3-i4)/(i1+i2+i3+i4); (i1-i2-i3+i4)/(i1+i2+i3+i4), depending on the
#device server setup, which reflects the cabling.
def oxbpm_getcnt(nb) '{
local double array valsr[5] vals[8]
local res
res = esrf_io(OXBPM_PROPS[nb]["dev"], "DevXbpmReadRaw",valsr)
res = esrf_io(OXBPM_PROPS[nb]["dev"], "DevXbpmReadAll",vals)
if (res == -1) {
S[OXBPM_PROPS[nb]["c1"]] = 0
S[OXBPM_PROPS[nb]["c2"]] = 0
S[OXBPM_PROPS[nb]["c3"]] = 0
S[OXBPM_PROPS[nb]["c4"]] = 0
S[OXBPM_PROPS[nb]["cx"]] = 0
S[OXBPM_PROPS[nb]["cy"]] = 0
S[OXBPM_PROPS[nb]["csum"]] = 0
} else {
S[OXBPM_PROPS[nb]["c1"]] = valsr[0]
S[OXBPM_PROPS[nb]["c2"]] = valsr[1]
S[OXBPM_PROPS[nb]["c3"]] = valsr[2]
S[OXBPM_PROPS[nb]["c4"]] = valsr[3]
S[OXBPM_PROPS[nb]["cx"]] = vals[4]
S[OXBPM_PROPS[nb]["cy"]] = vals[5]
S[OXBPM_PROPS[nb]["csum"]] = valsr[4]
}
}'
#%UU% (nb)
#%MDESC% Read the X and Y for the XBPM %B%nb%B% (nb starting from 0).
#X and Y are calculated as (i1-i2)/(i1+i2); (i3-i4)/(i3+i4) or
#(i1+i2-i3-i4)/(i1+i2+i3+i4); (i1-i2-i3+i4)/(i1+i2+i3+i4), depending on the
#device server setup, which reflects the cabling.
def oxbpm_getcounts(nb) '{
local double array vals[8]
local res
res = esrf_io(OXBPM_PROPS[nb]["dev"], "DevXbpmReadAll",vals)
if (res == -1) {
S[OXBPM_PROPS[nb]["cx"]] = 0
S[OXBPM_PROPS[nb]["cy"]] = 0
return(-1)
} else {
S[OXBPM_PROPS[nb]["cx"]] = vals[4]
S[OXBPM_PROPS[nb]["cy"]] = vals[5]
}
}'
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% A.Beteva/BLISS%BR%
#$Revision: 1.1 $ $Date: 2006/04/20 15:28:23 $
|