Ezca
index
/home/newville/Codes/epics/Epics-1.2/Ezca.py

#  Ezca: Epics EZCA interface in Python
#
#  Copyright (c) 2000--2002  Matt Newville, The University of Chicago
#
#  email:       newville@cars.uchicago.edu
#
#  versions
#    1.00   initial use, debugging of connect, start/end group
#    1.10   added optional use of Numeric data type, switched
#           build to use distutils, and updated docs
#    1.11   added "type='char'" option to caget to try to force
#           data to be returned as a string.  For many record types 
#           (mbbi, mbbo), this has the added benefit of retrieving
#           the string value for the field.
#           also add "use_char=1" option to initialization, which
#           will set caget to use character strings when appropriate.
#    1.12   improved support for long character arrays (byte-arrays)
#           from Epics string waveform records.  these allow strings
#           longer than 40 characters to be used in Epics records.
#    1.13   changed installation to include Geoff Savage's ca extension,
#           and build windows extensions.
#    1.14   improved behavior of caput(....,wait=1) so that it works.
#           caget() on an unconnected pv nows set the status to -99.
#    1.15   fixed bug in use of Numeric arrays in caput
#
#    1.20   changed layout/strategy by adding a PV class that does most
#           data exchange for an individual PV. The Ezca class is now
#           built as a dictionary of PVs, so that caget()/caput() are
#           nearly trivial calls to those from the PV class.
#
#           In addition (or, because of this change), monitors can now
#           have callback functions ...  in this approach a user-supplied
#           python function can be defined that will be called by
#           CheckMonitor() if and only if the value has changed.  The
#           supplied function should support keyword arguments, as the
#           argument 'pv' will have the PV instance.  Note that the new
#           value is not set by CheckMonitor() -- this would be the
#           responsibility of the callback... examples to come.
#
#           added Ezca.Check_All_Monitors() to call PV.CheckMonitor()
#           on all monitored PVs
#
#   last update: 09-Feb-2003
#

 
Modules
            
string
types
 
Classes
            
Command
Ezca
PV
 
class Command
       Generic Command execution... enhanced lambdas
x = Command(func, args, kw)
x(args,kw)
 
   Methods defined here:
__call__(self, *args, **kw)
__init__(self, func, *args, **kw)

Data and non-method functions defined here:
__doc__ = ' Generic Command execution... enhanced lambdas\n x = Command(func, args, kw)\n x(args,kw)'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
__module__ = 'Ezca'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
 
class Ezca
      Ezca: Epics EZCA interface in Python
 
example:
   import Ezca
   ez = Ezca.Ezca(timeout = 0.001, retrycount=20)
   x = ez.caget('XX:m1.VAL')
 
The Ezca class provides an interface to the EPICS Ezca library
from Python. The supported functions are:
 
   caput(pv,val)      :  set a PV value
   caget(pv)          :  get a PV value
   getpv(pv, options) :  enhanced PV get (see doc below)
   set_debug()        :  set debug flag
   show_config        :  show configuration of Ezca instance.
   get_status         :  return last Ezca exit status
   connect            :  connect to a pv, saving count,type in local cache
   use_numeric        :  set the use of Numeric Python arrays for array types
   GetCountAndType    :  return PV count and _python_ type
   GetNelem           :  return PV count
   GetStatus          :  Get time, status, and severity for a PV
   GetUnits           :  return units of a PV
   GetPrecision       :  return precision of a PV
   SetMonitor         :  set a PV monitor
   ClearMonitor       :  unset a PV monitor
   CheckMonitor       :  check status of a PV monitor
   StartGroup         :  start a group of efficient Ezca calls
   EndGroup           :  end a group of efficient Ezca calls
   delay              :  set an Ezca time delay
 
instance options for:
   import Ezca
   ez = Ezca.Ezca(option=value, ....)
 
   Several optional arguments can be given to affect the 
   behavior of the Ezca instance:
 
    option          meaning                                     default
      timeout        ca timeout (in sec)                          0.001
      retry          ca retry count                               300
      debug          debug flag (1: on, 0: off)                   0
      trace          flag to turn ezcaTraceOn on/off              0
      autoerror      flag to turn ezcaAutoError on/off            0
 
      use_char       flag to usw string output where appropriate  0
      use_numeric    flag to use Numeric arrays for array data    0
 
   Both 'use_char' and 'use_numeric' are recommended!
 
   Methods defined here:
CheckMonitor(self, pv, *args, **kw)
Check the Status of Monitored PV:
status  = ezca.CheckMonitor(pv)
Check_All_Monitors(self)
Call CheckMonitor for all Monitored PVs:
returns 1 if any monitors have been posted.
 
any monitor callbacks that have been defined
will be executed.
 
status  = ezca.Check_All_Monitors()
ClearMonitor(self, pv)
Clear a Monitor on a PV:
status  = ezca.ClearMonitor(pv)
EndGroup(self)
End a 'Group' for efficient get/puts:
status  = ezca.EndGroup()
GetCountAndType(self, pv)
Get Count and Type (python type!) of a PV:
(count,type) = ezca.GetNelem(pv)
GetNelem(self, pv)
Get Number of Elements (count) of a PV:
count = ezca.GetNelem(pv)
GetPrecision(self, pv)
Get Precision of a PV:
prec = ezca.GetPrecision(pv)
GetStatus(self, pv)
Get time, status, and severity for a PV:
(time, status, severity) = ezca.GetStatus(pv)
GetUnits(self, pv)
Get Units (as a character string) of a PV:
units = ezca.GetUnits(pv)
SetMonitor(self, pv, callback=None, args=[], kw={})
Set a Monitor on a PV:
status  = ezca.SetMonitor(pv)
StartGroup(self)
Start a 'Group' for efficient get/puts:
status  = ezca.StartGroup()
__init__(self, debug=0, trace=0, autoerror=0, retry=300, timeout=0.001, retrycount=None, use_char=0, use_numeric=1)
caget(self, pv, fromcache=None, type=None)
get a Process Variable:
x = ezca.caget(pv)
options:
    fromcache=1    do _not_ do a real caget, but get
                   the last read value, as after a set
                   of StartGroup/EndGroup.
    type='char'    try to force output as string (useful for
                   bo//bi/mbbi/mbbo output)
caput(self, pv, val, wait=0)
set a Process Variable:
x = ezca.caput(pv,val)
connect(self, pv)
initiate a connection to a PV,
internally storing information about the PV with the PV class.
   res = ezca.connect(pv)
returns a the PV class instance.
delay(self, time)
Do an Ezca time delay:
status  = ezca.delay(time)
get_status(self)
get Ezca status
getpv(self, pv, type='scalar', format=None, descpv=None)
Enhanced caget of a PV:
(val, desc) = ezca.getpv(pv, options)
 
where the options controlling what the output value and
and description are, and how they are formatted.
 
In general, a PV is assumed to have a '.VAL' (which is
optional), and the corresponding '.VAL'   and '.DESC'
fields will be found and passed back:
val,desc = ezca.getpv('XXX:m1')
will return the values of XXX:m1.VAL and XXX:m1.DESC
 
option     meaning
type       PV type (full, bo, mbbi)
           'bo':   PV is a binary out, lookup '.ZNAM'
                   or '.ONAM' field as appropriate
                   for the output VALUE
           'mbbi': PV is a mbbi, lookup '.ZRST', ...
                   as appropriate for the output VALUE
           'full': Do _NOT_ append '.VAL' and '.DESC'
                   to PV.
           'yes/no': translate 1/0 to 'Yes/No'
desc       PV to use to lookup description field (instead
           of using the '.DESC' field.
format     C/Python format string to use to format output
set_debug(self, d=1)
set debug status:
ezca.set_debug(1)   turn debugging on
ezca.set_debug()    turn debugging on
ezca.set_debug(0)   turn debugging off
show_config(self)
print current configuration to standard output

Data and non-method functions defined here:
__doc__ = "Ezca: Epics EZCA interface in Python\n\n example:\n...th 'use_char' and 'use_numeric' are recommended!\n"
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
__module__ = 'Ezca'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
version = '1.2'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
 
class PV
       Simple Epics EZCA Process Variable
 
example:
   import Ezca
   pv = Ezca.PV('XX:m1.VAL')
   print pv.get()
 
   Methods defined here:
CheckMonitor(self, kw={})
Check the Status of Monitored PV:
status  = pv.CheckMonitor()
returns:
   1 if a new Monitor has been posted,
   0 if a new Monitor has not been posted
   None if PV is not connected or no Monitor has been set on it.
   
if a monitor callback has been defined, it will be executed.
ClearMonitor(self)
Clear a Monitor on a PV:
status  = ezca.ClearMonitor(pv)
GetCountAndType(self)
Get Count and Type (python type!) of a PV:
(count,type) = PV.GetNelem()
GetNelem(self)
Get Number of Elements (count) of a PV:
count = ezca.GetNelem(pv)
GetPrecision(self)
Get Precision of a PV:
prec = PV.GetPrecision()
GetStatus(self)
Get time, status, and severity for PV:
(time, status, severity) = pv.GetStatus()
GetUnits(self)
Get Units (as a character string) of a PV:
units = PV.GetUnits()
SetMonitor(self, callback=None, args=[], kw={})
Set a Monitor on a PV:
status  = pv.SetMonitor()
can optionally define a monitor callback, which will 
be called by CheckMonitor() if the value has changed.
__init__(self, name=None, debug=0, use_numeric=1, retry=None, timeout=None)
connect(self, pv=None)
initiate a connection to a PV,
internally storing useful information about the PV
such as count, type, rtype, and allocating a  pointer
for the data.
   res = PV.connect(pv)
returns a tuple of count, ezcatype, python_type, and pointer
connected(self)
return 1 if a PV is 'connected', 0 otherwise
get(self, type=None)
get a Process Variable:  x = pv.get()
options:
  type='char' force output as string (useful for bo//bi/mbbi/mbbo output)
put(self, val, wait=0)
set a Process Variable:  x = pv.put(val)
options:
  wait=1  force waiting for record to completely process before returning
status(self)

Data and non-method functions defined here:
CaTypeMap = ((1, 'char'), (2, 'int'), (4, 'float'), (2, 'int'), (0, 'byte'), (3, 'long'), (5, 'double'))
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items
 
If the argument is a tuple, the return value is the same object.
__doc__ = " Simple Epics EZCA Process Variable\n\n example:\n ...pv = Ezca.PV('XX:m1.VAL')\n print pv.get()\n "
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
__module__ = 'Ezca'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
retry_range = (10, 500)
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items
 
If the argument is a tuple, the return value is the same object.
timeout_range = (0.00050000000000000001, 0.01)
tuple() -> an empty tuple
tuple(sequence) -> tuple initialized from sequence's items
 
If the argument is a tuple, the return value is the same object.
version = '0.2'
str(object) -> string
 
Return a nice string representation of the object.
If the argument is a string, the return value is the same object.
 
Functions
            
ezcaAutoErrorMessageOff(...)
ezcaAutoErrorMessageOn(...)
ezcaClearMonitor(...)
ezcaDebugOff(...)
ezcaDebugOn(...)
ezcaDelay(...)
ezcaEndGroup(...)
ezcaEndGroupWithReport(...)
ezcaFree(...)
ezcaGet(...)
ezcaGetControlLimits(...)
ezcaGetErrorString(...)
ezcaGetGraphicLimits(...)
ezcaGetNelem(...)
ezcaGetPrecision(...)
ezcaGetRetryCount(...)
ezcaGetStatus(...)
ezcaGetTimeout(...)
ezcaGetUnits(...)
ezcaGetWithStatus(...)
ezcaNewMonitorValue(...)
ezcaPerror(...)
ezcaPut(...)
ezcaPutOldCa(...)
ezcaPvToChid(...)
ezcaSetMonitor(...)
ezcaSetRetryCount(...)
ezcaSetTimeout(...)
ezcaStartGroup(...)
ezcaTraceOff(...)
ezcaTraceOn(...)
ezca_GetChar(...)
ezca_GetCharArray(...)
ezca_GetCountAndType(...)
ezca_GetStatus_(...)
ezca_GetUnits_(...)
ezca_PutChar(...)
ptradd(...)
ptrcast(...)
ptrcreate(...)
ptrfree(...)
ptrmap(...)
ptrset(...)
ptrvalue(...)
 
Data
             EZCA_CAFAILURE = 3
EZCA_FAILEDMALLOC = 2
EZCA_INGROUP = 7
EZCA_INVALIDARG = 1
EZCA_NOTCONNECTED = 5
EZCA_NOTIMELYRESPONSE = 6
EZCA_NOTINGROUP = 8
EZCA_OK = 0
EZCA_UDFREQ = 4
EZCA_UNITS_SIZE = 8
__file__ = './Ezca.pyc'
__name__ = 'Ezca'
ezcaByte = 0
ezcaDouble = 5
ezcaFloat = 4
ezcaLong = 3
ezcaShort = 2
ezcaString = 1