Changeset 85 for epics2xml/epics2xml.py


Ignore:
Timestamp:
Nov 6, 2009 1:15:10 PM (14 years ago)
Author:
jemian
Message:

Fixes #2: initial version ready for testing, probably needs better error handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • epics2xml/epics2xml.py

    r83 r85  
    2828import datetime
    2929#import copy
    30 #import pvConnect
     30import pvConnect
    3131
    3232
     
    5959        self.db = {}
    6060        self.pv = {}
     61        self.newData = False
    6162
    6263    def ReadConfigFile(self):
     
    185186        pv = self.pv[name]
    186187        pv[key] = value
     188        self.newData = True
    187189
    188190    def setPv(self, name, value):
     
    236238
    237239    def receiver(self, epics_args, user_args):
    238         '''Example response to an EPICS monitor on the channel
     240        '''Response to an EPICS monitor on the channel.  Expects to have the PV name as the first user_args.
    239241           @param value: str(epics_args['pv_value'])'''
    240242        value = epics_args['pv_value']
    241         print 'receiver', 'updated value:', str(value)
     243        pv = user_args[0]
     244        self.setPv(pv, str(value))
     245        #print 'receiver: ', pv, ' = ', str(value)
    242246
    243247
     
    246250    cf.ReadConfigFile()
    247251    # connect with EPICS here and start waiting for events
    248     # How to save periodically?
    249     # How to throttle the output file update rate?
    250    
     252    if pvConnect.IMPORTED_CACHANNEL:
     253        for item in cf.db['pvList']:
     254            pv = item['name']
     255            if pvConnect.testConnect(pv):
     256                #print pv
     257                ch = pvConnect.EpicsPv(pv)
     258                ch.SetUserArgs(pv)
     259                ch.connectw()
     260                ch.SetUserCallback(cf.receiver)
     261                ch.monitor()
     262                ch.chan.pend_event()
     263        import time
     264        while True:
     265            # wait for the minimum refresh period
     266            refreshSeconds = int(cf.db['targetFile'] ['refreshMinimum'])
     267            for seconds in range(refreshSeconds):
     268                time.sleep(1)
     269                ch.chan.pend_event()
     270            # write only if there is new data
     271            if cf.newData:
     272                #print cf.__repr__()
     273                cf.SaveXmlFile()
     274        # not likely to get here
     275        pvConnect.on_exit()
     276    else:
     277        #----------------------------
     278        # load some artificial data to test
     279        cf.setPv("S:SRcurrent:AI", '99.9853')
     280        cf.setPv("APS:BarometricPressure:MBR", '992.083')
     281        print cf.__repr__()
    251282    #----------------------------
    252     # load some artificial data to test
    253     cf.setPv("S:SRcurrent:AI", '99.9853')
    254     cf.setPv("APS:BarometricPressure:MBR", '992.083')
    255     print cf.__repr__()
    256     #----------------------------
Note: See TracChangeset for help on using the changeset viewer.