File: epicsPV.py

package info (click to toggle)
python-pyepics 3.5.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,336 kB
  • sloc: python: 10,539; makefile: 112; javascript: 104; sh: 53
file content (134 lines) | stat: -rwxr-xr-x 4,137 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
"""
Port of Mark Rivers epicsPV class to use epics.PV

Matt Newville  7-April-2010

Original comments:

This module defines the epicsPV class, which adds additional features to
Geoff Savage's CaChannel class.

Author:         Mark Rivers
Created:        Sept. 16, 2002.
Modifications:
"""
import epics

class epicsPV(epics.PV):
    """
    This class subclasses PV to provide a compatible API to Mark Rivers
    epicsPV class
    
    - setMonitor() sets a generic callback routine for value change events.
    Subsequent getw(), getValue() or array_get() calls will return the
    value from the most recent callback, and hence do not result in any
    network activity or latency.  This can greatly improve performance.
        
    - checkMonitor() returns a flag to indicate if a callback has occured
    since the last call to checkMonitor(), getw(), getValue() or
    array_get().  It can be used to increase efficiency in polling
    applications.
        
    - getControl() reads the "control" and other information from an
    EPICS PV without having to use callbacks.
    In addition to the PV value, this will return the graphic, control and
    alarm limits, etc.

    - putWait() calls array_put_callback() and waits for the callback to
    occur before it returns.  This allows programs to use array_put_callback()
    synchronously and without user-written callbacks.
    
    Created:  Mark Rivers, Sept. 16, 2002.
    Modifications:
    """

    def __init__(self, pvname=None, wait=True):
        """
        Keywords:
        pvname:
        An optional name of an EPICS Process Variable.
        
        wait: If wait==True and pvname != None then this constructor will do
        a wait for connection for the PV.  If wait==0 and pvname != None
        then the PV will eventually connect...
        
        """
        # Invoke the base class initialization
        PV.__init__(self, pvname)
        self.monitorState = False
        if pvname is not None and wait:
            self.connect()

    def _getCallback(self, pvname=None, value=None, **kw):
        self.monitorState = True

    def setMonitor(self):
        """
        Sets a simple callback routine for value change events
        to note when a change occurs.
        """
        self.monitorState = False
        self.add_callback(callback=self._getCallback)

    def clearMonitor(self):
        """
        Cancels the effect of a previous call to setMonitor().
        """
        self.monitorState = False

    def checkMonitor(self):
        """
        Returns True to indicate if a value callback has occured,
        indicating a new value is available since the last check.
        Returns False if no such callback has occurred.
        """
        epics.poll()
        out =  self.monitorState
        self.monitorState = False
        return out

    def getControl(self):
        """
        returns a dictionary of control information for a PV
        Example::
        
        >>> pv = epicsPV('13IDC:m1')
        >>> for field, value in pv.getControl().items():
        >>>    print field, ':', value
        status  :  0
        severity  :  0
        precision  :  5
        units  :  mm
        lower_alarm_limit  :  0.0
        upper_alarm_limit  :  0.0
        lower_warning_limit  :  0.0
        upper_warning_limit  :  0.0
        lower_disp_limit  :  -2.4
        upper_disp_limit  :  2.4
        upper_ctrl_limit  :  2.4
        lower_ctrl_limit  :  -2.4
        """
        epics.poll()
        return self.get_ctrlvars()
      
    def array_get(self, count=None):
        """ returns PV value    """
        return self.getw(count=count)

    def getw(self, count=None):
        """ returns PV value"""
        return self.get(count=count)

    def getValue(self):
        """  get most recent value for PV   """
        return self.get()
    
    def putw(self, value, wait=False):
        """ set PV value"""
        self.put(value, wait=wait)
        
    def putWait(self, value):
        """ put PV value, waits for the callback to
        occur before it returns.  """
        self.put(value, wait=True)