#%TITLE% cpseudo.mac
#%NAME%
# A macros set to help in defining pseudo counters
#
#%CATEGORY% Tools
#
#%DESCRIPTION%
# You should consider using the spec feature for implementing macro counters
# For more info check the spec help pages on
# %LINK%http://www.certif.com/spec_help/mac_hdw.html macro hardware%LINK%
# or type %B%help mac_hdw%B% in spec.
#%BR%
# Pseudo counters are a common used feature to implement counters in spec
# which do not have actual hardware connected (like calculations) or
# which are not directly supported in spec.
#%BR%
#
#%EXAMPLE%
#
#%DL%
#%DT% cpseudodef cnttim1 none cnt_move piezo_getangles none none none none 3 0
#%DD%
# Define a pseudo motor piezo1. Each time the user tries to move the
# piezo piezo_move is called. If the user wants to know the position
# of the piezo piezo_getangles is called. No action is taken on set
# ^c. The user parameters were 3 0 and could represent the channel
# on the corresponding DAC card.
#%XDL%
#
#%END%
#%UU% <counter_mne> <precount> <postcount> <getcounts> <cleanup> <config> <userdata1> <userdata2>
#%MDESC%
# This macro defines a new pseudo-counter. The counter has to be
# configured and the controller set to NONE. Whenever a count_em
# macro is used (all the time spec wants to start a counter/timer)
# <precount> is called before starting the timer and <postcount>
# after.
# These macros will get three parameters. The first parameter will
# be the counter number, the second the string userdata1 and the third
# the string userdata2.
# Normally the <precount> or <postcount> macro will start your timer.
# In <getcounts> you have to fill the S[] array with the counts read
# from the counter/timer. S[sec := 0] should be the time in seconds.
# The userdata can be used to give some information to the
# macro (for example the device server name).
# The <cleanup> macro will be called if the user hits ^c or some
# error condition occures (A limit is hit for example). The <config>
# macro will be called after the user called config.
# If you do not want to wait in your macros until counting has
# finished (and in this allow updated count commands), you can
# increment the USER_COUNTERSRUN global variable. While waiting
# your <pollcounts> macro will be called. Inside you can decrement
# USER_COUNTERSRUN as soon as you finished counting.
# Special care has to be taken if the user hits ^c.
def cpseudodef '
{
#defines pseudocounter
#cpseudodef countername precount postcount getcounts cleanup config user1 user2
global __p0 __p1 __p2 __p3 __p4 __p5 __p6 __p7 __p8 __p9 __p10 __p11
__p1="$1"; __p2="$2"; __p3="$3"; __p4="$4"; __p5="$5"; __p6="$6"; __p7="$7"
__p8="$8"; __p9="$9"; __p10="$10" ; __p11="$11"; __p0=$1
_cpseudodef
}
'
#%UU% <var-name>
#%MDESC%
# same as cpseudodef , the input parameter is just a variable name
def cpseudosdef '
{
#defines pseudocounter
#cpseudosdef stringvariable
global __p0 __p1 __p2 __p3 __p4 __p5 __p6 __p7 __p8 __p9 __p10 __p11
{
local xx i
split ($1,xx)
__p1=xx[0]; __p2=xx[1]; __p3=xx[2]; __p4=xx[3]; __p5=xx[4]; __p6=xx[5];
__p7=xx[6]; __p8=xx[7]; __p9=xx[8]; __p10=xx[9]; __p11=xx[10]
for (i=0,__p0=0;i<COUNTERS;i++) {
if (cnt_mne(i) == __p1) {
__p0=i
}
}
}
_cpseudodef
}
'
def _cpseudodef '
{
global __p0 __p1 __p2 __p3 __p4 __p5 __p6 __p7 __p8 __p9 __p10 __p11
local flag
flag = 0
if (substr(__p1,1,1)=="_") {
flag = 0 #If a counter name starts with underscore then def in any case
}
else {
flag = 2
}
pseudo_hook "user_prepcount" __p2 __p1 flag __p7 __p8
pseudo_hook "user_postcount" __p3 __p1 flag __p7 __p8
pseudo_hook "user_getcounts" __p4 __p1 flag __p7 __p8
pseudo_hook "user_c_cleanup" __p5 __p1 flag __p7 __p8
pseudo_hook "user_config1" __p6 __p1 flag __p7 __p8
}
'
def pseudo_hook '
{
local rstring
if (($2 != "") && ($2 != "none") && ($2 != "NONE")) {
rstring = sprintf ("%s %s %s %s; ",$2,$3,$5,$6)
cdef("$1",rstring,$3,$4)
}
}
'
#%UU% [countermne]
#%MDESC%
# A pseudomotor/counter can be deleted with this macro
def cpseudodel 'pseudodel $* ; '
def cpseudosdel 'pseudosdel $* ; '
def cpseudoshow 'pseudoshow $* ; '
#%MACROS%
#%IMACROS%
#%ATTENTION%
# %UL%
# %LI% Hitting ^c (so ^c twice) while the cleanup macro is running will undefine
# the cleanup macro (This will not erase your macro, it will just not be
# executed). Next time a counter/timer is started it is redefined again.
# %LI% There are side effects in defining a pseudo counter inside
# curly brackets - be careful.
# %XUL%
#%DEPENDENCIES%
# The file cpseudo.mac has to be loaded. ! This is done in startup
# (This file needs stchanges.mac)
#%AUTHOR%
# CPSEUDO.MAC JK 6.94
#%TOC%
|