esrf

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

#%TITLE% CaenV560.mac
#%NAME% 
#   Macro to control a CAEN V560 counter card, with macro counters and vmeds
#%CATEGORY% Detection, counting
#%DESCRIPTION%
# Use this macro set to control a Caen V560 counter card by the use of
# macro counters.
# %BR%
# For the internals:
# %BR%
# %BR%
# the channels are cleared before starting the counter; signal "prestart_all".
# %BR%
# all channels are read only once at the signal "halt_all".
# %BR%
# then each channel receives its value, signal "counts".
#%SETUP%
# The macro set needs the vmeds.mac file.
# %BR%
# %BR%
# In the config editor:
# %BR%    
# create a scaler controller like follows:
# %BR%
#\0YES\0\0\0\0\0\0\0\0\0\0V560\0\0IDXX/V560/0\0\0\0\0\0\016\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0Macro\0Counter
# %BR% 
# then create up to 16 counters:
# %BR%
#\012\0\0\0\0\0\0V560_1\0\0\0\0V560_1\0\0\0MAC_CNT\0\0\0\0\00\0\0\0\0\00(to15)\0\0\0\0counter\0\0\0\0\0\0\0\0\01
#%END%
#
# Modifications history:
# 08/02/2007 Creation 

need vmeds


def V560_config(mne,type,unit,mod,chan) '{
  global __V560[]
  if (mne != "..") {
     print "Configuring " cnt_mne(mne) " as a V560 scaler on " V560_ADDR
  } else {
    # Try to read the manufacturer code, offset 0xfa, short
    if ((manufacturer = vmeds_get(V560_ADDR, 0xfa, "D16")) != 0xfaf5) {
      eprint "Card with server name", V560_ADDR, "does not seem to be a"
      eprint "Caen V560! Macro counter disabled!"
      return ".error."
    }
    __V560[unit]["addr"] = V560_ADDR
  }
}'

def V560_cmd(mne, cmd, p1, p2, p3) '{
  local dsname, ldata, unit
  unit = counter_par(mne,"unit")
  if (mne != "..") {
    local V560_CLEAR_ADDR
    V560_CLEAR_ADDR = 0x50
    dsname = __V560[unit]["addr"]
    if (cmd == "counts") {
      ldata = "__V560_" unit "_DATA"
      if((chan = counter_par(mne,"channel")) > 0x10) {
        eprint "Caen V560! not enough channels for channel", chan, "!"
        return ".error."
      }
      return(@ldata[chan])
    }
  } else {
    local dsname, ldata
    if (cmd == "halt_all") {
      dsname = __V560[unit]["addr"]
      ldata = "__V560_" unit "_DATA"
      global long array @ldata[0x10]
      # read hardware only once per card
      vmeds_move(dsname,0x10,@ldata,0x10,"D32")
    } else if (cmd == "prestart_all") {
      dsname = __V560[unit]["addr"]
      # Clear all
      vmeds_put(dsname, 0x50, 1, "D16")
    }
    return(0)
  }
}
'