esrf

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

#%TITLE% K2001.MAC  
#%NAME%
# Use the keithley 2001 multimeter as a pseudo-counter
# (Obsolete: use multim.mac instead)
#
#%CATEGORY% Detection, Multimeter, Obsolete
#
#%DESCRIPTION%
# The keithley 2001 multimeter can be used as a counter . Each time you
# ask spec to count it will look for counters with a name 
# k_<keithley_number>_<channel_number> for multiplexed use or 
# k_<keithley_number> without multiplexing and read it once.
# The keithley will be programmed to automatic scaling.
#%EXAMPLE%
# counter k_1_1 and k_1_2 have been configured with spec
#   configuration editor.
#%DL%
# %DT% k2001setup 10 1 1 2 %DD%
#   You set up two multiplexed entries on one keithley on gpib address 10
# %DT% ct 2 %DD%
#   The actual values in the multimeter will be read on multiplexed
#   entry 1 and 2 and put into the counters k_1_1 and k_1_2.
#   The 2 will not have any meaning if you did not configure another
#   counter. The keithley will be read only once.
# %DT% ascan m1 0 10 1 1 %DD%
#   The motor m1 will be scanned and the to entries will be read at
#   each point. 
#%XDL%  
#
#%END%  

#%UU%  [first_gpib_channel] [number_of_keithleys] [channel_k1 ....]
#%MDESC%

#    define the keithley as a pseudo counter
def k2001setup '
{
local args
#Setup the channel of the Keithley K2001 as counter
global K2001_CHANNEL K2001_NO K2001_MCNO K2001_RATIO K2001_CH K2001_MEAS
global K2001_AVER K2001_NOREADS K2001_TXT
global K2001_ON
k2001off

K2001_MEAS["dcv"]=":SENSE:FUNC \'VOLT:DC\'\n"
K2001_MEAS["acv"]=":SENSE:FUNC \'VOLT:AC\'\n"
K2001_MEAS["dci"]=":SENSE:FUNC \'CURR:DC\'\n"
K2001_MEAS["aci"]=":SENSE:FUNC \'CURR:AC\'\n"
K2001_MEAS["res"]=":SENSE:FUNC \'RES\'\n"
K2001_MEAS["fres"]=":SENSE:FUNC \'FRES\'\n"
K2001_MEAS["frq"]=":SENSE:FUNC \'FREQ\'\n"
K2001_MEAS["tmp"]=":SENSE:FUNC \'TEMP\'\n"
if ($#) {
  split("$*",args)
  K2001_CHANNEL=args[0]
  K2001_NO =args[1]
  for (cc=0,ii=0;ii<K2001_NO;ii++) {
     K2001_MCNO[ii]=args[2+cc]
     nn=((K2001_MCNO[ii]>0)?K2001_MCNO[ii]:1)
     for (kk=0;kk<nn;kk++) {
       K2001_CH[sprintf("D%dC%d",ii,kk)]=(args[3+3*kk+cc]?args[3+3*kk+cc]:1)
       K2001_RATIO[sprintf("D%dC%d",ii,kk)]=(args[4+3*kk+cc]?args[4+3*kk+cc]:1)
       K2001_TXT[sprintf("D%dC%d",ii,kk)] = sprintf("%s",args[5+3*kk+cc])
       K2001_MEAS[sprintf("D%dC%d",ii,kk)] = K2001_MEAS[K2001_TXT[sprintf("D%dC%d",ii,kk)]]
       }
     cc+=(3*nn)+1
     }
  }
else {
  K2001_CHANNEL = getval("The k2001 start from which gpib channel ",                                     K2001_CHANNEL)
  K2001_NO = getval("How many k2001s do you use ",K2001_NO)
  for (cc=0,ii=0;ii<K2001_NO;ii++) {
    K2001_MCNO[ii] = getval(sprintf(" How many multiplexed entries on K2001 %d",                                     ii+1),K2001_MCNO[ii])  
    for (kk=0;kk<((K2001_MCNO[ii]>0)?K2001_MCNO[ii]:1);kk++) {
      printf(" entry %d\n",kk+1)
      K2001_CH[sprintf("D%dC%d",ii,kk)]=                                                  getval("  Channel number",K2001_CH[sprintf("D%dC%d",ii,kk)])
      K2001_RATIO[sprintf("D%dC%d",ii,kk)]=                                               getval("  Scale",K2001_RATIO[sprintf("D%dC%d",ii,kk)])
      K2001_TXT[sprintf("D%dC%d",ii,kk)]=getval("  Measurement unit \                 (dcv,dci,acv,aci,res,fres,frq,tmp\)",K2001_TXT[sprintf("D%dC%d",ii,kk)])
      K2001_MEAS[sprintf("D%dC%d",ii,kk)]=K2001_MEAS[K2001_TXT[sprintf("D%dC%d",ii,kk)]]
      }
    }
  }
k2001on
k2001_init
}'

def k2001on '
{
local i ii

K2001_ON=1
for (i=0; i<K2001_NO; i++) { 
  local ppstring
  if (K2001_MCNO[i] != 0) {
    for (ii=0;ii<K2001_MCNO[i];ii++) {
      if (K2001_NOAVERAGE) {
        ppstring = sprintf("k_%d_%d k2001_precount k2001_postcount k2001_getcounts none none %d %d",i+1,ii+1,K2001_CHANNEL+i,K2001_CH[sprintf("D%dC%d",i,ii)])
        cpseudosdef ppstring
      } else {
        ppstring = sprintf("k_%d_%d k2001_precount k2001_postcount _k2001_getcounts none none %d %d",i+1,ii+1,K2001_CHANNEL+i,K2001_CH[sprintf("D%dC%d",i,ii)])
        cpseudosdef ppstring
        cdef("user_pollcounts",sprintf("_k2001_getcounts k_%d_%d %d %d;",i+1,ii+1,K2001_CHANNEL+i,K2001_CH[sprintf("D%dC%d",i,ii)]),sprintf("k_%d_%d",i+1,ii+1),0x02)
      }
    }
  } else {
    if (K2001_NOAVERAGE) {
      ppstring = sprintf("k_%d k2001_precount k2001_postcount k2001_getcounts none none %d -1",i+1,K2001_CHANNEL+i)
      cpseudosdef ppstring
    } else {
      ppstring = sprintf("k_%d k2001_precount k2001_postcount _k2001_getcounts none none %d -1",i+1,K2001_CHANNEL+i)
      cpseudosdef ppstring
      cdef("user_pollcounts",sprintf("_k2001_getcounts k_%d %d -1;",i+1,K2001_CHANNEL+i),sprintf("k_%d",i+1),0x02)
    }
  }
} 

}'

def k2001body(mode) '{
  if (mode==1) {
     if (K2001_ON) {
         k2001off
     } else {
         k2001on
     }
  }

  if (mode==2) {
  }

  return(sprintf("%s",K2001_ON?"On":"Off"))
}'

def k2001off '
{
local i ii

K2001_ON=0
for (i=0; i<K2001_NO; i++) { 
  local ppstring
  if (K2001_MCNO[i] != 0) {
    for (ii=0;ii<K2001_MCNO[i];ii++) {
      ppstring = sprintf("k_%d_%d",i+1,ii+1)
      cpseudosdel ppstring
      }
    }
  else {
    ppstring = sprintf("k_%d",i+1)
    cpseudosdel ppstring
  }
}
} '

def k2001_init '
for (i=0; i<K2001_NO; i++) { 
  gpib_put(K2001_CHANNEL+i,":syst:pres\n")
}'

def k2001_open '
gpib_put($2,":rout:open:all\n")
'

def k2001_close '
gpib_put($2,":rout:close (@$3)\n")
'

def _k2001_getcounts '
{
global K2001_POLLTIME K2001_GPIBCHK
# To keep in compliance with id16 asl scans.
k2001_getcounts $*
if (0!=K2001_POLLTIME) 
  sleep (K2001_POLLTIME)
if ((0==K2001_GPIBCHK)||(S[$1]!=0)) {

  K2001_AVER[$1] += S[$1]
  K2001_NOREADS[$1]++
}
S[$1] = counter_par($1,"scale") * K2001_AVER[$1] / ((K2001_NOREADS[$1] == 0)?1:K2001_NOREADS[$1])}' 

global K2001_FAST K2001_NOAVERAGE

def k2001_getcounts '
{
local spl ind ii1 ii2 junk
split("$1",spl,"_")
ind=sprintf("D%dC%d",spl[1]-1,((spl[2]==0)?1:spl[2])-1)
if ($3!=-1) {
  if (spl[2] == 1) {
    k2001_open $*
    }
  k2001_close $*
  }
if (!K2001_FAST) {
  gpib_put($2,K2001_MEAS[ind])
  sleep(0.1)
}
gpib_put($2,":fetch?\n")
ii1= "INEEDSOMECHARHERE" gpib_get($2) 
sscanf(ii1,"%[A-Z]%g",junk,ii2)

S[$1] = counter_par($1,"scale")*ii2*K2001_RATIO[ind]
}'

def k2001_postcount ' 
# S[sec]=1000
_xx=$1
'

def k2001_precount ' 
_xx=$1 
K2001_AVER[$1] = 0; K2001_NOREADS[$1] = 0
'
#%MACROS%
#%IMACROS%
#%ATTENTION%
# The k2001 offers many possiblities and is therefore very difficult
# to program. There are other version of this files. If you would like
# to read the internal buffer of the K2001, you have to configure 
# the K2001 as a MCA in Spec.  
#%DEPENDENCIES%
# The file k2001.mac has to be read in          !done by: startup script
#    (this file needs: cpseudo.mac hook.mac stchanges.mac)
#%AUTHOR%
# JK/SL 11.93
#%TOC%