#%TITLE% ATT_RELAY.MAC
#%NAME%
# handle the relay driven attenuator box
#%CATEGORY% other hardware
#%LOG%
#$Log: att_relay.mac,v $
#Revision 1.3 2007/06/25 15:24:37 rey
#just documentation
#
#Revision 1.2 2002/04/08 16:07:53 beteva
#added mattsetmax function (AB)
#
#Revision 1.1 2002/03/20 17:10:12 beteva
#Initial revision
#
#%DESCRIPTION%
# Aset of rellays allows the remote control of the attenuators.
#%SETUP% The Relay OS-9 device server, using the digital I/O card (ivc196)
#in the VME crate controls OUTPUT relays.
#The attenuator value/blades_in table follows:
#
#%END%
#%UU% <nb_attn> <device_root> <firstin> <firstout>
#%MDESC% set up attenuator box for %B%nb_att%B% attenuators, controlled by
#relay devices with root name %B%device_root%B%. The %B%firstin%B% is the
#firs reading the state channel, while the %B%firstout%B% is the first
#control channel.
def mattsetup '
{
global ATT_FIRSTIN ATT_FIRSTOUT ATT_ROOT ATT_STATE ATT_OLD_STATE ATT_NUMBER
if ($# != 4) {
ATT_NUMBER = getval("Number of channels: ", ATT_NUMBER)
ATT_ROOT = getval("Device root name (e.g. id29/id292_1): ", ATT_ROOT)
ATT_FIRSTIN = getval("First read channel: ", ATT_FIRSTIN)
ATT_FIRSTOUT = getval("First control channel: ", ATT_FIRSTOUT)
} else {
ATT_NUMBER=$1
ATT_ROOT="$2"
ATT_FIRSTIN=$3
ATT_FIRSTOUT=$4
}
}'
def mattset0() '{
ATT_OLD_STATE = _matt_get()
mattset 0
}'
def mattreset() '{
mattset ATT_OLD_STATE
}'
def mattsetmax() '{
ATT_OLD_STATE = _matt_get()
mattset 224
}'
#%IU% ()
#%MDESC% read attenuator status
def _matt_get() '{
for (i=0,ATT_STATE=0;i<ATT_NUMBER;i++) {
ATT_STATE += ((esrf_io(sprintf("%s/%d",ATT_ROOT,ATT_FIRSTIN+i), \
"DevReadValue") == 4)?0:1)<<i
}
return(ATT_STATE)
}'
#%IU% (value)
#%MDESC%
# set attenuator to <value>
def _matt_put(value) '{
global ATT_ROOT ATT_FIRSTOUT ATT_NUMBER
local i
for (i=0;i<ATT_NUMBER;i++) {
esrf_io(sprintf("%s/%d",ATT_ROOT,ATT_FIRSTOUT+i),\
value&(1<<i)?"DevClose":"DevOpen")
}
}'
#%UU% <value>
#%MDESC% set attenuator, where %B%value%B% is a hexadecimal representation
#of the desires blades in. Insert needed blades first, then retract the
#unwanted ones to avoid exposure of detector while moving. Verify the
#result of the operation and print new attenuator status.
def mattset '{
local newvalue oldvalue getvalue notset
notset = 1
if ($# != 1) {
print "Usage: mattset value"
exit
}
newvalue = ($1)
oldvalue = _matt_get()
for(j=0;j<ATT_NUMBER+1;j++) {
if((~newvalue & oldvalue) && (newvalue & ~oldvalue)) {
_matt_put(newvalue | oldvalue)
sleep(0.25)
}
_matt_put(newvalue)
sleep(0.25)
getvalue = _matt_get()
printf("Set: %2d Got: %2d\n",newvalue,getvalue)
if (getvalue == newvalue) {
notset=0;
break
}
}
if (notset) printf("It appears the attenuators could not be set.\n")
}'
#%UU%
#%MDESC% Read attenuator status and print to screen.
# If an argument is given, the macro repeats until interupted by ^C.
def mattstatus '
{
global ATT_NUMBER
local i value
printf(" #")
for (i=1;i<=ATT_NUMBER; i++) {
printf(" F%d",i)
}
printf("\n")
for(;;) {
value = _matt_get()
printf ("%2d ", value)
for (i=0;i<ATT_NUMBER;i++) {
printf ("%s ",(value&(1<<i))?"IN ":"OUT")
}
if($# == 0) {
printf("\n");
break
} else {
printf ("\r");
}
}
}'
#%UU%
#%MDESC% read/set attenuators
def att '{
if($# != 0) {
att_set $*
}
mattstatus
}'
#%UU% <value>
#%MDESC%
# just a common typo...
def att_Set 'att_set $*'
#
#%UU% <forever>
#%MDESC%
# ...and another one...
def att_State 'mattstatus $*'
#
#%UU% <number of repetitions>
#%MDESC%
# test the attenuators - puts them in and out and leaves them
# in their original state.
#%TOC%
def matt_test '{
local ii
current_value = _matt_get()
for (ii=0;ii<$1;ii++) {
_matt_put(255)
sleep(1)
}
_matt_put(current_value)
}'
#%UU% (args)
#%MDESC% Set the table with sequence of attenuation values.
def matt_table_setup(args) '{
global MATT_TABLE NR_MATT
local auxlist i
list_init auxlist
NR_MATT = list_splitadd(auxlist,args)
for (i=1; i <= NR_MATT; i++) {
MATT_TABLE[i-1] = auxlist[i]
}
}'
#%MACROS%
#%AUTHOR% J.Klora, A.Beteva
#%TOC%
#$Revision: 1.3 $,$Date: 2007/06/25 15:24:37 $
|