#%TITLE% TALYVEL.MAC
#
#%NAME%
# Macros to read out TALYVEL4 inclinometer through serial line.
# Only one of the two channels can be read. The rotating button
# on the TALYVEL4 front panel selects the channel read by the macros.
#
#%DESCRIPTION%
# Configure a macro counter controller with ADDR field corresponding
# to the serial line used:
#
#SCALERS DEVICE ADDR <>MODE NUM <>TYPE
#%BR%YES talyvel 1 2 Macro Counter
#
# Here is an example of serial line setup:
#
#SERIAL DEVICE <>TYPE <>BAUD <>MODE
#%BR%1 YES /dev/ttyS1 <> 9600 raw
#
# Then configure a counter:
#
#Number Name Mnemonic <>Device Unit Chan <>Use As Scale
#%BR%XX incl incl MAC_CNT 0 0 counter 1
#
# NOTE: the cabling is not standard:
#%BR%TALYVEL4 4U
#%BR%DB25-F DB9-M
#%BR%2-------3
#%BR%3-------2
#%BR%6-------7
#%BR%7-------5
#%BR%18-25 4-6-8
#%END%
#
#%IU%()
#%MDESC%
# Macro counter implementation
#
def talyvel_config(num,type,p1,p2,p3) '{
local dev
#
# p1==controller index p2==number of motors supported
#
if(type == "ctrl") {
# check serial line
dev = talyvel_ADDR
if(ser_par(dev, "responsive") != 1) {
_talyvel_err
printf("Wrong serial line configured\n")
return ".error."
}
# check communication with instrument
if(talyvel_check(dev)) {
_talyvel_err
printf("No commmunication with instrument\n")
return ".error."
}
printf("Using TALYVEL4 inclinometer\n")
}
#
# p1==unit p2==0 p3==channel
#
if(type == "cnt") {
}
}'
#%IU%()
#%MDESC%
# Macro counter implementation
#
def talyvel_cmd(num,key,p1,p2) '{
local dev
#
# Handle actions at controller level
#
if(num == "..") {
return
}
#
# Handle actions at counter level
#
dev = talyvel_ADDR
#
# called for any counter,
# returns the current counter value
if (key == "counts") {
# switch off any previous readout
talyvel_off(dev)
# switch on instrument
talyvel_on(dev)
# read one value
val = talyvel_read(dev)
# switch off instrument
talyvel_off(dev)
# TODO: check format
return(val)
}
}'
#%IU%(sl)
#%MDESC%
# Returns null if ok
#
def talyvel_check(dev) '{
# ASCII char 63(dec)
ser_put(dev, "\077")
# TODO: check answer
ser_get(dev)
# normal end
return(0)
}'
#%IU%(sl)
#%MDESC%
#
def talyvel_off(dev) '{
# ASCII char 19(dec)
ser_put(dev, "\023")
sleep(.1)
ser_par(dev, "flush")
# normal end
return(0)
}'
#%IU%(sl)
#%MDESC%
#
def talyvel_on(dev) '{
# ASCII char 17(dec)
ser_put(dev, "\021")
# TODO: not clear how to distinguish channel A or B
# ASCII char 88(dec)
#ser_put(dev, "X")
#ser_put(dev, "X")
# ASCII char 70(dec)
ser_put(dev, "F")
# normal end
return(0)
}'
#%IU%(sl)
#%MDESC%
#
def talyvel_read(dev) '{
local ch
local to t
local ans val
# wait for instrument with a timeout
t = time()
for(to = 1;(time() - t) < 2.0;) {
ch = ser_par(dev, "queue")
if(ch > 20) {
to = 0
break
}
}
if(to) {
_talyvel_err
printf("Timeout waiting for instrument data\n")
return ".error."
}
# expected answers:
# "93.3\r A+193.2\r A+193."
# " B+$$$.$\r B+$$$.$\r B"
ans = ser_get(dev)
#printf("_%s_\n",substr(ans, index(ans,"\r")+4, 6))
if(sscanf(substr(ans, index(ans,"\r")+4, 6), "%f", val) != 1) {
_talyvel_err
printf("Unable to parse instrument answer\n")
return ".error."
}
# normal end
return(val)
}'
#%IU%
#%MDESC%
# Pure cosmetic macro
#
def _talyvel_err '{
tty_cntl("md")
printf("TALYVEL ERROR: ")
tty_cntl("me")
}'
#%MACROS%
#%IMACROS%
#%AUTHOR% MP BLISS (Original 05/2017).
# %BR%$Revision: 1.0 $ / $Date: 2017/06/02 11:33:15 $
#%TOC%
|