Changeset 85


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

Location:
epics2xml
Files:
2 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     #----------------------------
  • epics2xml/pvdata.xml

    r81 r85  
    11<?xml version="1.0" ?>
    22<?xml-stylesheet type="text/xsl" href="basic-table.xsl" ?>
    3 
    4 <pvdata version="1.0" date="2009-11-06" time="10:32:00">
    5     <title>epics2xml: demonstration of function</title>
    6     <pv name="S:SRcurrent:AI" rate="monitor" date="2009-11-06" time="09:26:00">
    7         <description>APS Storage ring current, mA</description>
    8         <value>99.9853</value>
    9     </pv>
    10     <pv name="APS:BarometricPressure:MBR" rate="monitor" date="2009-11-06" time="10:28:00">
    11         <description>ANL barometric pressure, mbar</description>
    12         <value>992.083</value>
    13     </pv>
     3<pvdata date="2009-11-06" time="13:10:20" version="1.0">
     4  <title>
     5    epics2xml: demonstration of function
     6  </title>
     7  <pv date="2009-11-06" name="S:SRcurrentAI" rate="monitor" time="13:10:20">
     8    <description>
     9      APS Storage ring current, mA
     10    </description>
     11    <value>
     12      94.5242330335
     13    </value>
     14  </pv>
     15  <pv date="2009-11-06" name="APS:BarometricPressure:MBR" rate="monitor" time="13:10:20">
     16    <description>
     17      ANL barometric pressure, mbar
     18    </description>
     19    <value>
     20      987.91800419
     21    </value>
     22  </pv>
    1423</pvdata>
Note: See TracChangeset for help on using the changeset viewer.