Exemple #1
0
def generate_live_data(duration, period, pvnames):
    pvnamelist = tuple(pvnames)
    cols = list(pvnamelist)
    cols.insert(0, 'timestamp')
    pvconn = {}
    alldata = []
    ca.initialize_libca()
    for name in pvnamelist:
        chid = ca.create_channel(name, connect=False, auto_cb=False)
        pvconn[name] = (chid, None)
    for key in list(pvconn):
        state = ca.connect_channel(pvconn.get(key)[0])
        if not state:
            print('PV:', key, 'not connected')
            pvconn.pop(key)
    ca.poll()
    while duration > 0 and pvconn:
        pvdata = []
        for name, data in pvconn.items():
            ca.get(data[0], wait=False)
        ca.poll()
        pvdata.append(datetime.datetime.now())
        for name, data in pvconn.items():
            val = ca.get_complete(data[0])
            pvdata.append(val)
        alldata.append(pvdata)
        time.sleep(period)
        duration = duration - period
    ca.finalize_libca(maxtime=1.0)
    df = pd.DataFrame(alldata, columns=cols)
    return df
Exemple #2
0
def caclient():
    ca.finalize_libca()

    sport = str(IocControl.server_port)
    os.environ['EPICS_CA_AUTO_ADDR_LIST'] = 'NO'
    os.environ['EPICS_CA_ADDR_LIST'] = 'localhost:{}'.format(sport)

    ca.initialize_libca()
    yield
    ca.finalize_libca()
Exemple #3
0
 def tearDown(self):
     ca.finalize_libca()
     self.gatewayControl.stop()
     self.iocControl.stop()
Exemple #4
0
def blowout_pvs():
    #epics.ca.clear_channel(pv_name.chid) 
    ca.finalize_libca()
    def testPropCache_ValueGetDisconnectCTRLGet(self):
        '''Get PV (value) through GW - disconnect client - change properties (HIGH, EGU) directly - get the DBR_CTRL of the PV through GW'''
        # gateway should show no VC (client side connection) and no PV (IOC side connection)
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 0,
            "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 0,
            "Expected GW PV total count: 0, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 0,
            "Expected GW connected PV count: 0, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 0,
            "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # gwcachetest is an ai record with full set of alarm limits: -100 -10 10 100
        gw = ca.create_channel("gateway:gwcachetest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:gwcachetest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 1,
            "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 1,
            "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # limit should not have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        highVal = ioc_ctrl['upper_warning_limit']
        self.assertTrue(
            highVal == 10.0,
            "Expected IOC warning_limit: 10; actual limit: " + str(highVal))
        eguVal = ioc_ctrl['units']
        self.assertTrue(
            eguVal == "wobbles",
            "Expected IOC units string: wobbles; actual units string: " +
            eguVal)
        gw_ctrl = ca.get_ctrlvars(gw)
        highVal = gw_ctrl['upper_warning_limit']
        self.assertTrue(
            highVal == 10.0,
            "Expected GW warning_limit: 10; actual limit: " + str(highVal))
        eguVal = gw_ctrl['units']
        self.assertTrue(
            eguVal == "wobbles",
            "Expected GW units string: wobbles; actual units string: " +
            eguVal)

        # disconnect Channel Access, reconnect Gateway stats
        ca.finalize_libca()
        ca.initialize_libca()
        self.connectGwStats()

        # gateway should show no VC and 1 connected inactive PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 0,
            "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 0,
            "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 1,
            "Expected GW inactive PV count: 1, actual: " + str(self.inactive))

        # set warning limit on IOC
        ioc_high = ca.create_channel("ioc:gwcachetest.HIGH")
        ca.put(ioc_high, 20.0, wait=True)
        # set unit string on IOC
        ioc_egu = ca.create_channel("ioc:gwcachetest.EGU")
        ca.put(ioc_egu, "foo", wait=True)
        time.sleep(.1)

        # reconnect Gateway and IOC
        gw = ca.create_channel("gateway:gwcachetest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:gwcachetest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 1,
            "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 1,
            "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # now the limit should have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        highVal = ioc_ctrl['upper_warning_limit']
        self.assertTrue(
            highVal == 20.0,
            "Expected IOC warning_limit: 20; actual limit: " + str(highVal))
        eguVal = ioc_ctrl['units']
        self.assertTrue(
            eguVal == "foo",
            "Expected IOC units string: foo; actual units string: " + eguVal)
        gw_ctrl = ca.get_ctrlvars(gw)
        highVal = gw_ctrl['upper_warning_limit']
        self.assertTrue(
            highVal == 20.0,
            "Expected GW warning_limit: 20; actual limit: " + str(highVal))
        eguVal = gw_ctrl['units']
        self.assertTrue(
            eguVal == "foo",
            "Expected GW units string: wobbles; actual units string: " +
            eguVal)
Exemple #6
0
    def testEnumPropCache_ValueGetDisconnectCTRLGet(self):
        '''Get PV (value) through GW - disconnect client - change ENUM string directly - get the DBR_CTRL of the PV through GW'''
        # gateway should show no VC (client side connection) and no PV (IOC side connection)
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 0,
            "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 0,
            "Expected GW PV total count: 0, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 0,
            "Expected GW connected PV count: 0, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 0,
            "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # enumtest is an mbbi record with three strings defined: zero one two
        gw = ca.create_channel("gateway:enumtest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:enumtest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 1,
            "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 1,
            "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # enum string should not have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        oneStr = ioc_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'one',
                        "Expected IOC enum[1]: one; actual enum[1]: " + oneStr)
        gw_ctrl = ca.get_ctrlvars(gw)
        oneStr = gw_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'one',
                        "Expected GW enum[1]: one; actual enum[1]: " + oneStr)

        # disconnect Channel Access, reconnect Gateway stats
        ca.finalize_libca()
        ca.initialize_libca()
        self.connectGwStats()

        # gateway should show no VC and 1 connected inactive PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 0,
            "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 0,
            "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 1,
            "Expected GW inactive PV count: 1, actual: " + str(self.inactive))

        # set enum string on IOC
        ioc_enum1 = ca.create_channel("ioc:enumtest.ONST")
        ca.put(ioc_enum1, 'uno', wait=True)
        time.sleep(.1)

        # reconnect Gateway and IOC
        gw = ca.create_channel("gateway:enumtest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:enumtest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected,
                        "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(
            self.vctotal == 1,
            "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(
            self.pvtotal == 1,
            "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(
            self.connected == 1,
            "Expected GW connected PV count: 1, actual: " +
            str(self.connected))
        self.assertTrue(
            self.active == 1,
            "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(
            self.inactive == 0,
            "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # Now the enum string should have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        oneStr = ioc_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'uno',
                        "Expected IOC enum[1]: uno; actual enum[1]: " + oneStr)
        gw_ctrl = ca.get_ctrlvars(gw)
        oneStr = gw_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'uno',
                        "Expected GW enum[1]: uno; actual enum[1]: " + oneStr)
 def tearDown(self):
     ca.finalize_libca()
     self.gatewayControl.stop()
     self.iocControl.stop()
    def testPropCache_ValueGetDisconnectCTRLGet(self):
        '''Get PV (value) through GW - disconnect client - change HIGH directly - get the DBR_CTRL of the PV through GW'''
        gw_vctotal = ca.create_channel("gwtest:vctotal")
        gw_pvtotal = ca.create_channel("gwtest:pvtotal")
        gw_connected = ca.create_channel("gwtest:connected")
        gw_active = ca.create_channel("gwtest:active")
        gw_inactive = ca.create_channel("gwtest:inactive")

        # gateway should show no VC (client side connection) and no PV (IOC side connection)
        count = ca.get(gw_vctotal)
        self.assertTrue(count == 0, "Expected GW VC total count: 0, actual: " + str(count))
        count = ca.get(gw_pvtotal)
        self.assertTrue(count == 0, "Expected GW PV total count: 0, actual: " + str(count))
        count = ca.get(gw_connected)
        self.assertTrue(count == 0, "Expected GW connected PV count: 0, actual: " + str(count))
        count = ca.get(gw_active)
        self.assertTrue(count == 0, "Expected GW active PV count: 0, actual: " + str(count))
        count = ca.get(gw_inactive)
        self.assertTrue(count == 0, "Expected GW inactive PV count: 0, actual: " + str(count))

        # gwcachetest is an ai record with full set of alarm limits: -100 -10 10 100
        gw = ca.create_channel("gateway:gwcachetest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected, "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:gwcachetest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        count = ca.get(gw_vctotal)
        self.assertTrue(count == 1, "Expected GW VC total count: 1, actual: " + str(count))
        count = ca.get(gw_pvtotal)
        self.assertTrue(count == 1, "Expected GW PV total count: 1, actual: " + str(count))
        count = ca.get(gw_connected)
        self.assertTrue(count == 1, "Expected GW connected PV count: 1, actual: " + str(count))
        count = ca.get(gw_active)
        self.assertTrue(count == 1, "Expected GW active PV count: 1, actual: " + str(count))
        count = ca.get(gw_inactive)
        self.assertTrue(count == 0, "Expected GW inactive PV count: 0, actual: " + str(count))

        # limit should not have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        highVal = ioc_ctrl['upper_warning_limit']
        self.assertTrue(highVal == 10.0, "Expected IOC warning_limit: 10; actual limit: "+ str(highVal))
        gw_ctrl = ca.get_ctrlvars(gw)
        highVal = gw_ctrl['upper_warning_limit']
        self.assertTrue(highVal == 10.0, "Expected GW warning_limit: 10; actual limit: "+ str(highVal))

        # disconnect Channel Access, reconnect Gateway stats
        ca.finalize_libca()
        ca.initialize_libca()
        gw_vctotal = ca.create_channel("gwtest:vctotal")
        gw_pvtotal = ca.create_channel("gwtest:pvtotal")
        gw_connected = ca.create_channel("gwtest:connected")
        gw_active = ca.create_channel("gwtest:active")
        gw_inactive = ca.create_channel("gwtest:inactive")

        # gateway should show no VC and 1 connected inactive PV
        count = ca.get(gw_vctotal)
        self.assertTrue(count == 0, "Expected GW VC total count: 0, actual: " + str(count))
        count = ca.get(gw_pvtotal)
        self.assertTrue(count == 1, "Expected GW PV total count: 1, actual: " + str(count))
        count = ca.get(gw_connected)
        self.assertTrue(count == 1, "Expected GW connected PV count: 1, actual: " + str(count))
        count = ca.get(gw_active)
        self.assertTrue(count == 0, "Expected GW active PV count: 0, actual: " + str(count))
        count = ca.get(gw_inactive)
        self.assertTrue(count == 1, "Expected GW inactive PV count: 1, actual: " + str(count))

        # set warning limit on IOC
        ioc_high = ca.create_channel("ioc:gwcachetest.HIGH")
        ca.put(ioc_high, 20.0, wait=True)
        time.sleep(.1)

        # reconnect Gateway and IOC
        gw = ca.create_channel("gateway:gwcachetest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected, "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:gwcachetest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        count = ca.get(gw_vctotal)
        self.assertTrue(count == 1, "Expected GW VC total count: 1, actual: " + str(count))
        count = ca.get(gw_pvtotal)
        self.assertTrue(count == 1, "Expected GW PV total count: 1, actual: " + str(count))
        count = ca.get(gw_connected)
        self.assertTrue(count == 1, "Expected GW connected PV count: 1, actual: " + str(count))
        count = ca.get(gw_active)
        self.assertTrue(count == 1, "Expected GW active PV count: 1, actual: " + str(count))
        count = ca.get(gw_inactive)
        self.assertTrue(count == 0, "Expected GW inactive PV count: 0, actual: " + str(count))

        # now the limit should have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        highVal = ioc_ctrl['upper_warning_limit']
        self.assertTrue(highVal == 20.0, "Expected IOC warning_limit: 20; actual limit: "+ str(highVal))
        gw_ctrl = ca.get_ctrlvars(gw)
        highVal = gw_ctrl['upper_warning_limit']
        self.assertTrue(highVal == 20.0, "Expected GW warning_limit: 20; actual limit: "+ str(highVal))
    def testEnumPropCache_ValueGetDisconnectCTRLGet(self):
        '''Get PV (value) through GW - disconnect client - change ENUM string directly - get the DBR_CTRL of the PV through GW'''
        # gateway should show no VC (client side connection) and no PV (IOC side connection)
        self.updateGwStats()
        self.assertTrue(self.vctotal == 0, "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(self.pvtotal == 0, "Expected GW PV total count: 0, actual: " + str(self.pvtotal))
        self.assertTrue(self.connected == 0, "Expected GW connected PV count: 0, actual: " + str(self.connected))
        self.assertTrue(self.active == 0, "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(self.inactive == 0, "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # enumtest is an mbbi record with three strings defined: zero one two
        gw = ca.create_channel("gateway:enumtest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected, "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:enumtest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(self.vctotal == 1, "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(self.pvtotal == 1, "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(self.connected == 1, "Expected GW connected PV count: 1, actual: " + str(self.connected))
        self.assertTrue(self.active == 1, "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(self.inactive == 0, "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # enum string should not have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        oneStr = ioc_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'one', "Expected IOC enum[1]: one; actual enum[1]: "+ oneStr)
        gw_ctrl = ca.get_ctrlvars(gw)
        oneStr = gw_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'one', "Expected GW enum[1]: one; actual enum[1]: "+ oneStr)

        # disconnect Channel Access, reconnect Gateway stats
        ca.finalize_libca()
        ca.initialize_libca()
        self.connectGwStats()

        # gateway should show no VC and 1 connected inactive PV
        self.updateGwStats()
        self.assertTrue(self.vctotal == 0, "Expected GW VC total count: 0, actual: " + str(self.vctotal))
        self.assertTrue(self.pvtotal == 1, "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(self.connected == 1, "Expected GW connected PV count: 1, actual: " + str(self.connected))
        self.assertTrue(self.active == 0, "Expected GW active PV count: 0, actual: " + str(self.active))
        self.assertTrue(self.inactive == 1, "Expected GW inactive PV count: 1, actual: " + str(self.inactive))

        # set enum string on IOC
        ioc_enum1 = ca.create_channel("ioc:enumtest.ONST")
        ca.put(ioc_enum1, 'uno', wait=True)
        time.sleep(.1)

        # reconnect Gateway and IOC
        gw = ca.create_channel("gateway:enumtest")
        connected = ca.connect_channel(gw, timeout=.5)
        self.assertTrue(connected, "Could not connect to gateway channel " + ca.name(gw))
        ioc = ca.create_channel("ioc:enumtest")
        connected = ca.connect_channel(ioc, timeout=.5)
        self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(gw))

        # gateway should show one VC and one connected active PV
        self.updateGwStats()
        self.assertTrue(self.vctotal == 1, "Expected GW VC total count: 1, actual: " + str(self.vctotal))
        self.assertTrue(self.pvtotal == 1, "Expected GW PV total count: 1, actual: " + str(self.pvtotal))
        self.assertTrue(self.connected == 1, "Expected GW connected PV count: 1, actual: " + str(self.connected))
        self.assertTrue(self.active == 1, "Expected GW active PV count: 1, actual: " + str(self.active))
        self.assertTrue(self.inactive == 0, "Expected GW inactive PV count: 0, actual: " + str(self.inactive))

        # Now the enum string should have been updated
        ioc_ctrl = ca.get_ctrlvars(ioc)
        oneStr = ioc_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'uno', "Expected IOC enum[1]: uno; actual enum[1]: "+ oneStr)
        gw_ctrl = ca.get_ctrlvars(gw)
        oneStr = gw_ctrl['enum_strs'][1]
        self.assertTrue(oneStr == 'uno', "Expected GW enum[1]: uno; actual enum[1]: "+ oneStr)