esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% HEIDENXY.MAC
#%NAME% 
#   Macros to define Heidenhein encoders as pseudomotors. 
#   Control is done through serial line
#
#%CATEGORY% Positioning 
#
#%DESCRIPTION%
#
#%PRE%
#  Macros to define and control Haidenhein encoders
#  as pseudomotors
#  These hdh are assumed to be controlled through
#  a serial line
#  Through an Hdh, we can access 2 values.
#
#  Serial line protocol:
#       ^B  to ask for a value
#       The response of the serial line is :
#       X=`sign'    <floating value> R <CR><LF>
#       Y=`sign'    <floating value> R <CR><LF><LF><LF><LF><LF>
#
#
#
#  March 1st 1994  MCD
#
#  NOTE: For the following macros, the HDH_DEV_index
#        represents the index 0..n in the list of 
#        HDH devices defined by the user with hdhsetup
#        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 with the first HDH of the list.
#
#  hdhsetup nb dev_name mne cha dev_name mne cha ...
#
#     setup of the devices
#
#  hdh_flush  HDH_DEV_index
#
#     print what is on the serial line buffer for one device
#
#  hdh_read n  HDH_DEV_index
#
#      prints the position in channel `n' (1 or 2 or 0=both)
#      of one device
#
#  hdh_read3  mne  n  HDH_DEV_index 
# 
#      for pseudo motor mecanism, reads the value
#      of one pseudo motor
#      It puts also the result in HDH_VAL
#
#  Macros:
#

#----------
#  hdhsetup nb dev_name1 pseudo_mne1 ch1 dev_name2 ch22 pseudo_mne2 ...
#
#           `nb          : nb of hdh pseudomotors defined
#           Dev_name`i'  : Name of the MAXE device containing
#                          the CC133 encoder for the `i'th pseudom.
#           pseudo_mne`i': mnemonic associated to that pseudomotor
#           ch`i'        : channel number (1 for X) or (2 for Y)
# 
#  when called without arguments, this macro asks interactively
#  for the values
#
#----------
#%PRE%
#
#%END%

#%UU%
#%MDESC%
def hdhsetup '
{
global HDH_NO HDH_DEV HDH_MNE HDH_CHA HDH_MAXNO
# HDH_VAL will receive the last read hdh value
global HDH_VAL  
global ppstring
local _pmne _pdev _chan nomne 

HDH_MAXNO=5
_pdev[0]="$2"
_pdev[1]="$5"
_pdev[2]="$8"
_pdev[3]="$11"
_pdev[4]="$14"
_pmne[0]="$3"
_pmne[1]="$6"
_pmne[2]="$9"
_pmne[3]="$12"
_pmne[4]="$15"
_chan[0]="$4"
_chan[1]="$7"
_chan[2]="$10"
_chan[3]="$13"
_chan[4]="$16"


if ($# > HDH_MAXNO*2+1) {
  print "Usage: hdhsetup [nb of hdh] [dev name] [hdh mne] [hdh cha]"
  print "                         [dev name] [hdh mne] [hdh cha] ..."
  exit
  }

nomne = int (($#-1)/2)

if ($# < 1) {
  HDH_NO = getval("How many Hdh devices do you want to use ",HDH_NO)
  }
else {
  HDH_NO = $1
  }

if (HDH_NO > HDH_MAXNO) {
  printf ("Just %d hdh allowed! Nothing done!\n",HDH_MAXNO)
  exit
  }


for (i=0; i< HDH_NO; i++) {
  if (nomne < i+1 && HDH_NO > i) {
    HDH_DEV[i]=getval(sprintf("What is the name of your Hdh device No %d ",i+1),HDH_DEV[i])
    }
  else if (HDH_NO > i) {
    HDH_DEV[i]=_pdev[i]
    }
  if (nomne < i+1 && HDH_NO > i) {
    HDH_MNE[i] = getval("What is the name of your pseudo motor hdh ",HDH_MNE[i])
    }
  else if (HDH_NO > i) {
    HDH_MNE[i]=_pmne[i]
    }
  if (nomne < i+1 && HDH_NO > i) {
    HDH_CHA[i] = getval("What is your Hdh channel [1 or 2]",HDH_CHA[i])
    }
  else if (HDH_NO > i) {
    HDH_CHA[i]=_chan[i]
    }
  }

for (i=0;i<HDH_NO; i++) {
  local ppstring
  ppstring=sprintf ("%s none none hdh_read3 %d %d",HDH_MNE[i],HDH_CHA[i],i)
  pseudosdef ppstring  
  } 
}

pseudoredef
'

#-------------------------------------------
#  hdh_flush  HDH_DEV_index
#
#  prints what is on the buffer for a device
#

def hdh_flush '
print esrf_io(HDH_DEV[$1],"DevSerReadString",0)
'


#-------------------------------------------
#  hdh_read  `n'  HDH_DEV_index
#
#  If n is not provided, prints the values of 
#  the 2 channels of a device
#  If n is 1  : prints the value of X channel
#  If n is 2  : prints the value of Y channel
#
#  put the last read value in HDH_VAL

def hdh_read '
{
local str1 str2 dummy valx valy
esrf_io(HDH_DEV[$2],"DevSerWriteString","\2")
sleep(0.5)
str1 = esrf_io(HDH_DEV[$2],"DevSerReadString",0)
str2 = esrf_io(HDH_DEV[$2],"DevSerReadString",0)
esrf_io(HDH_DEV[$2],"DevSerReadString",0)
if ($1 !=2 ) {
   sscanf(str1,"%s%f",dummy,valx)
   if (index(dummy,"-") !=0) {
     valx = -valx
   }
   print "X= " valx
   HDH_VAL = valx
}
if ($1 !=1) {
   sscanf(str2,"%s%f",dummy,valy)
   if (index(dummy,"-") !=0) {
     valy = -valy
   }
   print "Y= " valy
   HDH_VAL = valy
}
}
'

#-------------------------------------------
#-------------------------------------------
#-------------------------------------------

#  macro for the pseudo_motor mecanism

#-------------------------------------------
#  hdh_read3  motor_mne  1/2  HDH_list_index 
#              
#       HDH_list_index:  index in HDH_xx list
#       1 -> if interested by X value of Hdh
#       2 -> if interested by Y value of Hdh
#
#  macro for the pseudo_motor mecanism
#  put the value in HDH_VAL
#
def hdh_read3 '
{
local str1 str2 dummy valx valy
esrf_io(HDH_DEV[$3],"DevSerWriteString","\2")
sleep(0.5)
str1 = esrf_io(HDH_DEV[$3],"DevSerReadString",0)
str2 = esrf_io(HDH_DEV[$3],"DevSerReadString",0)
esrf_io(HDH_DEV[$3],"DevSerReadString",0)
if ($2 !=2 ) {
   sscanf(str1,"%s%f",dummy,valx)
   if (index(dummy,"-") !=0) {
     valx = -valx
   }
   A[$1]=valx
}
if ($2 !=1) {
   sscanf(str2,"%s%f",dummy,valy)
   if (index(dummy,"-") !=0) {
     valy = -valy
   }
   A[$1]=valy
}
HDH_VAL=A[$1]
}
'
#%MACROS%
#%IMACROS%
#%TOC%
#%AUTHOR% G.Berruyer