source: pvrrd/src/pvrrd/pvwatch.py @ 619

Last change on this file since 619 was 619, checked in by jemian, 12 years ago

relocate to more standard layout

  • Property :svn_eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Date Author Revision Url Id
File size: 1.6 KB
Line 
1#!/usr/bin/env python
2
3'''
4log EPICS data into RRD files
5'''
6
7########### SVN repository information ###################
8# $Date: 2011-08-21 13:24:14 +0000 (Sun, 21 Aug 2011) $
9# $Author: jemian $
10# $Revision: 619 $
11# $HeadURL$
12# $Id: pvwatch.py 619 2011-08-21 13:24:14Z jemian $
13########### SVN repository information ###################
14
15#-------------------------------------------------------------
16
17import time
18import pprint
19import epics        # Matt Newville's EpicsCA support
20
21#-------------------------------------------------------------
22
23
24class pvwatch:
25    '''A single monitored EPICS PV'''
26
27    name = None        # EPICS PV name
28    ch = None          # EPICS channel object
29    value = None       # value at last update
30    count = 0          # number of updates received
31    timestamp = None   # Python time of last update
32    connected = False  # current EPICS connection state
33
34    def __init__(self, name):
35        self.name = name
36        self.ch = epics.PV( name,
37           connection_callback = self.connectHandler,
38           callback = self.updateHandler,
39           auto_monitor = True)
40
41    def __str__(self):
42        n = "%s" % self.name
43        v = "%s" % self.value
44        c = "%d" % self.count
45        return "%40s %20s %15s" % (n, v, c)
46
47    def connectHandler(self, **kw):
48        self.timestamp = time.time()
49        self.connected = kw['conn']
50        self.ch = kw['pv']
51        # cannot call self.get() here!
52        #print self.name, " connected = ", self.connected
53
54    def updateHandler(self, **kw):
55        #pprint.pprint(kw)
56        self.timestamp = time.time()
57        self.value = kw['value']
58        self.count += 1
59        #print self.name, " = ", self.value
60
61    def get(self):
62        self.value = self.ch.get()
Note: See TracBrowser for help on using the repository browser.