#%TITLE%
# UPM60.mac
#%NAME%
# Set of macros to control upm60 sensors
#
#%DESCRIPTION%
# Macros to read the UPM60 controller for
# HBM sensors, using the following servers:
#%UL%
#%LI% Upm60 server
#%LI% Hbmsh server
#%XUL%
# The sensors are read through Hbmsh server.
# They allow to work with one single Upm60
# equipement (60 sensors).
#%BR% These macros allow to define a pseudomotor which will be
# connected to an Upm60 channel.
#%BR% The user can define the channel on which he wants to work.
#
#%DEPENDENCIES%
# To use the `upm60' pseudomotor:
#%UL%
#%LI% load the macro file : upm60.mac
#%LI% setup the encoder : with upm60setup
#%LI% configure your encoder :
#%UL%
#%LI% controller NONE
#%LI% mnemonic upm60
#%XUL%
#%XUL%
#%END%
# author : MCD
# $Revision: 3.0 $
#
# ---> This set of macros allow to read the Upm60 encoders through
# Hbmsh server.
# Use upm60_ma.mac if you want to use the sensors through Maxe
#
# upm60setup nb_of_sensors upm60_device_name hbmsh_device_root_name \
# "motor_mnemo upm60_channel motor_mnemo upm60_channel ..."
# Allows to work with Upm60 sensors of ONE UPM60 EQUIPEMENT
# (one single upm60 device)
#
# The list "motor_mnemo upm60_channel.." must be within " ".
# preliminary inits, defines:
# - UPM60_DEV : Upm60 device name
# filled with upm60_device_name
# - UPM60_HBM_ROOT : filled with hbmsh_device_root_name
# The Hbmsh objects (1 by channel) names will be built as:
# UPM60_HBM_ROOT/`upm60_channel
# (example : IDXX/Hbmsh/`upm60_channel')
# - UPM60_CHA[] : Upm60 channel for coresponding sensor
# filled with the `upm60_channel'
# - UPM60_EDEV[] : Hbmsh object name for reading corresponding sensor
# - UPM60_FOUND[] : 0/1 if there is an Upm60 sensor associated
# - defines the `upm60' pseudomotor
#
#
# upm60_select mnemo_name
# select the Upm60 sensor associated to motor
# `mnemo_name'
# Sets UPM60_SELMOT
#
# whatis_upm60
# print the Upm60 channel number selected for
# polling (UPM60_SELMOT)
# and the associated motor config number.
#
# upm60_read
# read the value of sensor Upm60 associated
# to the selected motor (UPM60_SELMOT)
# put value in UPM60_VAL
# prints the value
#
# upm60_read3
# called by the pseudo motor mechanism
# read the value of sensor Upm60 associated
# to the selected motor (UPM60_SELMOT)
# put value in UPM60_VAL and A[$1]
#
#
# set_acq_time acquisition time
# set the acquisition time (in msec)
# it is the time between sending the read command
# and reading the response
# This time is put in the global variable UPM60_ACQT
# by default : 300 ms
#
# set_poll_time polling_time
# set the polling time (in msec)
# it is the time to wait between 2 sets of
# acquisitions
# This time is put in the global variable UPM60_POLLT
# by default : 1 sec
#
# set_upm60 value
# sets the value of Upm60 selected channel
#
#
# GLOBAL VARIABLES:
# UPM60_VAL : last value of the selected UPM60 channel
# UPM60_SELMOT : motor mnemo assoiated to the UPM60 channel
# selected
# UPM60_DEV : UPM60 device name
# UPM60_HBM_ROOT : Hbmsh device root name
# UPM60_CHA[motor_mnemo] : array : = UPM60 channel associated
# UPM60_FOUND[motor_mnemo]: array
# set to 1 if the motor has an
# UPM60 sensor associated
#
# UPM60_EDEV[motor_mnemo] : array : Hbmsh device name to access the value of
# the UPM60 channel selected
#
# UPM60_PR : flag : set to 1 if `upm60_read3' has to print
# the UPM60 channel read.
# set to 0 if not.
# UPM60_ACQT : acquisition time (in msec)
# UPM60_POLLT : polling time (in msec)
# UPM60_TOT : nb of UPM60 channels defined
#
#
# Needed the following modification:
# Now, read the Upm60 sensor values through Hbmsh server instead of
# through Maxe_hm because Maxe_hm has problems with "home"
# Need to run Maxe
#---------------------------------------------
#
# upm60setup nb_of_chan hbmsh_device_root dev_name [" motor_mne upm60_cha motor mne ..."]
#
#---------------------------------------------
#%UU% <nb_of_chan> <hbmsh_device_root> <dev_name> [ "<motor_mne> <upm60_cha> <motor mne> ..."]
#%MDESC%
# Allows to work with Upm60 sensors of ONE UPM60 EQUIPEMENT
# (one single upm60 device)
#
#%BR% The list "motor_mnemo upm60_channel.." must be within " ".
# preliminary inits, defines:
#%UL%
#%LI% UPM60_DEV : Upm60 device name
#%BR% filled with upm60_device_name
#%LI% UPM60_HBM_ROOT : filled with hbmsh_device_root_name
#%BR% The Hbmsh objects (1 by channel) names will be built as:
#%BR% UPM60_HBM_ROOT/`upm60_channel
# (example : IDXX/Hbmsh/`upm60_channel')
#%LI% UPM60_CHA[] : Upm60 channel for coresponding sensor
# filled with the `upm60_channel'
#%LI% UPM60_EDEV[] : Hbmsh object name for reading corresponding sensor
#%LI% UPM60_FOUND[] : 0/1 if there is an Upm60 sensor associated
# defines the `upm60' pseudomotor
#%XUL%
#
def upm60setup'
{
global UPM60_SELMOT UPM60_DEVMOT UPM60_CHAMOT UPM60_EDEV UPM60_HBM_ROOT
global UPM60_VAL UPM60_DEV UPM60_CHA UPM60_FOUND
global UPM60_PR
global UPM60_ACQT UPM60_POLLT
global UPM60_TOT
local upm_MAX
local pstring motindex j found
global xx
upm_MAX=16
UPM60_TOT = $1
UPM60_DEV=sprintf("%s","$2")
UPM60_HBM_ROOT = sprintf("%s","$3")
if ( ($# > upm_MAX*2+2) || ($# == 0)) {
print "Usage: upm60setup <nb of chan> <dev name> <hbm root name> \" <motor mne> <upm60 cha> <motor mne> ..\" "
exit
}
# Following array gives the correspondance between
# a motor mnemo and an UPM60 channel
xx[16*2]=0
split("$4",xx)
# we get the list of UPM60_TOT couples
# "motor_mnemo" upm60_channel
# xx[i] xx[i+1]
# first clean
for (i=0; i<MOTORS; i++){
UPM60_FOUND[i]=0
UPM60_CHA[j]=0
}
# Creates array for motor to sensor correspondance
for (j=0; j<UPM60_TOT*2; j=j+2){
found = 0
motindex=0
while( (motindex<MOTORS) && (found==0) ) {
if( motor_mne(motindex) == xx[j]){
UPM60_CHA[motindex]=xx[j+1]
UPM60_EDEV[motindex]= sprintf("%s/%d",UPM60_HBM_ROOT,UPM60_CHA[motindex])
UPM60_FOUND[motindex]=1
found = 1
}
else {
motindex++
}
}
}
# Creates the pseudomotor
ppstring=sprintf("upm60 none none upm60_read3 none none none none 0 0")
pseudosdef ppstring
# Selects the channel to poll int he server (another appli could have changed it)
UPM60_PR=0
upm60_select UPM60_SELMOT
UPM60_PR=1
}
'
#---------------------------------------------
#
# upm60_select mnemo_name
#
#---------------------------------------------
#%UU% <mnemo_name>
#%MDESC%
#%BR% select the Upm60 sensor associated to motor
# `mnemo_name'
#%BR% Sets UPM60_SELMOT
#
def upm60_select '
{
local err
# Commented because no need to change the bounds now (all channels polled)
# err = esrf_io(UPM60_DEV,"DevSetBound",UPM60_CHA[$1],UPM60_CHA[$1])
# if (err != 0) {
# print "Upm60 server error while changing channels to poll"
# }
UPM60_SELMOT=$1
# print $1 " " UPM60_SELMOT
# print "UPM60_SELMOT = " UPM60_SELMOT
if (UPM60_FOUND[$1] == 0) {
print " "
print "No encoder selected !!!!"
}
else{
if (UPM60_PR == 1){
whatis_upm60
# commented because no bounds change, so no need to wait for a while
# sleep(3)
wa
}
}
}
'
#---------------------------------------------
#
# whatis_upm60
#
#---------------------------------------------
#%UU%
#%MDESC%
# print the Upm60 channel number selected for
# polling (UPM60_SELMOT)
# and the associated motor config number.
def whatis_upm60'
{
print " Upm60 channel selected: " UPM60_CHA[UPM60_SELMOT]
print " motor mnemo selected: " UPM60_SELMOT
}
'
#---------------------------------------------
#
# upm60_read motor_mnemo
#
#---------------------------------------------
#%UU% <motor_mnemo>
#%MDESC%
# read the value of sensor Upm60 associated
# to the selected motor (UPM60_SELMOT)
#%BR% puts the value in UPM60_VAL
#%BR% prints the value
def upm60_read '
{
if (UPM60_FOUND[UPM60_SELMOT] == 0) {
print " "
print "No encoder selected !!!!"
}
else {
UPM60_VAL = esrf_io(UPM60_EDEV[UPM60_SELMOT],"DevReadCount")
# need to read the error
if (ESRF_ERR !=0) {
print "upm60 : error"
}
if ( UPM60_PR == 1){
print " upm60 = " UPM60_VAL
}
}
}
'
#---------------------------------------------
#
# upm60_read3 upm60_mnemo
#
#---------------------------------------------
#%UU% <upm60_mnemo>
#%MDESC%
#%BR% called by the pseudo motor mechanism
#%BR% read the value of sensor Upm60 associated
# to the selected motor (UPM60_SELMOT)
#%BR% puts the value in UPM60_VAL and A[$1]
def upm60_read3'
{
UPM60_PR=0
upm60_read
UPM60_PR=1
A[$1] = UPM60_VAL
}
'
#---------------------------------------------
#
# set_acq_time acq_time_in_msec
#
#---------------------------------------------
#%UU% <acq_time_in_msec>
#%MDESC%
# sets the acquisition time (in msec),
# it is the time between sending the read command
# and reading the response
#%BR% This time is put in the global variable UPM60_ACQT
#%BR% by default : 300 ms
def set_acq_time'
{
local err
UPM60_ACQT=$1
err = esrf_io(UPM60_DEV,"DevSetAcqTime",UPM60_ACQT)
if (err != 0) {
print "Error in setting acquisition time of Upm60"
}
}
'
#---------------------------------------------
#
# set_poll_time poll_time_in_msec
#
#---------------------------------------------
#%UU% <poll_time_in_msec>
#%MDESC%
# sets the polling time (in msec)
#%BR% it is the time to wait between 2 sets of
# acquisitions
#%BR% This time is put in the global variable UPM60_POLLT
# by default : 1 sec
def set_poll_time'
{
local err
UPM60_POLLT=$1
err = esrf_io(UPM60_DEV,"DevSetPollTime",UPM60_POLLT)
if (err != 0) {
print "Error in setting polling time of Upm60"
}
}
'
#----------------------------------------------
#
# set_upm60 value
#
# sets Upm60 channel value
#----------------------------------------------
#%UU% <value>
#%MDESC%
# sets the value of Upm60 selected channel
def set_upm60 '
{
err = esrf_io(UPM60_EDEV[UPM60_SELMOT],"DevWriteCount",$1)
if (err == -1) {
print "Error in setting Upm60 value"
}
else {
print "Upm60 value is set to " $1
}
}'
#%MACROS%
#%IMACROS%
|