pvConnect
index
/home/oxygen18/JEMIAN/Documents/eclipse/usaxs/wxmtxy/trunk/pvConnect.py

simplified connections to an EPICS PV using CaChannel
 
Provides these classes:
 
    CaPollWx
        Use in WX-based GUIs to call ca.poll() in the background
        @param interval_s: [float] interval between calls to ca.poll()
 
    EpicsPv
        manage a CaChannel connection with an EPICS PV
        @param name: [string] EPICS PV to connect
 
Provides these utility routines:
 
    on_exit(timer)
        Exit handler to stop the ca.poll()
        @param timer: CaPollWx object
 
    CaPoll()
        Use in non-GUI scripts to call ca.poll() in the background
 
    GetRTYP(pv)
        Returns the record type of "pv"
        @param pv:[string]
        @return: [string] EPICS record type or None if cannot connect
 
    testConnect(pv)
        Tests if a CaChannel connection can be established to "pv"
        @param pv:[string]
        @return: True if can connect, otherwise False
 
    receiver(value)
        Example response to an EPICS monitor on the channel
        @param value: str(epics_args['pv_value'])
 
@version: 
########### SVN repository information ###################
# $Date: 2010-06-03 16:04:15 -0500 (Thu, 03 Jun 2010) $
# $Author: jemian $
# $Revision: 184 $
# $URL: https://subversion.xor.aps.anl.gov/bcdaext/wxmtxy/trunk/pvConnect.py $
# $Id: pvConnect.py 184 2010-06-03 21:04:15Z jemian $
########### SVN repository information ###################

 
Modules
       
CaChannel
sys
time
wx

 
Classes
       
CaPollWx
EpicsPv

 
class CaPollWx
    Use in WX-based GUIs to call ca.poll() in the background
 
Set up a separate thread to trigger periodic calls to the 
EPICS CaChannel.ca.poll() connection.  Awaiting (a.k.a., 
outstanding or pending) channel access background 
activity executes during the poll.  Calls pend_event() 
with a timeout short enough to poll.  
 
The default polling interval is 0.1 second.
 
@note: The code will silently do nothing if wx was not imported.
This routine use the wx.PyTimer() to call ca.poll() frequently 
during the main WX event loop.
 
@warning: Only use this in a routine that has already called 
wx.App() or an exception will occur.  
Command line code will need to call ca.poll() using a different 
method (such as CaPoll() below).
 
  Methods defined here:
GetInterval(self)
return the current interval between calls to CaChannel.ca.poll()
SetInterval(self, interval_s)
set the next interval between calls to CaChannel.ca.poll()
__init__(self, interval_s=0.10000000000000001)
@param interval_s: [float] interval between calls to ca.poll()
poll(self)
Poll for changes in Channel
start(self)
start polling
stop(self)
stop polling

 
class EpicsPv
    manage a connection with an EPICS PV
 
  Methods defined here:
GetChan(self)
@return: CaChannel channel
GetEpicsArgs(self)
@return: epics_args from the most recent monitor event
GetPv(self)
@return: PV name
GetUserArgs(self)
@return: user_args from the most recent monitor event
GetUserCallback(self)
return the callback function supplied by the caller
values will be set by user_callback(value)
@return: function object
GetValue(self)
@return: value from EPICS from the most recent monitor event
SetMask(self, mask)
Define the mask used when applying a channel monitor.
The default is: self.mask = CaChannel.ca.DBE_VALUE
@param mask: as defined in the CaChannel manual
SetPv(self, name)
redefine the PV name only if there is no connection
@param name: valid EPICS PV name
SetUserArgs(self, user_args)
define the user_args tuple to use when monitoring
@param user_args: tuple of user data (for use in user_callback function)
SetUserCallback(self, user_callback)
Set the callback function supplied by the caller
values will be set by user_callback(value)
@param user_callback: function object
__init__(self, name)
initialize the class and set default values
@param name: [string] EPICS PV to connect
callback(self, epics_args, user_args)
receive an EPICS callback, copy epics_args and user_args, then call user
connect(self)
initiate the connection with EPICS
connectw(self)
initiate the connection with EPICS, standard wait for the connection
monitor(self)
Initiate a monitor on the EPICS channel, delivering the 
CaChannel callback to the supplied function.
 
@note: Example:
    ch = EpicsPv(test_pv)
    ch.connectw()
    uargs = test_pv, widget.SetLabel
    ch.SetUserArgs(uargs)
    ch.SetUserCallback(myCallback)
    ch.monitor()
 
@warning: At this time, there is not an easy way to turn off monitors.
    Instead, ch.release() the channel (which will set self.chan = None),
    To re-start a monitor after a ch.release(), connect as usual and start
    the monitor again, as the first time.
release(self)
release the connection with EPICS
@note: Release ALL channels before calling on_exit()

 
Functions
       
CaPoll()
Use in non-GUI scripts to call ca.poll() in the background
GetRTYP(pv)
Returns the record type of "pv"
@param pv:[string]
@return: [string] EPICS record type or None if cannot connect
on_exit(timer=None)
Exit handler to stop the ca.poll()
@param timer: CaPollWx object
 
Call this to cleanup when program is exiting.
ONLY call this function during a program's exit handling.
If ca.task_exit() is not called, then expect to see the errors:
     FATAL: exception not rethrown
     Abort
receiver(epics_args, user_args)
Example response to an EPICS monitor on the channel
@param value: str(epics_args['pv_value'])
testConnect(pv)
Tests if a CaChannel connection can be established to "pv"
@param pv:[string]
@return: True if can connect, otherwise False

 
Data
        IMPORTED_CACHANNEL = True
IMPORTED_WX = True