#%TITLE% CC133.MAC
#
#%NAME%
# Macros for defining encoders as pseudocounters.
#
#%CATEGORY% Positioning
#
#%OVERVIEW%
# This macroset allow to define encoders conected to CC133 boards as
# pseudocounters. Each time the counters are read, the pseudocounters are
# loaded with the current values of the associated encoders. The values of
# the encoders may also be multiplied by scale factors.%BR%
# The definition of a pseudocounter is done by the macro %B%cc133setup%B% that
# has to be executed once per encoder. There is no limit in the number of
# encoders that can be defined by this way.%BR%%BR%
# The encoders must be accessible through their own device server (not MAXE).
#
#%EXAMPLE%
#
# %DL%
# %DT%cc133setup enc0 id47/cc133a/1 2.5
# %DD%Associates the pseudocounter `enc0' to the encoder `id47/cc133a/1' and
# sets the scale factor to 2.5.
# %DT%setc133 enc0 5
# %DD%Changes the encoder position to 5.
# %DT%cc133show
# %DD%Displays the current configuration.
# %XDL%
#
#%LOG%
# $Revision: 3.1 $ / $Date: 2008/02/27 12:51:41 $
#
# $Log: cc133.mac,v $
# Revision 3.1 2008/02/27 12:51:41 rey
# documentation changes
#
#
#%END%
#%UU% <pseudo_counter> <device_name> [<scale_factor>]
#%MDESC%
# Associates the encoder <device_name> to <pseudo_counter>. If scale factor
# is not explicitly specified, unity is assumed.
#
def cc133setup '{
global INTERFDEVICE
if ($# != 2 && $# != 3 || $# == 3 && $3 == 0) {
if (SETUP) print "Error in line: $0 $*"
print "Usage: $0 pseudocounter device [scale_factor]"
} else {
global CC133
local key
list_test CC133
key = "$1"
list_add(CC133, key)
list_setpar(CC133, key, "device", "$2")
list_setpar(CC133, key, "scalefact", ($# == 3)?$3:1)
cdef("user_getcounts","cc133_getcounts $*\n",key,0x02)
setup_tail("cc133", key)
}
}'
#%IU% <pseudo_counter>
#%MDESC%
# Removes the definition of a encoder as pseudocounter.
#
def cc133unsetup '{
local key
key = "$1"
cdef("user_getcounts", "", key ,"delete")
list_remove(CC133, key)
if (!CC133[0]) unglobal CC133
}'
#%IU% <pseudo_counter> <device_name> [<scale_factor>]
#%MDESC%
# Reads the current encoder position and stores it in the corresponding
# global variable.
#
def cc133_getcounts '
S[$1] = esrf_io("$2","DevReadCount") * (($# == 3)?$3:1)
'
#%UU% [<pseudo_counter> [<new_value>]]
#%MDESC%
# Sets the position of the encoder associated to <pseudo_counter> to
# <new_value>. If no parameters are specified, the macros prompt for them.
#
def setcc133 '{
local enc newvalue
if ($# > 2) {
print "Usage: $0 [encoder_name [value]]"
exit
}
if ($# == 0)
enc = getval("Input encoder name", "")
else
enc = "$1"
if (list_check(CC133, enc) <= 0) {
printf("`%s\' is not a currently defined encoder.\n", enc)
cc133show
exit
}
devicename = list_getpar(CC133, enc, "device")
scalefact = list_getpar(CC133, enc, "scalefact")
value = esrf_io(devicename,"DevReadCount") * scalefact
if (ESRF_ERR) {
printf("Can\'t read device `%s\' associated to `%s\'.\n", devicename, enc)
exit
}
if ($# < 2)
value = getval("Input new value", value)
else
value = "$2"
esrf_io(devicename, "DevWriteCount", value / scalefact)
}'
#%UU%
#%MDESC%
# Lists the pseudocounters currently defined along with the associated device
# names and scale factors.%BR%
# If a counter name is associated to an encoder by %B%cc133setup%B% but the
# counter is not included in the configuration of %B%spec%B%, the
# corresponding line is marked as disabled.
#
def cc133show '{
local n i enc
if (n = list_n(CC133) <= 0) {
print "No encoders configured currently as pseudocounters."
} else {
for (i = 1; i <= n; i++){
enc = list_item(CC133,i)
printf("%8s: %20s x %10g %s\n", enc, list_getpar(CC133,i,"device"), \
list_getpar(CC133,i,"scalefact"), cnt_num(enc)>=0?"":"(disabled)")
}
}
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% P.Fajardo, (Original 8/96).
#%TOC%
|