esrf

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

#%TITLE% BEAMCHECK.MAC
#%NAME% Checks for beam presence
#%CATEGORY% x-ray beam
#
#%END%

#%UU% [counter-mne] [count-time] [count-threshold] [sleeptime]
#
def beamchecksetup '
global BCHK_CNT_MNE BCHK_CNT_TIME BCHK_CNT_THRESHOLD BCHK_SLEEP BCHK_BEAM
global BCHK_SETUP BCHK_ON
{
   if($# > 4) {
      print "Usage beamchecksetup [counter-mne] [count-time] [count-threshold] [sleeptime]"
      exit
   }
   if ($# >= 1) BCHK_CNT_MNE = $1
   else BCHK_CNT_MNE = getval("Counter mnemonic", BCHK_CNT_MNE)
   if ($# >= 2) BCHK_CNT_TIME = $2
   else BCHK_CNT_TIME = getval("Count time [s]", BCHK_CNT_TIME)
   if ($# >= 3) BCHK_CNT_THRESHOLD = $3
   else BCHK_CNT_THRESHOLD = getval("Threshold", BCHK_CNT_THRESHOLD)
   if ($# >= 4) BCHK_SLEEP = $4
   else BCHK_SLEEP = getval("Sleep time [s]", BCHK_SLEEP)
   BCHK_SETUP = 1
   BCHK_ON = 0
}
'

#%UU%
def beamcheckon '
global BCHK_SETUP BCHK_ON
   if (!BCHK_SETUP) {
      print "You did not setup the beamcheck (macro beamchecksetup)."
      exit
   } else {
      BCHK_ON = 1
      print ("Beamcheck is ON now.")
   }
'

#%UU%
def beamcheckoff '
global BCHK_CNT_MNE BCHK_CNT_TIME BCHK_CNT_THRESHOLD BCHK_SLEEP
global BCHK_SETUP BCHK_ON

   BCHK_ON = 0
   print ("Beamcheck is OFF now.")
   
'

def beamcheck '
global BCHK_CNT_MNE BCHK_CNT_TIME BCHK_CNT_THRESHOLD BCHK_SLEEP
global BCHK_SETUP BCHK_ON
   if (BCHK_ON) {
      count_em BCHK_CNT_TIME; waitcount; get_counts
      if (S[cnt_num(BCHK_CNT_MNE)] >= BCHK_CNT_THRESHOLD) {
         BCHK_BEAM = 1
      } else {
         BCHK_BEAM = 0
      }
   }
   printf("Beam is %s (%d)\n", BCHK_BEAM?"on":"off", S[cnt_num(BCHK_CNT_MNE)])
'


def beampoll '
{
   if (BCHK_ON) {
      beamcheck
      if (!BCHK_BEAM) {
         while (!BCHK_BEAM) {
            printf("\rWaiting for beam...")
            sleep(BCHK_SLEEP)
            beamcheck
         }
         printf("ok\n")
      }
   }
}
'

BCHK_SETUP = 0