#%TITLE% REGLO.MAC
#
#%NAME%
# Macros to control REGLO Digital TUBING PUMP
#
#%OVERVIEW%
# This macro set allows to control the REGLO tubing pump in
# \"Pump flow rate\" mode only.
# %BR%
# Only one pump can be driven at a time.
#
#%EXAMPLE%
# %DL%
# %DT%reglosetup 0 4
# %DD%Configures a reglo pump unit connected to the spec serial line #0
# and having an address #4 (to be set on the controller)
# %DT%reglostart + 0.2
# %DD%Start the pump in clockwise direction with a flow rate of 0.2 ml/min.
# %DT%reglostop
# %DD%Stop the pump
# %XDL%
#
#%END%
#%UU% <serline> <address>
#%MDESC%
# Configure the REGLO pump unit connected to <serline> with address <address>
# %BR%
# The serial line has to be configured as %B%raw%B%, %B%9600%B% baud.
# %BR%
# The address has to be set on the controller. Turn the unit off, press settings
# button while powering on. Go to \"addr\", and set/read desired address.
# %BR%
# On setup, the pump is set to \"PUMP FLOW RATE\" mode, and direction set \"clockwise\"
#
def reglosetup '{
global REGLO_PAR[]
if ($#!=2) {
print "Usage: $0 <serline> <addr>"
exit
}
REGLO_PAR["sdev"]= int($1)
REGLO_PAR["addr"]= int($2)
if ((desc= _reglo_io("#"))==-1) {
printf("REGLO ERROR> Failed to address pump unit\n")
} else {
printf("Using %s\n", desc)
if (_reglo_command("M")!=0) {
printf("REGLO ERROR> Failed to set pump flow rate mode\n")
}
reglodirection +
}
}'
#%UU% [<direction>] [<flowrate>]
#%MDESC%
# Start the pump.
# %BR%
# if %B%direction%B% is specified by %B%+%B% or %B%-%B%, set it before starting.
# %BR%
# if %B%flowrate%B% is also specified (in ml/min), set it before starting.
#
def reglostart '{
if ($#>=1) {
reglodirection $1
}
if ($#>=2) {
reglorate $2
}
if (_reglo_command("H")!=0) {
printf("REGLO ERROR> Failed to start pump\n")
} else {
printf("REGLO> Started.\n")
}
}'
#%UU%
#%MDESC%
# Stop the pump
#
def reglostop '{
if (_reglo_command("I")!=0) {
printf("REGLO ERROR> Failed to stop pump\n")
} else {
printf("REGLO> Stopped.\n")
}
}'
#%UU%
#%MDESC%
# Print out current status (running state, flow rate, direction)
def reglostatus '{
local status dir str
status= _reglo_command("E")
if (status==1) str="Running"
else if (status==-1) str="Idle"
else str="ERROR"
printf("REGLO> State is \"%s\"\n", str)
reglorate
if (REGLO_PAR["dir"]==-1)
dir="Counter-clockwise"
else if (REGLO_PAR["dir"]==1)
dir="Clockwise"
else dir= "Unknown"
printf("REGLO> Direction is %s\n", dir)
}'
#%UU% <+ or ->
#%MDESC%
# Set pump direction:
# %BR%
# %B%+%B% : clockwise direction
# %BR%
# %B%-%B% : counter-clockwise direction
#
def reglodirection '{
local dir
if ($#!=1) {
print "Usage: $0 <+|->\n\t(+=clockwise, -=counter-clockwise)"
exit
}
dir= "$1"
if (dir=="+") {
if (_reglo_command("J")!=0) {
printf("REGLO ERROR> Failed to set + direction")
}
REGLO_PAR["dir"]= 1
} else if (dir=="-") {
if (_reglo_command("K")!=0) {
printf("REGLO ERROR> Failed to set - direction")
}
REGLO_PAR["dir"]= -1
} else {
printf("REGLO ERROR> Wrong input direction: + or - only")
}
}'
#%UU%
#%MDESC%
# Set flow rate in ml/min if %B%rate%B% is specified, or print out
# current flow rate.
#
def reglorate '{
local flow sign vale cmd
if ($#==1) {
ret= _reglo_setrate($1+0.)
} else {
ret= _reglo_io("f")
}
if (ret==-1) {
printf("REGLO ERROR> Failed to set flow rate\n")
} else {
if (sscanf(ret, "%g", flow)==1)
printf("REGLO> Flow rate is %g ml/min.\n", flow)
else
printf("REGLO ERROR> Cannot parse flow rate in <%s>\n", ret)
}
}'
#%IU%
def _reglo_setrate(flow) '{
local valm sign vale cmd vmax
valm= flow
sign= "+"
vale= 0
vmax= _reglo_getmaxrate()
if (flow>vmax) {
printf("REGLO WARNING> Maximum flow rate is %g\n", vmax)
valm= flow
}
if (valm>9999.) {
for (vale=0; (valm>9999.)&&(vale<9); vale++) {
valm/=10.
}
if (valm>9999.) {
printf("REGLO ERROR> Flow rate too high\n")
}
sign= "+"
}
if (valm<1000.) {
for (vale=0; (valm<1000)&&(vale<9); vale++) {
valm*=10.
}
if (int(valm)==0) {
printf("REGLO ERROR> Flow rate too low\n")
}
sign= "-"
}
cmd= sprintf("f%04d%1.1s%1d", int(valm), sign, vale)
return _reglo_io(cmd)
}'
#%IU%
def _reglo_getmaxrate() '{
ret= _reglo_io("\!")
if (ret!=-1) {
if (sscanf(ret, "%g", val)==1)
return val
}
return ret
}'
#%IU%
def _reglo_io(par) '{
local ret
_reglo_serput(par)
ret= ser_get(REGLO_PAR["sdev"], "\r\n")
if (ret!="") {
return substr(ret, 1, length(ret)-2)
}
return (-1)
}'
#%IU%
def _reglo_serput(cmd) '{
local scmd
ser_par(REGLO_PAR["sdev"], "flush")
scmd= sprintf("%d%s\r", REGLO_PAR["addr"], cmd)
return ser_put(REGLO_PAR["sdev"], scmd)
}'
#%IU%
def _reglo_command(cmd) '{
_reglo_serput(cmd)
ret= ser_get(REGLO_PAR["sdev"], 1)
if (ret=="-")
return (-1)
else if (ret=="*")
return (0)
else if (ret=="+")
return (1)
return (-2)
}'
#%MACROS%
#%AUTHOR% EP, BLISS
# $Revision: 1.1 $ / $Date: 2008/12/17 10:28:50 $
#%TOC%
|