esrf

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

#$Log: wika.mac,v $
#Revision 1.4  2002/11/06 15:01:14  beteva
#fixed bugs (AB)
#
#Revision 1.3  2002/03/07  16:53:51  16:53:51  beteva (Antonia Beteva)
#added pseudo-counter. Changed from macros to functions.
#
#Revision 1.2  98/07/22  10:22:59  10:22:59  icntl (Instrument Control Account)
#added new functionalities (A.Beteva)
#
#Revision 1.1  97/10/28  15:07:03  15:07:03  beteva (Antonia Beteva)
#Initial revision
#
#%TITLE% WIKA.MAC
#%NAME%
#  %B%wika.mac%B% - macros to control the WIKA Pressure Indicator
#%DESCRIPTION%
# The %B%RS232%B% serial interface allows remote reading and programming the
# Pressure Indicator. 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 serial line interface card
# COMU 2000 (COMU 30), known as IBAM. A "device server" called SerialLine
# should be running in the VME crate, where the IBAM is. The configuration
# of the "server" can be found in a the resource file xxxSerilaLine.res,
# where xxx is the name of the crate (i.e. d291, id011 ...)
#%END%

#%UU% <serial line number (i.e. 0) counter_mnemonic>
#%MDESC% Establishes the communication with the Indicator. The input
#parameter is the ordinal number of the serial line device (starting from 0),
#as assigned in the %B%config%B% file. The %B%counter_mnemonic%B% is
#needed for the reading during a count.
def wika_setup '{
global SER_LINE WIKA_MNE

if ($# == 2) {
  SER_LINE = $1
  WIKA_MNE = "$2"
 } else {
  SER_LINE = getval("Serial line number (starting from 0):",SER_LINE)
  WIKA_MNE = getval("Wika pseudo counter mnemonic",WIKA_MNE)
 }
}'

#%UU% 
#%MDESC% Configure the reading of the pessure into the counters reading.
def wika_on '{
cdef ("user_getcounts",";wika_read;",WIKA_MNE,2)
}'

#%UU% 
#%MDESC% removes all the macros and definitions for the WIKA Pressure Indicator
def wika_off '{
cdef ("","",WIKA_MNE,"delete")
}'

#%IU% ()
#%MDESC% Generic read information from the controller. Return the value or
#-10000 if read error
def _wika_read(_quest) '{
local val ser_asw
  if (ser_put(SER_LINE,_quest) != -1) {
     ser_asw = ser_get(SER_LINE,"\r")
     if (ser_asw == 0)
       return (-10000)
     else {
       val = substr(ser_asw, 6)
       return (val)
      }
    } else
      return (-10000)
}'

#%UU%
#%MDESC% Reads the pressure [bars]
def wika_read '{
local _press _quest
  if (_check_sl() < 0)
    exit

  _quest = "RREAL\r"
  _press = _wika_read(_quest)
   if (_press == -10000)
      printf ("No answer from the serial line\n")
   else {
      printf ("The pressure is %.2f bars\n", _press)
      S[cnt_num(WIKA_MNE)] = _press
     }
}'

#%UU%
#%MDESC% Reads the minimum pressure [bars]
def wika_read_min '{
local val _quest

  if (_check_sl() < 0)
    exit

   _quest = "RMINM\r"
   val = _wika_read(_quest)
   if (val == -10000)
     printf ("No answer from the serial line\n")
   else
     printf ("The minimum pressure is %.3f bars\n", val)
}'

#%UU%
#%MDESC% Reads the maximum pressure [bars]
def wika_read_max '{
local val _quest

  if (_check_sl() < 0)
    exit

   _quest = "RMAXM\r"
   val = _wika_read(_quest)
   if (val == -10000)
     printf ("No answer from the serial line\n")
   else
     printf ("The maximum pressure is %.3f bars\n", val)
}'

#%IU% (val1,val2)
#%MDESC% Checks the set limit macros input values.
def _wika_check_limits(val1,val2) '{
local val_a val_e _quest

  if (((val1 - val2 - 0.5) || (val1 + val2 + 0.5)) > 9999) {
    printf("Out of the limits, please give smaller offset or setpoin.\n")
    exit
   }

  if (_check_sl() < 0)
    exit

  _quest = "RSCLA\r"
  val_a = _wika_read(_quest)
  if (val_a == -10000) {
    printf ("Problem reading the serial line, exiting...\n")
    exit
   }

  _quest = "RSCLE\r"
  val_e = _wika_read(_quest)
  if (val_e == -10000) {
    printf ("Problem reading the serial line, exiting...\n")
    exit
   }

  if (((val1 - val2 - 0.5) < val_a) || ((val1 + val2 + 0.5) > val_e)) {
    printf ("Out of the limits, please give smaller offset\n")
    exit
   }
}'

#%UU% [setpoint offset]
#%MDESC% puts pressure limits [bars] when the setpoint is lower than the
#current pressure %BR%
# 1E.........1A.........SP.........2A.........2E%BR%
# |<-offset->|<-offset->|<-offset->|<-offset->|
def wika_set_limit_down '{
local setpoint w_offset
local val _quest

  if (_check_sl() < 0)
    exit
 if ($# < 2) {
    setpoint = input("setpoint [bars]:")
    w_offset = input("offset [%]:")
   } else {
    setpoint = $1
    w_offset = $2
   }

 _wika_check_limits(setpoint,w_offset)

 _quest = "RREAL\r"
 val = _wika_read(_quest)
 if (val == -10000) {
   printf ("Error reading the serial line, exiting...\n")
   exit
  } else {
    S[cnt_num(WIKA_MNE)] = val
    if (val < setpoint) {
      printf("The pressure is lower than the setpoint. Use wika_set_limit_up instead\n")
      exit
     }
  }

 _format_string(setpoint - 2*w_offset)
 _quest = sprintf ("PST1E%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
   printf("Cannot set the desired value - serial line problem\n")
   exit
  }
 printf ("Lower limit min value is %.1f bars\n", val)

 _format_string(setpoint - w_offset)
 _quest = sprintf ("PST1A%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
   printf("Cannot set the desired value - serial line problem\n")
   exit
  }
 printf ("Lower limit max value is %.1f bars\n", val)

 _format_string(setpoint + w_offset)
 _quest = sprintf ("PST2A%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
   printf("Cannot set the desired value - serial line problem\n")
   exit
  }
 printf ("Upper limit min value is %.1f bars\n", val)

 _format_string(setpoint + 2*w_offset)
 _quest = sprintf ("PST2E%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
   printf("Cannot set the desired value - serial line problem\n")
   exit
  }
 printf ("Upper limit max value is %.1f bars\n", val)

}'

#%UU% [setpoint offset]
#%MDESC% puts pressure limits [bars] when the setpoint is higher than the
#current pressure %BR%
# 1E.........1A.........SP.........2A.........2E%BR%
# |<-offset->|<-offset->|<-offset->|<-offset->|
def wika_set_limit_up '{
local val setpoint w_offset _quest

  if (_check_sl() < 0)
    exit

 if ($# == 2) {
    setpoint = $1
    w_offset = $2
  } else {
    setpoint = input("setpoint [bars]:")
    w_offset = input("offset [%]:")
  }

 _wika_check_limits(setpoint,w_offset)
 _quest = "RREAL\r"
 val = _wika_read(_quest)
 if (val == -10000) {
   printf ("Error reading the serial line, exiting...\n")
   exit
  } else {
    S[cnt_num(WIKA_MNE)] = val
    if (val > setpoint) {
      printf("The pressure is higher than the setpoint. Use wika_set_limit_down instead\n")
      exit
     }
  }

 _format_string(setpoint + 2*w_offset)
 _quest = sprintf ("PST2E%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
    printf("Cannot set the desired value - serial line problem\n")
    exit
  }
 printf ("Upper limit max value is %.1f bars\n", val)

 _format_string(setpoint + w_offset)
 _quest = sprintf ("PST2A%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
    printf("Cannot set the desired value - serial line problem\n")
    exit
  }
 printf ("Upper limit min value is %.1f bars\n", val)

 _format_string(setpoint - w_offset)
 _quest = sprintf ("PST1A%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
    printf("Cannot set the desired value - serial line problem\n")
    exit
  }
 printf ("Lower limit max value is %.1f bars\n", val)

 _format_string(setpoint - 2*w_offset)
 _quest = sprintf ("PST1E%s\r", _F_STRING)
 val = _wika_read(_quest)
 if (val == -10000) {
    printf("Cannot set the desired value - serial line problem\n")
    exit
  }
 printf ("Lower limit min value is %.1f bars\n", val)
}'

#%IU% ()
#%MDESC% Check if the serial line is configured (return 0) or not (return -1).
def _check_sl() '{
  if (SER_LINE == 888) {
    printf("The serial line is not attributed.\nExecute wika_on first.\n")
    return(-1)
   }
  return(0)
}'

#%IU% (val)
#%MDESC% Format a string.
def _format_string(val) '{
global _F_STRING
if (val < 10)
  _F_STRING = sprintf ("+00%1.1f", val)
else if (val < 100)
  _F_STRING = sprintf ("+0%2.1f", val)
else if (val < 1000)
  _F_STRING = sprintf ("+%3.1f", val)
else
  _F_STRING = sprintf ("%4.1f", val)
}'

#%MACROS%
#%IMACROS%
#%AUTHOR% A.Beteva %BR%
#$Revision: 1.4 $, $Date: 2002/11/06 15:01:14 $
#%TOC%