#%TITLE% specclient.mac
#%NAME%
#
#%CATEGORY%
#%DESCRIPTION%
#
#%EXAMPLE%
#%DL%
#%DT%XXXsetup%DD%
#%SETUP%
#%UL%
#%LI%
#%XUL%
######################################################################
##################### #####################
##################### check remote connections #####################
##################### #####################
######################################################################
#%UU% ()
#%MDESC%
# Returns 1 if current SPEC session is busy.
def specclient_willblock() '{
# wait :
# 0 - moving, counting and other acquisition
# 1 - (bit 0) moving
# 2 - (bit 1) counting (by the master timer)
# 4 - (bit 2) other acquisition (MCAs, CCDs, etc.)
# 8 - (bit 3) remote connections and remote asynchronous events
# 32 - (bit 5) return zero or nonzero to indicate if busy
# 8 - (bit 3) remote connections and remote asynchronous events
# 32 - (bit 5) return zero or nonzero to indicate if busy
return wait(0x28)
}'
#%IU% (<timeout>)
#%MDESC%
#
# <timeout> :
def specclient_wait(timeout) '{
local t0
global SPECCLIENT_SLEEP
SPECCLIENT_SLEEP = SPECCLIENT_SLEEP ? SPECCLIENT_SLEEP : 0.01
t0 = time()
while (specclient_willblock()) {
if ((timeout < 0) || ((timeout > 0) && ((time() - t0) > timeout))){
break
}
sleep(SPECCLIENT_SLEEP)
}
return(specclient_willblock())
}'
#%IU% (<servname>, <timeout>)
#%MDESC%
#
# <servname> : spec session name
# <timeout> : timeout
#
def specclient_prompt(servname, timeout) '{
local _os _str tmparr[] _t0
_t0 = time()
if (specclient_wait(0.2)) {
_os = (split(servname, tmparr) == 1)
printf("\nSpec server%s %s not available.\n", _os ? "" : "s", servname)
printf("Please start %s or press \"C\" to abort connection ", \
_os ? "it" : "them")
while (specclient_wait(0.2)) {
printf(".")
if ((timeout > 0) && ((time() - _t0) > timeout)) {
printf("\nConnection to %s timed out\n", servname)
return(-1)
}
_str = input(-1)
if ((_str == "C") || (_str == "c")) {
printf("\nConnection to %s aborted\n", servname)
return(-2)
}
}
}
printf("\nConnected to %s.\n", servname)
return(0)
}'
|