# THERE IS A DEVICE SERVER FOR THAT !!!!
#%TITLE% HYGROPALM
#
#%NAME%
# Pseudo counter on Rotronic HYGROPALM / Hygrometer via RS232
#
#%CATEGORY% other hardware
#
#%DESCRIPTION%
# Macros to read a HygroPalm hygrometer through a serial line.
# The macros allow the definition of a pseudo-counter in spec.
#%END%
#%UU% [ctmne devserver [type [address]]
#%MDESC%
# Setup parameters for hygropam operation
def hygro_setup '{
global HYGRO_PAR[]
# HYGRO_PAR["on"]
# HYGRO_PAR["mne"]
# HYGRO_PAR["serial_server"]
# HYGRO_PAR["type"]
# HYGRO_PAR["addr"]
# HYGRO_PAR["timeout"]
# HYGRO_PAR["setup_done"]
# HYGRO_PAR[""]
if ( $# < 4 ) {
print "Usage: hygro_setup ctmne serial_dev_server [type [address]] "
print "Where: "
print " ctmne = counter mnemonic "
print " serial_dev_server = serial line device server name "
print " type = 1/2/3 indicates HydroPalm 1/2 or 3"
print " address = if not given 99 is taken by default "
print "Config of the serial line :"
print " baudrate = 19200"
print " parity = even"
print " charlength = 7"
print " stopbits = 1"
print "--->exit"
exit
}
HYGRO_PAR["timeout"] = 1
HYGRO_PAR["mne"] = "$1"
HYGRO_PAR["serial_server"] = "$2"
if ( $# > 2 ) {
if ("$3" == 1) {
HYGRO_PAR["type"] = "0"
} else if ("$3" == 2) {
HYGRO_PAR["type"] = "u"
} else if ("$3" == 3) {
HYGRO_PAR["type"] = "U"
}
} else {
HYGRO_PAR["type"] = " "
}
if ( $# > 3 ) {
HYGRO_PAR["addr"] = "$4"
} else {
HYGRO_PAR["addr"] = "99"
}
cdef("user_getcounts",sprintf("hygro_getcounts %s\n", HYGRO_PAR["mne"]),HYGRO_PAR["mne"], 0x02)
HYGRO_PAR["setup_done"] = 1
hygro_on
}'
def hygro_unsetup '{
global HYGRO_PAR[]
cdef("user_getcounts", "", HYGRO_PAR["mne"], "delete")
hygro_off
HYGRO_PAR["setup_done"] = 0
}'
def hygro_on '{
global HYGRO_PAR[]
if(HYGRO_PAR["setup_done"]){
HYGRO_PAR["on"] = 1
counter_par(HYGRO_PAR["mne"], "disable", 0)
}
else{
print "--hygro--error : setup not done"
}
}'
def hygro_off '{
global HYGRO_PAR[]
HYGRO_PAR["on"] = 0
S[cnt_num(HYGRO_PAR["mne"])] = 0
counter_par(HYGRO_PAR["mne"], "disable", 1)
}'
def hygro_getcounts '{
global HYGRO_PAR[]
local ctmne ctnum answer
local hygval
ctmne = "$1"
ctnum = cnt_num(ctmne)
answer = hygro_read()
sscanf(answer, sprintf("{%s%sRDD %%f;",HYGRO_PAR["type"],HYGRO_PAR["addr"]), hygval)
S[ctnum] = hygval
}'
def hygro_read() '{
global HYGRO_PAR[]
local answer retans
local time0
cmd = sprintf("{%s%sRDD}\r", HYGRO_PAR["type"], HYGRO_PAR["addr"] )
while(1) {
answleft = esrf_io( HYGRO_PAR["serial_server"], "DevSerReadString", answer )
if (answleft == "") break
}
esrf_io( HYGRO_PAR["serial_server"], "DevSerWriteString", cmd)
time0 = time()
retans = ""
while (1) {
answer = esrf_io( HYGRO_PAR["serial_server"], "DevSerReadString", answer )
if (answer != "") {
retans = sprintf("%s%s", retans , answer)
if (index(answer,"\r") != 0) { # finished
break
}
}
if ((time() - time0) > HYGRO_PAR["timeout"]) {
print "Timeout reading Hygropalm"
break
}
sleep(0.01)
}
return retans
}'
#
#%AUTHOR% V.Rey // BLISS // Sept 2006
#
|