esrf

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

#%TITLE% MCCE.MAC
#%NAME%
#    MCCE (Module de Command et Control des Electrometres) macros
#
#%CATEGORY% Other hardware
#
#%DESCRIPTION%
#The %B%RS422%B% serial interface allows remote reading and programming the
#MCCE. The parameters of the serial line are:%BR%
#		- 8 bits%BR%
#		- no parity%BR%
# 		- 1 stop bit%BR%
#		- 9600 bauds%BR%
#%SETUP%
#The serial line cable is connected to the interface card - either COMU
#2000 (COMU 30), known as IBAM (os9) or RocketPort (linux).
#There should be a "serial line" device servre running, on top of which a
#linux device server Mcce should run as well. Tha macro calles the Mcce device
#server commands only.
#%END%

#%UU% 
#%MDESC% Define all the globals and macros. This is the first macro to
#be executed, when using MCCE.
def mcce_init '{
global MCCE_DEV MCCE_NO MCCE_SETUPOK
global MCCE_TYPE MCCE_RANGE MCCE_FREQ MCCE_GAIN MCCE_POL
global MCCE_RANGE_LIST MCCE_FREQ_LIST MCCE_GAIN_LIST MCCE_RANGE_UNIT
global MCCE_RANGE_NB MCCE_FREQ_NB MCCE_GAIN_NB MCCE_SLEEP MCCE_OK
global MCCE_NAMES

  MCCE_RANGE_LIST[1][0] = 1e-11
  MCCE_RANGE_LIST[1][1] = 3e-11
  MCCE_RANGE_LIST[1][2] = 1e-10
  MCCE_RANGE_LIST[1][3] = 3e-10

  MCCE_RANGE_LIST[2][0] = 1e-10
  MCCE_RANGE_LIST[2][1] = 3e-10
  MCCE_RANGE_LIST[2][2] = 1e-09
  MCCE_RANGE_LIST[2][3] = 3e-09
  MCCE_RANGE_LIST[2][4] = 1e-08
  MCCE_RANGE_LIST[2][5] = 3e-08
  MCCE_RANGE_LIST[2][6] = 1e-07
  MCCE_RANGE_LIST[2][7] = 3e-07

  MCCE_RANGE_LIST[3][0] = 1e-08
  MCCE_RANGE_LIST[3][1] = 3e-08
  MCCE_RANGE_LIST[3][2] = 1e-07
  MCCE_RANGE_LIST[3][3] = 3e-07
  MCCE_RANGE_LIST[3][4] = 1e-06
  MCCE_RANGE_LIST[3][5] = 3e-06
  MCCE_RANGE_LIST[3][6] = 1e-05
  MCCE_RANGE_LIST[3][7] = 3e-05

  MCCE_RANGE_LIST[4][0] = MCCE_RANGE_LIST[5][0] = 30
  MCCE_RANGE_LIST[4][1] = MCCE_RANGE_LIST[5][1] = 100
  MCCE_RANGE_LIST[4][2] = MCCE_RANGE_LIST[5][2] = 300
  MCCE_RANGE_LIST[4][3] = MCCE_RANGE_LIST[5][3] = 1000

  MCCE_RANGE_LIST[6][0] = 1e-10
  MCCE_RANGE_LIST[6][1] = 1e-09
  MCCE_RANGE_LIST[6][2] = 1e-08
  MCCE_RANGE_LIST[6][3] = 1e-07

  MCCE_RANGE_NB[1] = 4
  MCCE_RANGE_NB[2] = MCCE_RANGE_NB[3] = 8
  MCCE_RANGE_NB[4] = MCCE_RANGE_NB[5] = MCCE_RANGE_NB[6] = 4

  MCCE_RANGE_UNIT[1] = MCCE_RANGE_UNIT[2] = MCCE_RANGE_UNIT[3] = \
  MCCE_RANGE_UNIT[6] = "Amper CC"
  MCCE_RANGE_UNIT[5] = "KOhm"
  MCCE_RANGE_UNIT[4] = "MOhm"

  MCCE_GAIN_LIST[4][0] = MCCE_GAIN_LIST[5][0] = 1
  MCCE_GAIN_LIST[4][1] = MCCE_GAIN_LIST[5][1] = 10
  MCCE_GAIN_LIST[4][2] = MCCE_GAIN_LIST[5][2] = 100
  MCCE_GAIN_NB = 3

  MCCE_FREQ_LIST[1][0] = MCCE_FREQ_LIST[2][0] = MCCE_FREQ_LIST[3][0] = \
  MCCE_FREQ_LIST[6][0]= 3
  MCCE_FREQ_LIST[1][1] = MCCE_FREQ_LIST[2][1] = MCCE_FREQ_LIST[3][1] = \
  MCCE_FREQ_LIST[6][1] = 10
  MCCE_FREQ_LIST[1][2] = MCCE_FREQ_LIST[2][2] = MCCE_FREQ_LIST[3][2] = \
  MCCE_FREQ_LIST[6][2] = 100
  MCCE_FREQ_LIST[1][3] = MCCE_FREQ_LIST[2][3] = MCCE_FREQ_LIST[3][3] = \
  MCCE_FREQ_LIST[6][3] = 1000
  MCCE_FREQ_NB = 4

}'

#%UU% [<first electrometer device server name> (<second electrometer device server name>...)]
#%MDESC% Establish communication with the MCCE(s). The device server name is in
#database format (e.g. id00/e1/ch1).
def mccesetup '{
local ch

  MCCE_SETUPOK = 0

  if ($#) {
    MCCE_NO = split ("$*",MCCE_DEV)
  } else {
    MCCE_NO = getval("How many electrometer channels",MCCE_NO)
    for (ch=0;ch<MCCE_NO;ch++)
      MCCE_DEV[ch]=getval(sprintf("Device name for ch. #%d",ch+1),MCCE_DEV[ch])
  }

  MCCE_SETUPOK = 1
  MCCE_SLEEP = 0.5
  mccestat
}'

def mccesetup_names '{
  local _ans

  unglobal MCCE_NAMES
  global MCCE_NAMES

  if ($#) {
    _ans = split ("$*", MCCE_NAMES)
    if (_ans != MCCE_NO ){
      print "MCCE - mccesetup_name- Warning : number of mcce and number of names do not match"
    }
  } else {
    print "no interactive setup_names for now... sorry."
  }
}'

#%UI% (elnb)
#%MDESC% Print the parameters of the %B%elnb%B% electrometer.
def _mccestat(elnb) '{
local ret

  MCCE_OK[elnb] = 0
  ret = _mcce_type(MCCE_DEV[elnb])
  if (ret == -1) {
    MCCE_OK[elnb] = -1
    return(ret)
  }
  MCCE_TYPE[elnb]= ret
  sleep(MCCE_SLEEP)
  MCCE_RANGE[elnb] = _mcce_getrange(MCCE_DEV[elnb])
  if (MCCE_TYPE[elnb] == 4) {
    MCCE_RANGE[elnb] /= 1000000
    sleep(MCCE_SLEEP)
    MCCE_GAIN[elnb] = _mcce_getgain (MCCE_DEV[elnb])
  } else {
    MCCE_GAIN[elnb] = 1
    sleep(MCCE_SLEEP)
    MCCE_FREQ[elnb] = _mcce_getfreq (MCCE_DEV[elnb])
  }
  sleep(MCCE_SLEEP)
  MCCE_POL[elnb]= _mcce_getpolarity(MCCE_DEV[elnb])
}'

#%UU% [<electrometer number> ...]
#%MDESC% Print parameters of the electrometers. If no argument given, the
#macro will print information about all configured electrometers. The input
#parameter can be one or more electrometer numbers (as specified when
#mccesetup executed).
def mccestat '{
local inp i ch

  if ($# == 0) {
    for (ch=0; ch<MCCE_NO; ch++) {
      printf ("electrometer #%d [device: %s]\n", ch+1, MCCE_DEV[ch])
      if (_mccestat(ch) == -1)
        eprintf("cannot read parametes, electrometer disabled\n")
      else {
        printf ("type     : %d\n", MCCE_TYPE[ch])
        if (MCCE_TYPE[ch] == 4)
          printf ("gain     : %d\n", MCCE_GAIN[ch])
        else
          printf ("frequency: %d Hz\n", MCCE_FREQ[ch])
        printf ("range    : %s %s\n",MCCE_RANGE[ch], \
		MCCE_RANGE_UNIT[MCCE_TYPE[ch]])
        printf ("polarity : %s\n", MCCE_POL[ch])
      }
    }
  } else {
    split ("$*", inp)
    for (ch=0; ch<$#; ch++) {
      ch = inp[i]-1
      if (_mcce_chk(ch+1) == -1)
        continue
      printf ("electrometer #%d [device: %s]\n", ch+1, MCCE_DEV[ch])
      if (_mccestat(ch) == -1)
        eprintf("cannot read parametes, electrometer disabled\n")
      else {
        printf ("type     : %d\n", MCCE_TYPE[ch])
        if (MCCE_TYPE[inp[i]-1] == 4)
          printf ("     gain: %d\n", MCCE_GAIN[ch])
        else
          printf ("frequence: %d Hz\n", MCCE_FREQ[ch])
        printf ("range    : %s %s\n",MCCE_RANGE[ch], \
	    	  MCCE_RANGE_UNIT[MCCE_TYPE[ch]])
        printf ("polarity : %s\n", MCCE_POL[ch])
      }
    }
  }
}'

#%UU% [<electrometer number> <range> <electrometer number> <range> ...]
#%MDESC% Set the %B%range%B% of the electrometers. This macro follows a
#procedure to change the range. Different scales are possible, depending on
#the electrometer type. The %B%electrometer number%B% cannot exceed the
#configured number of electrometers, but it does not need to be in
#consecutive order, if more then one. When no arguments, the macro will ask
#for confirmation for all the available electrometers.
def mccerange '{
local inp ch i ii range

  if ($# == 0) {
    for (ch=0; ch<MCCE_NO; ch++) {
      if (_mcce_chk(ch+1) == -1)
        continue
      printf ("Range for electrometer #%d [", ch+1)
      for (i=0;i<MCCE_RANGE_NB[MCCE_TYPE[ch]];i++)
	printf (" %s",MCCE_RANGE_LIST[MCCE_TYPE[ch]][i])
      range = getval (sprintf (" ] "), MCCE_RANGE[ch])
      if (range == MCCE_RANGE[ch])
	printf ("Range %g already set, nothing done\n", range)
      else {
        if (_mcce_chkrange (ch, range) < 0) {
          printf ("Invalid input, allowed values are:\n")
          for (i=0;i<MCCE_RANGE_NB[MCCE_TYPE[ch]];i++)
            printf (" %s",MCCE_RANGE_LIST[MCCE_TYPE[ch]][i])
          printf("\n")
          ch--
	} else {
          if (_mcce_setrange (MCCE_DEV[ch], range) < 0)
            printf ("Range not changed\n")
          else {
            MCCE_RANGE[ch] = _mcce_getrange(MCCE_DEV[ch])
            if (MCCE_RANGE[ch] != 0) {
              if (MCCE_TYPE[ch] == 4)
                MCCE_RANGE[ch] /= 1000000
              printf("New range for electrometer #%d [%s]: %s %s\n", ch+1, \
		MCCE_DEV[ch], MCCE_RANGE[ch], MCCE_RANGE_UNIT[MCCE_TYPE[ch]])
            }
          }
        }
      }
    }
  } else {
    split ("$*", inp)
    for (i=0; i<$#/2; i++) {
      ch = inp[2*i] - 1
      range = inp[2*i + 1]
      if (_mcce_chk(ch+1) == -1)
        continue
      if (range == MCCE_RANGE[ch])	
	printf ("Range %d already set, nothing done\n", range)
      else if (_mcce_chkrange (ch, range) < 0) {
        printf ("Invalid input, allowed values are:\n")
        for (ii=0; ii<MCCE_RANGE_NB[MCCE_TYPE[ch]]; ii++)
	  printf (" %s",MCCE_RANGE_LIST[MCCE_TYPE[ch]][ii])
      } else {
	MCCE_RANGE[ch] = range
        if (_mcce_setrange(MCCE_DEV[ch], MCCE_RANGE[ch]) < 0)
          eprintf ("Range not changed\n")
	else {
          MCCE_RANGE[ch] = _mcce_getrange (MCCE_DEV[ch])
          if (MCCE_RANGE[ch] != 0) {
            if (MCCE_TYPE[ch] == 4)
	      MCCE_RANGE[ch] /= 1000000
            printf("New range for electrometer #%d (%s) : %s %s\n", ch+1, \
		MCCE_DEV[ch], MCCE_RANGE[ch], MCCE_RANGE_UNIT[MCCE_TYPE[ch]])
	  }
        }
      }
    }
  }
}'

#%UU% [<electrometer number> <polarity> <electrometer number> <polarity> ...]
#%MDESC% Set the polarity of the electrometers. This macro follows a procedur
#(several MCCE commands executed). The electrometer number cannot exceed the
#configured number of electrometers, but it does not need to be in consecutive
#order. When no arguments, the macro asks for confirmation for all the
#available electrometers. Allowed input + or -.
def mccepolarity '{
local inp ch i pol

  if ($# == 0) {
    for (ch=0; ch<MCCE_NO; ch++) {
      if (_mcce_chk(ch+1) == -1)
        continue
      MCCE_POL[ch]=getval(sprintf("Polarity sign for electrometer #%d (%s)", \
			ch+1, MCCE_DEV[ch]), MCCE_POL[ch])
      if ((MCCE_POL[ch] != "+") && (MCCE_POL[ch] != "-")) {
	printf ("Allowed input + or -\n")
        ch--
      } else {
        if (_mcce_setpolarity (MCCE_DEV[ch], MCCE_POL[ch]) < 0)
          eprintf ("Error - cannot change the polarity\n")
        else {
          MCCE_POL[ch] = _mcce_getpolarity(MCCE_DEV[ch])
	  if (MCCE_POL[ch] != 0)
            printf("New polarity for electrometer #%d (%s) : %s\n", ch+1, \
	            MCCE_DEV[ch], MCCE_POL[ch])
        }
      }
    }
  } else {
    split ("$*", inp)
    for (i=0; i<$#/2; i++) {
      ch = inp[2*i] - 1
      pol = inp[2*i + 1]
      if (_mcce_chk(ch+1) == -1)
        continue
      MCCE_POL[ch] = pol
      if (_mcce_setpolarity(MCCE_DEV[ch], MCCE_POL[ch]) < 0)
        eprintf ("Error - cannot change the polarity\n")
      else{
        MCCE_POL[ch]=_mcce_getpolarity(MCCE_DEV[ch])
        if (MCCE_POL[ch] != 0)
          printf("New polarity for electrometer #%d (%s) : %s\n", ch+1, \
		MCCE_DEV[ch], MCCE_POL[ch])
      }
    }
  }
}'

#%UU% [<electrometer number> <frequency> <electrometer number> <frequency> ...]
#%MDESC% Set the frequency filter of the fotovoltaic electrometers. This macro
#follows a procedure (several MCCE commands executed). The electrometer number
#cannot exceed the configured number of electrometers, but it does not need to
#be in consecutive order. When no arguments, the macro asks for confirmation
#for all the available electrometers.
def mccefreq '{
local inp ch i ii freq

  if ($# == 0) {
    for (ch=0; ch<MCCE_NO; ch++) {
      if (_mcce_chk(ch+1) == -1)
        continue
      if ((MCCE_TYPE[ch] == 4) || (MCCE_TYPE[ch] == 5))
        printf ("Electrometer #%d (%s) has no filter, command ignored\n",\
		ch+1, MCCE_DEV[ch])
      else {
	freq = getval(sprintf("Frequency for electrometer #%d (%s)", \
		ch+1, MCCE_DEV[ch]), MCCE_FREQ[ch])
	if (freq == MCCE_FREQ[ch])
	  printf ("Frequence %d already set, nothing done\n", freq)
	else {
	  if (_mcce_chkfreq (ch, freq) < 0) {
	    printf ("Invalid input, allowed values are: ")
            for (i=0; i<MCCE_FREQ_NB; i++)
	      printf (" %s",MCCE_FREQ_LIST[MCCE_TYPE[ch]][i])
            printf("\n")
	    ch--
	  } else {
            if (_mcce_setfreq (MCCE_DEV[ch], freq) < 0)
	      eprintf ("Error - cannot change the frequency\n")
            else {
              MCCE_FREQ[ch] = _mcce_getfreq(MCCE_DEV[ch])
	      if (MCCE_FREQ[ch] != 0)
                printf("New frequency for electrometer #%d (%s) : %s\n", \
			ch+1, MCCE_DEV[ch], MCCE_FREQ[ch])
	    }
	  }
	}
      }
    }
  } else {
    split ("$*", inp)
    for (i=0; i<$#/2; i++) {
      ch = inp[2*i] - 1
      if (_mcce_chk(ch+1) == -1)
        continue
      freq = inp[2*i+1]
      if ((MCCE_TYPE[ch] == 4) || (MCCE_TYPE[ch] == 5))
        printf ("Electrometer #%d (%s) has no filter, command ignored\n",\
		ch+1, MCCE_DEV[ch])
      else {
        if (freq == MCCE_FREQ[ch])
          printf ("Frequence %d already set, nothing done\n", freq)
	else if (_mcce_chkfreq (ch, freq) < 0) {
	  printf ("Invalid input, allowed values are: ")
          for (ii=0; ii<MCCE_FREQ_NB; ii++)
	    printf (" %s",MCCE_FREQ_LIST[MCCE_TYPE[ch]][ii])
        } else {
	  MCCE_FREQ[ch] = freq
	  if (_mcce_setfreq(MCCE_DEV[ch], MCCE_FREQ[ch]) < 0)
	    eprintf ("Error - cannot change the frequency\n")
	  else {
            MCCE_FREQ[ch] = _mcce_getfreq (MCCE_DEV[ch])
            if (MCCE_FREQ[ch] != 0)
              printf("New frequency for electrometer #%d (%s) : %s\n", \
		ch+1, MCCE_DEV[ch], MCCE_FREQ[ch])
          }
	}
      }
    }
  }
}'

#%UU% [<electrometer number> <gain> <electrometer number> <gain> ...]
#%MDESC% Set the gain of the fotoconductive electrometers. This macro
#follows a procedure (several MCCE commands executed). The electrometer number
#cannot exceed the configured number of electrometers, but it does not need to
#be in consecutive order. When no arguments, the macro asks for confirmation
#for all the available electrometers.
def mccegain '{
local inp ch i ii gain

  if ($# == 0) {
    for (ch=0; ch<MCCE_NO; ch++) {
      if (_mcce_chk(ch+1) == -1)
        continue
      if ((MCCE_TYPE[ch] != 4) && (MCCE_TYPE[ch] != 5))
        printf ("Electrometer #%d (%s) has no gain, command ignored\n", \
		ch+1, MCCE_DEV[ch])
      else {
	gain = getval(sprintf("Gain for electrometer #%d (%s)", \
		ch+1, MCCE_DEV[ch]), MCCE_GAIN[ch])
        if (gain == MCCE_GAIN[ch])
          printf ("Gain %d already set, nothing done\n",gain)
	else {
	  if (_mcce_chkgain (ch, gain) < 0) {
	     printf ("Invalid input, allowed values are: ")
             for (ii=0; ii<MCCE_GAIN_NB; ii++)
	       printf (" %s",MCCE_GAIN_LIST[MCCE_TYPE[ch]][ii])
	     printf("\n")
	     ch--
	  } else {
            if (_mcce_setgain (MCCE_DEV[ch], gain) < 0)
	      eprintf ("Error - cannot change the gain\n")
            else {
              MCCE_GAIN[ch] = _mcce_getgain(MCCE_DEV[ch])
	      if (MCCE_GAIN[ch] != 0)
                printf("New gain for electrometer #%d (%s) : %s\n", \
			ch+1, MCCE_DEV[ch], MCCE_GAIN[ch])
	    }
	  }
        }
      }
    }
  } else {
    split ("$*", inp)
    for (i=0; i<$#/2; i++) {
      ch = inp[2*i] - 1
      gain = inp[2*i+1]
      if (_mcce_chk(ch+1) == -1)
        continur
      if ((MCCE_TYPE[ch] != 4) && (MCCE_TYPE[ch] != 5))
        printf ("Electrometer #%d (%s) has no gain, command ignored\n", \
		ch+1, MCCE_DEV[ch])
      else {
        if (gain == MCCE_GAIN[ch])
          printf ("Gain %d already set, nothing done\n",gain)
        else if (_mcce_chkgain (ch, gain) < 0) {
	  printf ("Invalid input, allowed values are: ")
          for (ii=0; ii<MCCE_GAIN_NB; ii++)
	    printf (" %s",MCCE_GAIN_LIST[MCCE_TYPE[ch]][ii])
        } else {
	  MCCE_GAIN[ch] = gain
          if (_mcce_setgain (MCCE_DEV[ch], gain) < 0)
	    eprintf ("Error - cannot change the gain\n")
          else {
            MCCE_GAIN[ch]=_mcce_getgain (MCCE_DEV[ch])
            if (MCCE_GAIN[ch] != 0)
              printf("New gain for electrometer #%d (%s) : %s\n", \
			ch+1, MCCE_DEV[ch], MCCE_GAIN[ch])
	  }
        }
      }
    }
  }
}'

######## internal macros ########
#%IU% (device)
#%MDESC% Change parameters enabled - corresponds to the MCCE front
#pannel key in horizontal position
def _mcce_Mon (device) '{
  return(esrf_io(device,"DevMcceMeasureOn"))
}'

#%IU% (device)
#%MDESC% Change parameters disabled - corresponds to the MCCE front
#pannel key in vertical position
def _mcce_Moff (device) '{
  return(esrf_io(device,"DevMcceMeasureOff"))
}'

#%IU% (device)
#%MDESC%Get the type of the electrometer (values 1-6), -1 if error
def _mcce_type (device) '{
  return (esrf_io(device,"DevMcceGetType"))
}'

#-------- range --------
#%IU% (device, range)
#%MDESC% Change the electrometer range.
def _mcce_setrange (device, range) '{
    return(esrf_io(device,"DevMcceSetRange",sprintf("%s",range)))
}'

#%IU% (device)
#%MDESC% Get the electrometer range.
def _mcce_getrange (device) '{
  return(esrf_io(device,"DevMcceGetRange")+0)
}'

#%IU% (elnb, value)
#%MDESC% Check the %B%elnb%B% range input %B%value%B%.
def _mcce_chkrange (elnb, value) '{
local i

  for (i=0; i<MCCE_RANGE_NB[MCCE_TYPE[elnb]];i++) {
    if (value == MCCE_RANGE_LIST[MCCE_TYPE[elnb]][i])
      return (value)
  }
  return (-1)
}'
#-------- end range --------

#-------- frequency --------
#%IU% (device, freq)
#%MDESC% Change the frequency filter value [Hz] of a fotovoltaic electrometer.
def _mcce_setfreq (device,freq) '{
  return(esrf_io(device,"DevMcceSetFrequency",freq))
}'

#%IU% (device)
#%MDESC% Get the frequency filter value [Hz] of a fotovoltaic electrometer.
def _mcce_getfreq (device) '{
  return(esrf_io(device,"DevMcceGetFrequency"))
}'

#%IU% (elnb, value)
#%MDESC% Check the %B%elnb%B% electrometer frequency filter input %B%value%B%.
def _mcce_chkfreq (elnb, value) '{
local i
  for (i=0; i<MCCE_FREQ_NB;i++) {
    if (value == MCCE_FREQ_LIST[MCCE_TYPE[elnb]][i])
      return(value)
  }
  return(-1)
}'
#-------- end frequency --------

#-------- polarity --------
#%IU% (device, pol)
#%MDESC% Change an electrometer polarity sign
def _mcce_setpolarity (device, pol) '{
  esrf_io(device,"DevMcceSetPolarity",pol)
}'

#%IU% (device)
#%MDESC%Get an electrometer polarity sign
def _mcce_getpolarity (device) '{
  return(esrf_io(device,"DevMcceGetPolarity"))
}'
#-------- end polarity --------

#-------- gain --------
#%IU% (device, gain)
#%MDESC% Change the fotoconductive electrometer gain filter.
def _mcce_setgain (device, gain) '{
  return(esrf_io(device,"DevMcceSetGain",gain))
}'

#%IU% (device)
#%MDESC% Get the fotoconductive electrometer gain filter.
def _mcce_getgain (device) '{
  return(esrf_io(device,"DevMcceGetGain"))
}'

#%IU% (elnb, value)
#%MDESC% Check the %B%elnb%B% electrometer gain input %B%value%B%.
def _mcce_chkgain (elnb, value) '{
local i
  for (i=0; i<MCCE_GAIN_NB; i++) {
    if (value == MCCE_GAIN_LIST[MCCE_TYPE[elnb]][i])
      return(value)
  }
  return(-1)
}'
#-------- end gain --------

#%UI% (elnb)
#%MDESC% Check if %B%elnb%B% electrometer is configured. Retur 0 if OK,
#-1 if error.
def _mcce_chk(elnb) '{
  if (!MCCE_SETUPOK) {
    eprintf("No electrometers configured.\nPlease, execute")
    tty_cntl("so");eprintf ("mccesetup");tty_cntl("se");eprintf(" first.\n")
    return(-1)
  }
  if ((elnb > MCCE_NO) && (elnb != 0)) {
    eprintf("You have asked information about nonconfigured electrometer\n")
    eprintf("Please, change the input or execute")
    tty_cntl("so");eprintf ("mccesetup");tty_cntl("se");eprintf(" first.\n")
    return(-1)
  }
  if (MCCE_OK[elnb-1] == -1) {
    eprintf ("Electrometer %s disabled.\n", MCCE_DEV[elnb-1])
    return(-1)
  }
  return(0)
}'

#%MACROS%
#%IMACROS%
#%AUTHOR%A. Beteva / BLISS%BR%
#$Revision: 2.5 $, $Date: 2009/04/29 13:39:15 $
#%TOC%
#%END%
#%LOG%
#$Log: mcce.mac,v $
#Revision 2.5  2009/04/29 13:39:15  guilloud
#add mccesetup_names macros to give names to mcce channels.
#
#Revision 2.4  2009/01/06 12:47:46  beteva
#added check if no connection with the device server to save time
#
#Revision 2.3  2008/11/27 12:18:19  guilloud
#Some changes to be used with the MCCE Brick.
#
#Revision 2.2  2008/08/12 13:33:41  rey
#documentation changes
#
#Revision 2.1  2007/10/02 12:31:59  guilloud
#remove declaration of unused MCCE_MORE variable.
#
#Revision 2.0  2005/02/11 14:00:12  beteva
#refactored due to the new Mcce linux device server (AB)
#
#Revision 1.7  2000/04/11 19:49:28  icntl
#added set of gain macros (AB)
#
#Revision 1.6  99/08/20  17:39:28  17:39:28  icntl (Instrument Control Account)
#changed the input values check
#
#Revision 1.5  99/07/26  17:30:46  17:30:46  icntl (Instrument Control Account)
#added polarity macros
#
#Revision 1.4  98/07/22  10:18:33  10:18:33  icntl (Instrument Control Account)
#fixed bug in mccefreq macro (A.Beteva)
#
#Revision 1.3  98/06/23  11:01:14  11:01:14  icntl (Instrument Control Account)
#added new functionalities (A.Beteva)