#%TITLE% OT302.MAC
#%NAME%
# Macros to control the ON-TRAK (OT-302D) module
#
#%CATEGORY% Positioning, Detection, BPM
#
#%DESCRIPTION%
#The is the OT302 display module for the ON-TRAK position sensig amplifiers.
#The later provide an X-Y (normalised) position and SUM output from
#different position detectors.
#%SETUP%
# The serial line cable is connected to the serial line interface card
# COMU 2000 (COMU 30), known as IBAM. A "device server" called SerialLine
# should be running in the VME crate, where the IBAM is. The configuration
# of the "server" can be found in a the resource file xxxSerilaLine.res,
# where xxx is the name of the crate (i.e. d291, id011 ...)
#The parameters of the %B%RS232%B% serial line are:%BR%
# - 8 bits%BR%
# - no parity%BR%
# - 1 stop bit%BR%
# - 9600 bauds
#
#%LOG%
#$Log: ot302.mac,v $
#Revision 1.2 2008/08/12 15:27:02 rey
#documentation changes
#
#Revision 1.1 2003/07/25 12:33:17 beteva
#Initial revision
#
#%END%
#define global variables and assign some values
global OT_LINE OT_UNIT OT_DATA OT_CMNEM
#%UU%
#%MDESC% Activates the OT-302D: executes the setup sequence
#(_ot_setup macro), adds the reading of the possition into the
#counters reading (ct) only if ot_x counter defined
def ot_on '{
cdef ("","",OT_CMNEM[0],"delete")
cdef ("user_getcounts",";ot_read();",OT_CMNEM[0],0x22)
}'
#%UU%
#%MDESC% removes all the macros and definitions for the OT-302D
def ot_off '{
cdef ("","",OT_CMNEM[0],"delete")
}'
#%UU% <serial line number (i.e. 0), <unit number>>
#%MDESC% Establish the communication with the module. The input
#parameter is the ordinal number of the serial line device (starting from 0),
#as assigned in the %B%config%B% file and the unit number connected to the
#module. Default unit number is 1.
def ot_setup '{
local i
OT_UNIT = 1
if ($#) {
OT_LINE = $1
OT_CMNEM[0] = "$2"
OT_CMNEM[1] = "$3"
OT_CMNEM[2] = "$4"
OT_UNIT = $5
}
else {
OT_LINE = getval("Serial line number (starting from 0):",OT_LINE)
OT_CMNEM[0] = getval("X position pseudo counter mnemonic:",OT_CMNEM[0])
OT_CMNEM[1] = getval("Y position pseudo counter mnemonic:",OT_CMNEM[1])
OT_CMNEM[2] = getval("Sum pseudo counter mnemonic:",OT_CMNEM[2])
OT_UNIT = getval("Unit number (1-255):",OT_UNIT)
}
_ot_setup(OT_LINE, OT_UNIT)
}'
#%IU% (ser_line)
#%MDESC% Sets the Module in mm, no echo, fast averaging, default unit number
def _ot_setup(ser_line,unit) '{
local ot_put
ot_put = "m1\r"
if (ser_put(ser_line, ot_put) == -1)
eprintf ("error setting mm\n")
else
ser_get(ser_line,"!")
ot_put = "e0\r"
if (ser_put(ser_line, ot_put) == -1)
eprintf ("error setting no echo mode\n")
else
ser_get(ser_line,"!")
ot_put = "f1\r"
if (ser_put(ser_line, ot_put) == -1)
eprintf ("error setting fast averaging\n")
else
ser_get(ser_line,"!")
ot_put = sprintf ("s%d\r", unit)
if (ser_put(ser_line, ot_put) == -1)
eprintf ("error setting unit %d as default\n", unit)
else
ser_get(ser_line,"!")
}'
#%UU%
#%MDESC% Read the position (X,Y) [mm] and the SUM gain calibration [V].
def ot_read() '{
local i ot_data[]
_ot_read(OT_UNIT,ot_data)
for (i=0; i<3; i++)
S[cnt_num(OT_CMNEM[i])] = ot_data[i]
}'
#%UI% (unit)
#%MDESC% Read the position (X,Y) [mm]. Return 0 if success, -1 if error
def _ot_read(unit, ot_data) '{
local ot_put ot_get
local abb ind1 ind2
ot_put = sprintf("r%d\r",unit)
if (ser_put(OT_LINE, ot_put) != -1) {
ot_get = ser_get(OT_LINE,"!")
if (ot_get != 0) {
split(ot_get,abb,"mm")
ot_data[0] = 1*(substr(abb[0],index(abb[0],"=")+1))
ot_data[1] = 1*(substr(abb[1],index(abb[1],"=")+1))
ind1 = index(abb[2],"=") + 1
ind2 = index(abb[2],"V")
ot_data[2] = 1*(substr(abb[2],ind1, ind2-ind1))
return (0)
}
}
else {
for (i=0; i<3; i++)
ot_data[i] = 0
return (-1)
}
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% A.Beteva %BR%
#$Revision: 1.2 $, $Date: 2008/08/12 15:27:02 $
#%TOC%
|