def testCtrlStruct_ValueMonitor(self): '''Monitor PV (value events) through GW - change value and properties directly - check CTRL structure consistency''' diffs = [] # 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, use_ctrl=True, callback=self.onChangeGW) ioc = ca.create_channel("ioc:gwcachetest") connected = ca.connect_channel(ioc, timeout=.5) self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(ioc)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, use_ctrl=True, callback=self.onChangeIOC) # set value on IOC ioc_value = ca.create_channel("ioc:gwcachetest") ca.put(ioc_value, 10.0, wait=True) gwtests.wait_until( lambda: self.eventsReceivedIOC == self.eventsReceivedGW, 5.0) self.assertTrue( self.eventsReceivedIOC == self.eventsReceivedGW, "After setting value, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue( are_diff == False, "At update {0} (change value), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs))) # set property on IOC ioc_hihi = ca.create_channel("ioc:gwcachetest.HIHI") ca.put(ioc_hihi, 123.0, wait=True) ca.put(ioc_value, 11.0, wait=True) # trigger update gwtests.wait_until( lambda: self.eventsReceivedIOC == self.eventsReceivedGW, 5.0) self.assertTrue( self.eventsReceivedIOC == self.eventsReceivedGW, "After setting property, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue( are_diff == False, "At update {0} (change property), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs)))
def testEnumPropCache_ValueMonitorCTRLget(self): '''Monitor PV (value events) through GW - 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, callback=self.onChange) 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)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, callback=self.onChange) # 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) # set enum string on IOC ioc_enum1 = ca.create_channel("ioc:enumtest.ONST") ca.put(ioc_enum1, 'uno', wait=True) time.sleep(.1) # Now the enum string should have been updated (if IOC supports DBE_PROPERTY) 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) if self.propSupported: gw_expected = 'uno' else: gw_expected = 'one' gw_ctrl = ca.get_ctrlvars(gw) oneStr = gw_ctrl['enum_strs'][1] self.assertTrue(oneStr == gw_expected, "Expected GW enum[1]: {0}; actual enum[1]: {1}".format(gw_expected, oneStr))
def _test_array_callback(self, arrayname, array_type, length, element_type): """ Helper function to subscribe to a PV array and check it receives at least one subscription callback w/ specified type, length & uniform element type. Checks separately for normal, TIME & CTRL subscription variants. Returns the array or fails an assertion.""" results = {} for form in [ 'normal', 'time', 'ctrl' ]: chid = ca.create_channel(arrayname,connect=True) cb, uarg, eventID = ca.create_subscription(chid, use_time=form=='time', use_ctrl=form=='ctrl', callback=onChanges) CHANGE_DAT.pop(arrayname, None) timeout=0 # wait up to 6 seconds, if no callback probably due to simulator.py # not running... while timeout<120 and not arrayname in CHANGE_DAT: time.sleep(0.05) timeout = timeout+1 val = CHANGE_DAT.get(arrayname, None) ca.clear_subscription(eventID) self.assertIsNot(val, None) self.assertEqual(type(val), array_type) self.assertEqual(len(val), length) self.assertEqual(type(val[0]), element_type) self.assertTrue(all( type(e)==element_type for e in val)) results[form] = val return results
def setup_callback(pvname): def my_cb(pvname=None, value=None, **kw): sys.stdout.write( 'get: %s value=%s, kw=%s\n' %( pvname, str(value), repr(kw))) sys.stdout.flush() chid = ca.create_channel(pvname) return ca.create_subscription(chid, callback=my_cb)
def setup_callback(pvname): def my_cb(pvname=None, value=None, **kw): sys.stdout.write('get: %s value=%s, kw=%s\n' % (pvname, str(value), repr(kw))) sys.stdout.flush() chid = ca.create_channel(pvname) return ca.create_subscription(chid, callback=my_cb)
def testCtrlStruct_ValueMonitor(self): '''Monitor PV (value events) through GW - change value and properties directly - check CTRL structure consistency''' diffs = [] # 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, use_ctrl=True, callback=self.onChangeGW) ioc = ca.create_channel("ioc:gwcachetest") connected = ca.connect_channel(ioc, timeout=.5) self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(ioc)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, use_ctrl=True, callback=self.onChangeIOC) # set value on IOC ioc_value = ca.create_channel("ioc:gwcachetest") ca.put(ioc_value, 10.0, wait=True) time.sleep(.1) self.assertTrue(self.eventsReceivedIOC == self.eventsReceivedGW, "After setting value, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue(are_diff == False, "At update {0} (change value), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs))) # set property on IOC ioc_hihi = ca.create_channel("ioc:gwcachetest.HIHI") ca.put(ioc_hihi, 123.0, wait=True) ca.put(ioc_value, 11.0, wait=True) # trigger update time.sleep(.1) self.assertTrue(self.eventsReceivedIOC == self.eventsReceivedGW, "After setting property, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue(are_diff == False, "At update {0} (change property), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs)))
def test_subscription_double(self): pvn = pvnames.updating_pv1 chid = ca.create_channel(pvn,connect=True) cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges) start_time = time.time() global CHANGE_DAT while time.time()-start_time < 5.0: time.sleep(0.01) if CHANGE_DAT.get(pvn, None) is not None: break val = CHANGE_DAT.get(pvn, None) ca.clear_subscription(eventID) self.assertIsNot(val, None)
def test_subscription_str(): pvn = pvnames.updating_str1 write(" Subscription on string: %s " % pvn) chid = ca.create_channel(pvn, connect=True) cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges) start_time = time.time() global CHANGE_DAT while time.time() - start_time < 3.0: time.sleep(0.01) ca.put(chid, "%.1f" % (time.time() - start_time)) if CHANGE_DAT.get(pvn, None) is not None: break assert CHANGE_DAT.get(pvn, None) is not None
def test_subscription_double(self): pvn = pvnames.updating_pv1 chid = ca.create_channel(pvn,connect=True) cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges) start_time = time.time() global CHANGE_DAT while time.time()-start_time < 5.0: time.sleep(0.01) if CHANGE_DAT.get(pvn, None) is not None: break val = CHANGE_DAT.get(pvn, None) ca.clear_subscription(eventID) self.assertNotEqual(val, None)
def test_subscription_str(self): pvn = pvnames.updating_str1 write(" Subscription on string: %s " % pvn) chid = ca.create_channel(pvn,connect=True) cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges) start_time = time.time() global CHANGE_DAT while time.time()-start_time < 3.0: time.sleep(0.01) ca.put(chid, "%.1f" % (time.time()-start_time) ) if CHANGE_DAT.get(pvn, None) is not None: break val = CHANGE_DAT.get(pvn, None) # ca.clear_subscription(eventID) self.assertNotEqual(val, None) time.sleep(0.2)
def test_subscription_custom(self): pvn = pvnames.updating_pv1 chid = ca.create_channel(pvn, connect=True) global change_count change_count = 0 def my_callback(pvname=None, value=None, **kws): write( ' Custom Callback %s value=%s' %(pvname, str(value))) global change_count change_count = change_count + 1 cb, uarg, eventID = ca.create_subscription(chid, callback=my_callback) start_time = time.time() while time.time()-start_time < 2.0: time.sleep(0.01) ca.clear_subscription(eventID) time.sleep(0.2) self.assertTrue(change_count > 2)
def testPropCache_ValueMonitorCTRLget(self): '''Monitor PV (value events) through GW - 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, callback=self.onChange) ioc = ca.create_channel("ioc:gwcachetest") connected = ca.connect_channel(ioc, timeout=.5) self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(ioc)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, callback=self.onChange) # 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)) 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)) # set warning limit on IOC ioc_high = ca.create_channel("ioc:gwcachetest.HIGH") ca.put(ioc_high, 20.0, wait=True) time.sleep(.1) # Now the limit should have been updated (if IOC supports DBE_PROPERTY) 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)) if self.propSupported: gw_expected = 20.0 else: gw_expected = 10.0 gw_ctrl = ca.get_ctrlvars(gw) highVal = gw_ctrl['upper_warning_limit'] self.assertTrue( highVal == gw_expected, "Expected GW warning_limit: {0}; actual limit: {1}".format( gw_expected, highVal)) # set unit string on IOC ioc_egu = ca.create_channel("ioc:gwcachetest.EGU") old_egu = ca.get(ioc_egu) ca.put(ioc_egu, "foo", wait=True) time.sleep(.1) # Now the unit string should have been updated (if IOC supports DBE_PROPERTY) ioc_ctrl = ca.get_ctrlvars(ioc) eguVal = ioc_ctrl['units'] self.assertTrue( eguVal == "foo", "Expected IOC units string: foo; actual units string: " + eguVal) if self.propSupported: gw_expected = "foo" else: gw_expected = old_egu gw_ctrl = ca.get_ctrlvars(gw) eguVal = gw_ctrl['units'] self.assertTrue( eguVal == gw_expected, "Expected GW units string: {0}; actual units string: {1}".format( gw_expected, eguVal))
def testPropCache_ValueMonitorCTRLget(self): '''Monitor PV (value events) through GW - 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, callback=self.onChange) 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)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, callback=self.onChange) # 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)) # set warning limit on IOC ioc_high = ca.create_channel("ioc:gwcachetest.HIGH") ca.put(ioc_high, 20.0, wait=True) time.sleep(.1) # Now the limit should have been updated (if IOC supports DBE_PROPERTY) 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)) if self.propSupported: gw_expected = 20.0 else: gw_expected = 10.0 gw_ctrl = ca.get_ctrlvars(gw) highVal = gw_ctrl['upper_warning_limit'] self.assertTrue(highVal == gw_expected, "Expected GW warning_limit: {0}; actual limit: {1}".format(gw_expected, highVal))
def testEnumPropCache_ValueMonitorCTRLget(self): '''Monitor PV (value events) through GW - 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription(gw, mask=dbr.DBE_VALUE, callback=self.onChange) ioc = ca.create_channel("ioc:enumtest") connected = ca.connect_channel(ioc) self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(gw)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription(ioc, mask=dbr.DBE_VALUE, callback=self.onChange) # 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) # set enum string on IOC ioc_enum1 = ca.create_channel("ioc:enumtest.ONST") ca.put(ioc_enum1, 'uno', wait=True) time.sleep(.1) # Now the enum string should have been updated (if IOC supports DBE_PROPERTY) 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) if self.propSupported: gw_expected = 'uno' else: gw_expected = 'one' gw_ctrl = ca.get_ctrlvars(gw) oneStr = gw_ctrl['enum_strs'][1] self.assertTrue( oneStr == gw_expected, "Expected GW enum[1]: {0}; actual enum[1]: {1}".format( gw_expected, oneStr))
def testCSStudio_ValueAndPropMonitor(self): '''Monitor PV (imitating CS-Studio) through GW - change value and properties directly - check CTRL structure consistency''' diffs = [] if gwtests.verbose: print() # 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)) (gw_cbref, gw_uaref, gw_eventid) = ca.create_subscription( gw, mask=dbr.DBE_VALUE | dbr.DBE_ALARM, use_time=True, callback=self.onChangeGW) (gw_cbref2, gw_uaref2, gw_eventid2) = ca.create_subscription(gw, mask=dbr.DBE_PROPERTY, use_ctrl=True, callback=self.onChangeGW) ioc = ca.create_channel("ioc:gwcachetest") connected = ca.connect_channel(ioc, timeout=.5) self.assertTrue(connected, "Could not connect to ioc channel " + ca.name(ioc)) (ioc_cbref, ioc_uaref, ioc_eventid) = ca.create_subscription( ioc, mask=dbr.DBE_VALUE | dbr.DBE_ALARM, use_time=True, callback=self.onChangeIOC) (ioc_cbref2, ioc_uaref2, ioc_eventid2) = ca.create_subscription(ioc, mask=dbr.DBE_PROPERTY, use_ctrl=True, callback=self.onChangeIOC) time.sleep(.1) # set value on IOC ioc_value = ca.create_channel("ioc:gwcachetest") ca.put(ioc_value, 10.0, wait=True) time.sleep(.1) if gwtests.verbose: print() self.assertTrue( self.eventsReceivedIOC == self.eventsReceivedGW, "After setting value, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue( are_diff == False, "At update {0} (change value), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs))) # set property on IOC ioc_hihi = ca.create_channel("ioc:gwcachetest.HIHI") ca.put(ioc_hihi, 123.0, wait=True) time.sleep(.1) if gwtests.verbose: print() ca.put(ioc_value, 11.0, wait=True) time.sleep(.1) if gwtests.verbose: print() self.assertTrue( self.eventsReceivedIOC == self.eventsReceivedGW, "After setting property, no. of received updates differ: GW {0}, IOC {1}" .format(str(self.eventsReceivedGW), str(self.eventsReceivedIOC))) (are_diff, diffs) = self.compareStructures() self.assertTrue( are_diff == False, "At update {0} (change property), received structure updates differ:\n\t{1}" .format(str(self.eventsReceivedIOC), "\n\t".join(diffs)))
from epics import ca import time import sys import pvnames mypv = pvnames.updating_pv1 def onChanges(pvname=None, value=None, **kw): sys.stdout.write( 'New Value: %s value=%s, kw=%s\n' %( pvname, str(value), repr(kw))) sys.stdout.flush() chid = ca.create_channel(mypv) eventID = ca.create_subscription(chid, callback=onChanges) t0 = time.time() while time.time()-t0 < 15.0: time.sleep(0.001)
def test_subscribe(): global change_count chid = ca.create_channel(mypv) eventID = ca.create_subscription(chid, callback=onChanges) wait(maxtime=10) assert change_count > 5