esrf

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

#%TITLE% deltaelec.mac  
#%NAME%
#   Delta Elektronika Power Supply Control.
#
#%CATEGORY% Other hardware
#
#%DESCRIPTION%
#   Volt/Current setpoint are controlled via GPIB as pseudo motors and both output 
#   values can be read in as pseudo counters.
#
#%EXAMPLE%
#
#%DL%
#%DT% deltasetup 8 15 200 volt curr v i 
#%DD%
#   Sets motors volt and curr as respectively voltage and current setpoint, v and i as respectively 
#   voltage and current readout counters, for power supply connected at GPIB address 8. 
#   The Power supply is set for delivering 15 V and 200 A at full scale. 
#%XDL%  
#
#%END%

#%UU%  [gpib_address] [max volt] [max current] [Volt actuator mne] [Current actuator mne] [Volt sensor mne] [Current sensor mne]
#%MDESC% Setup macro. Full scales are 15 V and 200 A maxi. 

def deltasetup '{

  global DE_FU DE_FI DE_U DE_I DE_GPIB DE_IMNE DE_UMNE
  global DE_ICMNE DE_UCMNE
  local res

  DE_FU=15 
  DE_FI=200

  DE_GPIB=DE_GPIB?DE_GPIB:8
  DE_GPIB=$#?$1:getval ("GPIB address of the Delta Electronica device",DE_GPIB)
  print

  print "Alim Delta Elektronika",delta_io("ID?")  
  print "Full Scale 15 V and 200 A."
  print
  delta_io("FU15,FI200")
  
  res=delta_io("MA?")
  sscanf(res,"MA%d",res)
  if (res>0) {
    DE_U=DE_FU*res/4095
  } else 
    DE_U=0
  res=delta_io("MB?")
  sscanf(res,"MB%d",res)
  if (res>0) {
    DE_I=DE_FI*res/4095
  } else 
    DE_I=0
  
  DE_U=$#?$2:getval ("  Constant Voltage",DE_U)
  DE_I=$#?$3:getval ("  Constant Current",DE_I)
  
  DE_U=int(DE_U*4095/DE_FU)
  DE_I=int(DE_I*4095/DE_FI)

  delta_io(sprintf("SA%f,SB%f",DE_U,DE_I))

  DE_UMNE=$#?"$4":getval ("  Voltage actuator mnemonic",DE_UMNE) 
  DE_IMNE=$#?"$5":getval ("  Current actuator mnemonic",DE_IMNE) 
  DE_UCMNE=$#?"$6":getval ("  Voltage sensor mnemonic",DE_UCMNE) 
  DE_ICMNE=$#?"$7":getval ("  Current sensor mnemonic",DE_ICMNE) 
  
  
  cdef("prompt_mac",     "_de_prompt\n","de")
  cdef("user_getpangles","_de_getI\n",DE_IMNE, 0x10)
  cdef("user_getpangles","_de_getU\n",DE_UMNE, 0x10)
  cdef("user_checkall",  "_de_premove\n","de", 0x10)
  cdef("user_moveall",  "_de_setI\n",DE_IMNE,0x20)
  cdef("user_moveall",  "_de_setU\n",DE_UMNE,0x20)
  cdef("user_getcounts",sprintf("_de_getIC %s\n",DE_ICMNE),DE_ICMNE)
  cdef("user_getcounts",sprintf("_de_getUC %s\n",DE_UCMNE),DE_UCMNE)

  setup_tail("delta")

}'

#%IU%
#%MDESC% Un-Setup macro.

def deltaunsetup '{
  cdef ("","","de","delete")
  cdef ("","",DE_IMNE,"delete")
  cdef ("","",DE_UMNE,"delete")
  cdef ("","",DE_ICMNE,"delete")
  cdef ("","",DE_UCMNE,"delete")
}'

#%IU% (command)
#%MDESC% Input/Output function. GPIB interface only.

def delta_io(command) '{
 
  local com res add
  add=DE_GPIB
  com=command "\r\n"

  gpib_put(add,com)
  sleep (0.1)
  res= gpib_get(add) 
  return res
}'


#%IU%
#%MDESC% 

def _de_prompt '{
  global DE_DONTREAD
  DE_DONTREAD=0
}'

#%IU%
#%MDESC% 

def _de_premove '{
  global DE_DONTREAD
  DE_DONTREAD=1
}'

#%IU%
#%MDESC% user_getpangles for actual output current.

def _de_getI '{
  global DE_DONTREAD DE_OLDI
  if (0==DE_DONTREAD) {
    res=delta_io("MB?")
    sscanf(res,"MB%d",res)
    if (res>0) {
      DE_I=DE_FI*res/4095
    } else 
      DE_I=0
  }
  
  DE_OLDI=A[motor_num(DE_IMNE)]=DE_I
}'

#%IU%
#%MDESC% user_getpangles for actual output voltage.

def _de_getU '{
  global DE_DONTREAD DE_OLDU
  if (0==DE_DONTREAD) {
    res=delta_io("MA?")
    sscanf(res,"MA%d",res)
    if (res>0) {
      DE_U=DE_FU*res/4095
    } else 
      DE_U=0
  }
  DE_OLDU=A[motor_num(DE_UMNE)]=DE_U
}'

#%IU%
#%MDESC% user_checkall for current setpoint.

def _de_setI '{
 global DE_DONTREAD 
 if (DE_OLDI!=A[motor_num(DE_IMNE)]) {
   DE_DONTREAD=0
   DE_I=A[motor_num(DE_IMNE)]
   DE_I=int(DE_I*4095/DE_FI)
   delta_io(sprintf("SB%d",DE_I))
 }
}'

#%IU%
#%MDESC% user_checkall for voltage setpoint.

def _de_setU '{
 global DE_DONTREAD 
 if (DE_OLDU!=A[motor_num(DE_UMNE)]) {
   DE_DONTREAD=0
   DE_U=A[motor_num(DE_UMNE)]
   DE_U=int(DE_U*4095/DE_FU)
   delta_io(sprintf("SA%d",DE_U))
 }
}'

#%IU%
#%MDESC% user_getcounts for current.

def _de_getIC '{

    res=delta_io("MB?")
    sscanf(res,"MB%d",res)
    if (res>0) {
      DE_I=DE_FI*res/4095
    } else 
      DE_I=0

    S[$1]=DE_I
}'

#%IU%
#%MDESC% user_getcounts for voltage.

def _de_getUC '{

    res=delta_io("MA?")
    sscanf(res,"MA%d",res)
    if (res>0) {
      DE_U=DE_FU*res/4095
    } else 
      DE_U=0

    S[$1]=DE_U
}'


#%MACROS%
#%IMACROS%
#%DEPENDENCIES%
#  stlocal.mac, pseudo.mac 
#%AUTHOR%
#  DELTAELEC.MAC MCL  
#%TOC%