esrf

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

#%TITLE% frelon.mac
#%NAME%
#   Frelon CCD-camera control macros. OBSOLETE
#%CATEGORY%  Detection, ccd, Obsolete
#%DESCRIPTION% 
# That Frelon CCD Camera delivers images through the SDV bus. The Camera is controlled (start, stop, preset...) through the Serial Line. The maximum presetable exposure time is 1.7 second, but you can easily overcome that limit by hard-gating the camera, eventually coupled to a shutter,  with the Vct6 Timer. This is automatically done from standard scans command and general camera commands.
#%BR%%BR%%B%See also %{%<a HREF=camera_doc.html>camera.mac</a>%}%.%B%
#%SETUP% The work station must be a Sun Solaris. %BR%
#%DL% SPEC config must declare:
#%DD% CCD-like device type SDV Digital Camera Interface.
#%DD% SERIAL interface to which the camera control box is connected, 9600 Baud, raw mode. 
#%XDL%
#%END%

#%UU% [serline] [sleep] [expos] [prefix] [vct6]
#%MDESC% Set up the camera and the macros.
#%PRE%
# [serline]: configured serial line number in spec config.
# [sleep]:   sleep time for serial line output in ms.
# [expos]:   exposure time in s.
# [prefix]:  file prefix to store images.
# [vct6]:    vct6 channel device server name.  
#%PRE% 
# That camera is then addressable from scans and standard camera commands. see %B%camera.mac%B%
def f3setup '{
 global F3_TIME F3_LINE F3_SLEEP F3_PREFIX F3_VCT6
 
  if ($#) {
    F3_LINE = $1
    F3_SLEEP = $2
    F3_TIME = $3
    F3_PREFIX = "$4"
    F3_VCT6 = "$5"
  } else {
    F3_LINE = getval("Spec serial line for the F3 camera (0..)",F3_LINE)
    F3_SLEEP = getval("Sleep time for Serial line output[ms]",F3_SLEEP)
    F3_TIME = getval("Exposure time [ms]",F3_TIME)
    F3_PREFIX = getval("File Prefix",F3_PREFIX)
    F3_VCT6 = getval("Vct6 device name to gate the shutter",F3_VCT6)
  }

  ser_par(0,"timeout",0.15)

  f3settime F3_TIME/1000
  f3_vct6init 
  f3_init
  
  cam_define (F3_PREFIX,"f3_vct6start","f3_vct6stop")
}'

#%IU%
#%MDESC% Starts counting on the Vct6.
def f3_vct6start '{
esrf_io(F3_VCT6,"DevCntStart")
}'

#%IU%
#%MDESC% Stops counting on the Vct6.
def f3_vct6stop '{
esrf_io(F3_VCT6,"DevCntStop")
}'


#%IU%
#%MDESC% Flushes data away from the serial line.
def f3_flush ' {
  if (F3_SLEEP) sleep (F3_SLEEP/1000)
  for (end="NO";end != "" ; end = ser_get(F3_LINE)) sleep (.02) 
}'


#%UU% [exposure]
#%MDESC% Presets the camera exposure time. 
#%BR% Maximum is 1.7 seconds. 
def f3settime '{

  global F3_oldival
  local exposure

  if ($#) exposure = int($1/.41*1000)
  else exposure = int(getval("time in sec",F3_TIME)/.41*1000)

  if (exposure > 4095) {
    print "FRELON Camera only allows time up to 1.7s"
    exit
  }
  if (F3_oldival != exposure) {
    F3_oldival = exposure
    ser_put(F3_LINE,sprintf("I%d\r\n",exposure));    sleep(1)
    f3_flush;    sleep(1)
  }
}'

# Use VCT6 for simple gate start /stop control
#%IU%
#%MDESC% Sets the vct6 to gate out the camera.  
def f3_vct6init '{

local vct_init

vct_init[0]=0 ; vct_init[1]=0 ; vct_init[2]=0 ; vct_init[3]=0
vct_init[4]=0 ; vct_init[5]=0 ; vct_init[6]=0 

esrf_io(F3_VCT6,"DevCntInit",vct_init)
esrf_io(F3_VCT6,"DevCntPresetValue",1e9)
}'

#%IU%
#%MDESC% Sets the camera in one by one image mode
def f3_init '{
  ser_put(F3_LINE,"a\r\n"); f3_flush;  sleep(1)
  ser_put(F3_LINE,"N1\r\n"); f3_flush; sleep(1)
  ser_put(F3_LINE,"T0\r\n"); f3_flush; sleep(1)
}'


#%UU%
#%MDESC% Frelon Menu to talk directly to the camera controller. A lot of parameters can be configured this way.
def f3menu '{
  for (;;) {
    if ((ch = input(-1)) != "") {
      if (ch == "\n") {
        ser_put(F3_LINE,"\r\n") 
      } else if  (ch == "~") {
        f3live
        ser_put(F3_LINE, "\r\n")
      } else {
        ser_put(F3_LINE,ch)
      }
    }
    printf("%s",ser_get(F3_LINE))
  }
}'


#%UU%
#%MDESC% Reads in images one by one in an endless loop. hit "~" key to exit, or control-C.
def f3live ' {
 for (;;) {
   if ((ch = input(-1)) != "") {
     if (ch == "~") {
       break
     }
   }
   oldtime = time()
   f3takemem
   printf("\r%5.2f",1/(time()-oldtime))
 }
}'


#%UU%
#%MDESC% Reads in one image.
def f3takemem '{
  image_par("start",0)
  ser_put(F3_LINE,"S\r\n");#  f3_flush
  image_get(0,image_data)
  ser_get(F3_LINE)
  if (image_par("lasterror")) {
    printf("\n\nTIMEOUT\n"  )
  }
}'

#%UU%
#%MDESC% Sets the camera up using a special configuration file.
def f3sendfile '{
  global F3_PNAME
  local line

  if ($#) F3_PNAME = "$1"
  else F3_PNAME = getval("Enter config filename",F3_PNAME)

  if (getline (F3_PNAME,"open") == "-1") {
    printf("Could not open your file: %s\n",F3_PNAME)
    exit
  }   

  for (;(line = getline (F3_PNAME)) != "-1";) {
    line = substr(line,1,length(line)-1)
    ser_put(F3_LINE,sprintf("%s\r\n",line))
    printf("*********%s***********\n",line)
    sleep(1)
    f3_dump
  }
  getline (F3_PNAME,"close")
}'

#%IU% 
#%MDESC% Flushes data away from the serial line and prints out those data.
def f3_dump ' {
  if (F3_SLEEP) sleep (F3_SLEEP/1000)
  for (end="NO";end != "" ; end = ser_get(F3_LINE))
    if (end != "NO") printf("%s",end)
  sleep (.05) 
}'

#%MACROS%
#%IMACROS%
#%DEPENDENCIES%
#%PRE%
#  - The file %B%frelon.mac%B% has to be read in
#    it uses: %B%camera.mac%B%
#%PRE%
#%AUTHOR%
# FRELON.MAC - ICNTL - February 1996
#%PRE%
# Changed 96/3/27 to use the more general camera.mac features.
#%PRE%
#%TOC%