#%TITLE% HBM2.MAC
#%NAME%
# Macros to control the Hbm 2 channels equipement (MGC)
#
#%AUTHOR% MCD
#
#%CATEGORY% Positioning
#
#%DESCRIPTION%
# These macros allow to initialize, read this type of encoder, and
# define them as pseudomotors.
#%DEPENDENCIES%
# To use an HBM encoder:
#%UL%
#%LI% load the macro file : hbm2.mac
#%LI% setup the encoder(s) : with hbmsetup
#%LI% configure your encoder(s) :
#%UL%
#%LI% controller NONE
#%LI% mnemonic corresponding to the one provided in hbmsetup
#%XUL%
#%XUL%
# For the following macros, the HBM_DEV_index
# represents the index 0..n in the list of
# HBM devices defined by the user with hbmsetup
# if this parameter is omitted, as it is always
# the last parameter in the list of the macro,
# Spec will replace it by 0. So omitting it
# allows to work to the first HBM of the list.
#%END%
# $Revision: 3.1 $
#
# NOTE: For the following macros, the HBM_DEV_index
# represents the index 0..n in the list of
# HBM devices defined by the user with hbmsetup
# if this parameter is omitted, as it is always
# the last parameter in the list of the macro,
# Spec will replace it by 0. So omitting it
# allows to work to the first HBM of the list.
#
# hbm_quit HBM_DEV_index
#
# frees the connection with the serial line for
# one device
#
# hbm_cmd cmd HBM_DEV_index
#
# sends the set of caracters `cmd' to one device
#
# hbm_init HBM_DEV_index
#
# initialises the connection with one device
#
# hbm_flush HBM_DEV_index
#
# reads what is on the serial line buffer for
# one device
#
# hbm_read HBM_DEV_index
#
# print the position value of one device
# It puts also this value in HBM_VAL
#
# hbm_read3 mne HBM_DEV_index
#
# for pseudo motor mecanism, reads the value
# of one pseudo motor
# It puts also this value in HBM_VAL
#
#------
# hbmsetup [nb of hbm] [dev name] [hbm mne] [dev name] .."
# nb of hbm : nb of pseudomotors hbm defined
# dev name `i' : server device name for pseudomotor hbm `i'
# hbm mne `i' : mnemonic for pseudomotor hbm `i'
#-----
global HBMMACLOADED
#%UU% <nb of hbm> <dev name> <hbm mne> <dev name> ..
#%MDESC%
#%UL%
#%LI% nb of hbm : nb of pseudomotors hbm defined
#%LI% dev name `i' : server device name for pseudomotor hbm `i'
#%LI% hbm mne `i' : mnemonic for pseudomotor hbm `i'
#%BR% This macro allows to define some HBM encoders as pseudomotors.
#%BR% For each encoder, the user has to provide the mnemonic for this
# encoder (free), plus the server device name for the hardware
# access to the encoder. Each encoder has a number, from 0 to
# [nb of hbm]-1.
def hbmsetup '
{
global HBM_NO HBM_DEV HBM_MNE HBM_MAXNO
# HBM_VAL will have the last hbm value read
global HBM_VAL
global ppstring
local _pmne _pdev nomne
HBM_MAXNO=5
_pdev[0]="$2"
_pdev[1]="$4"
_pdev[2]="$6"
_pdev[3]="$8"
_pdev[4]="$10"
_pmne[0]="$3"
_pmne[1]="$5"
_pmne[2]="$7"
_pmne[3]="$9"
_pmne[4]="$11"
if ($# > HBM_MAXNO*2+1) {
print "Usage: hbmsetup [nb of hbm] [dev name] [hbm mne] [dev name] .."
exit
}
nomne = int (($#-1)/2)
if ($# < 1) {
HBM_NO = getval("How many Hbm devices do you want to use ",HBM_NO)
}
else {
HBM_NO = $1
}
if (HBM_NO > HBM_MAXNO) {
printf ("Just %d hbm allowed! Nothing done!\n",HBM_MAXNO)
exit
}
for (i=0; i< HBM_NO; i++) {
if (nomne < i+1 && HBM_NO > i) {
HBM_DEV[i]=getval(sprintf("What is the name of your Hbm device No %d ",i+1),HBM_DEV[i])
}
else if (HBM_NO > i) {
HBM_DEV[i]=_pdev[i]
}
if (nomne < i+1 && HBM_NO > i) {
HBM_MNE[i] = getval(sprintf("What is the name of your pseudo motor hbm No %d ",i+1),HBM_MNE[i])
}
else if (HBM_NO > i) {
HBM_MNE[i]=_pmne[i]
}
}
for (i=0;i<HBM_NO; i++) {
local ppstring
ppstring=sprintf ("%s none none hbm_read3 none none none none %d %d",HBM_MNE[i],i,i)
pseudosdef ppstring
}
}
for (i=0;i<HBM_NO; i++) {
hbm_init i
}
'
#------------------------------------
# hbm_quit HBM_DEV_index
#
#%IU% <HBM_DEV_index>
#%MDESC%
# frees the connection with the serial line for
# one device
def hbm_quit '
{
esrf_io(HBM_DEV[$1],"DevSerWriteString","\001")
}
'
#------------------------------------
# hbm_cmd XXX HBM_DEV_index
#
# sends the set of characters XXX to Hbm
#
#%IU% <XXX> <HBM_DEV_index>
#%MDESC%
# sends the set of characters XXX to Hbm
def hbm_cmd '
{
esrf_io(HBM_DEV[$2],"DevSerWriteString","$1")
}
'
#------------------------------------
# hbm_init HBM_DEV_index
#
#%IU% <HBM_DEV_index>
#%MDESC%
# initialises the connection with one device
#%BR% this macro is automatically run by hbm_init
def hbm_init '
{
esrf_io(HBM_DEV[$1],"DevSerWriteString","\022")
esrf_io(HBM_DEV[$1],"DevSerWriteString","COF0;")
sleep(0.1)
hbm_flush
hbm_flush
esrf_io(HBM_DEV[$1],"DevSerWriteString","CHS1;")
sleep(0.1)
hbm_flush
hbm_flush
}
'
#------------------------------------
# hbm_flush HBM_DEV_index
#
# Reads the buffer and displays the value
#%IU% <HBM_DEV_index>
#%MDESC%
# Reads the buffer and displays the value
def hbm_flush '
{
local str
str=esrf_io(HBM_DEV[$1],"DevSerReadString",0)
print str
}
'
#------------------------------------
# hbm_flushnom HBM_DEV_index
#
# Reads silently the buffer
#%UU% <HBM_DEV_index>
#%MDESC%
# Reads silently the buffer
# This macro can be run, in case of problem, to flush
# old values in the buffer.
def hbm_flushnom '
{
local str
str=esrf_io(HBM_DEV[$1],"DevSerReadString",0)
}
'
#-----------------------------------
# hbm_read HBM_DEV_index
#
# Displays the value of the Hbm
# Puts the value in HBM_VAL
#
#%UU% <HBM_DEV_index>
#%MDESC%
# Displays the value of the Hbm
#%BR% Puts the value in HBM_VAL
def hbm_read '
{
local val dum chan stat str
esrf_io(HBM_DEV[$1],"DevSerWriteString","MSV?;")
sleep(0.1)
str=esrf_io(HBM_DEV[$1],"DevSerReadString",0)
#print str
sscanf(str,"%f%c%d%c%d",val,dum,chan,dum,stat)
printf("val = %f, err = %d",val,stat)
HBM_VAL=val
hbm_flush $1
}
'
#-------------------------------------
#-------------------------------------
#-------------------------------------
# Macros for the pseudo_motors mechanism
#-------------------------------------
#
# hbm_read3 mne HBM_list_index
#
#%IU% <mne> <HBM_list_index>
#%MDESC%
# for pseudo motor mecanism, reads the value
# of one pseudo motor <mne>
#%BR% It puts also this value in HBM_VAL
#
def hbm_read3 '
{
local val dum chan stat str
esrf_io(HBM_DEV[$2],"DevSerWriteString","MSV?;")
sleep(0.1)
str=esrf_io(HBM_DEV[$2],"DevSerReadString",0)
sscanf(str,"%f%c%d%c%d",val,dum,chan,dum,stat)
A[$1]=val
HBM_VAL=val
if (stat !=0) {
print "HBM: error on channel"
}
hbm_flushnom $2
}
'
#%MACROS%
#%IMACROS%
|