def test_type_converions_1(self): write("CA type conversions scalars") pvlist = (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv, pvnames.double_pv2) chids = [] with no_simulator_updates(): for name in pvlist: chid = ca.create_channel(name) ca.connect_channel(chid) chids.append((chid, name)) ca.poll(evt=0.025, iot=5.0) ca.poll(evt=0.05, iot=10.0) values = {} for chid, name in chids: values[name] = ca.get(chid, as_string=True) for promotion in ('ctrl', 'time'): for chid, pvname in chids: write('=== %s chid=%s as %s' % (ca.name(chid), repr(chid), promotion)) time.sleep(0.01) if promotion == 'ctrl': ntype = ca.promote_type(chid, use_ctrl=True) else: ntype = ca.promote_type(chid, use_time=True) val = ca.get(chid, ftype=ntype) cval = ca.get(chid, as_string=True) if ca.element_count(chid) > 1: val = val[:12] self.assertEqual(cval, values[pvname])
def test_type_converions_2(self): write("CA type conversions arrays") pvlist = (pvnames.char_arr_pv, pvnames.long_arr_pv, pvnames.double_arr_pv) with no_simulator_updates(): chids = [] for name in pvlist: chid = ca.create_channel(name) ca.connect_channel(chid) chids.append((chid, name)) ca.poll(evt=0.025, iot=5.0) ca.poll(evt=0.05, iot=10.0) values = {} for chid, name in chids: values[name] = ca.get(chid) for promotion in ('ctrl', 'time'): for chid, pvname in chids: write('=== %s chid=%s as %s' % (ca.name(chid), repr(chid), promotion)) time.sleep(0.01) if promotion == 'ctrl': ntype = ca.promote_type(chid, use_ctrl=True) else: ntype = ca.promote_type(chid, use_time=True) val = ca.get(chid, ftype=ntype) cval = ca.get(chid, as_string=True) for a, b in zip(val, values[pvname]): self.assertEqual(a, b)
def test_type_converions_2(self): write("CA type conversions arrays\n") pvlist = (pvnames.char_arr_pv, pvnames.long_arr_pv, pvnames.double_arr_pv) with no_simulator_updates(): chids = [] for name in pvlist: chid = ca.create_channel(name) ca.connect_channel(chid) chids.append((chid, name)) ca.poll(evt=0.025, iot=5.0) ca.poll(evt=0.05, iot=10.0) values = {} for chid, name in chids: values[name] = ca.get(chid) for promotion in ('ctrl', 'time'): for chid, pvname in chids: write('=== %s chid=%s as %s\n' % (ca.name(chid), repr(chid), promotion)) time.sleep(0.01) if promotion == 'ctrl': ntype = ca.promote_type(chid, use_ctrl=True) else: ntype = ca.promote_type(chid, use_time=True) val = ca.get(chid, ftype=ntype) cval = ca.get(chid, as_string=True) for a, b in zip(val, values[pvname]): self.assertEqual(a, b)
def test_type_converions_1(self): write("CA type conversions scalars") pvlist = (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv, pvnames.double_pv2) chids = [] pause_updating() for name in pvlist: chid = ca.create_channel(name) ca.connect_channel(chid) chids.append((chid, name)) ca.poll(evt=0.025, iot=5.0) ca.poll(evt=0.05, iot=10.0) values = {} for chid, name in chids: values[name] = ca.get(chid, as_string=True) for promotion in ('ctrl', 'time'): for chid, pvname in chids: write('=== %s chid=%s as %s' % (ca.name(chid), repr(chid), promotion)) time.sleep(0.01) if promotion == 'ctrl': ntype = ca.promote_type(chid, use_ctrl=True) else: ntype = ca.promote_type(chid, use_time=True) val = ca.get(chid, ftype=ntype) cval = ca.get(chid, as_string=True) if ca.element_count(chid) > 1: val = val[:12] self.assertEqual(cval, values[pvname]) resume_updating()
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 connectGwStats(self): self.gw_vctotal = ca.create_channel("gwtest:vctotal") ca.connect_channel(self.gw_vctotal, timeout=.5) self.gw_pvtotal = ca.create_channel("gwtest:pvtotal") ca.connect_channel(self.gw_pvtotal, timeout=.5) self.gw_connected = ca.create_channel("gwtest:connected") ca.connect_channel(self.gw_connected, timeout=.5) self.gw_active = ca.create_channel("gwtest:active") ca.connect_channel(self.gw_active, timeout=.5) self.gw_inactive = ca.create_channel("gwtest:inactive") ca.connect_channel(self.gw_inactive, timeout=.5)
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 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
def batch_get(pv_list): chids = {} pvdata = {} for name in pv_list: chid = ca.create_channel(name, connect=False, auto_cb=False) chids[name] = chid for name, chid in chids.items(): ca.connect_channel(chid) ca.poll() for name, chid in chids.items(): ca.get(chid, wait=False) ca.poll() for name, chid in chids.items(): val = ca.get_complete(chid) pvdata[name] = val return pvdata
def test_Values(self): write("CA test Values (compare 5 values with caget)") os.system("rm ./caget.tst") vals = {} pause_updating() for pvn in (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv): os.system("caget -n -f5 %s >> ./caget.tst" % pvn) chid = ca.create_channel(pvn) ca.connect_channel(chid) vals[pvn] = ca.get(chid) rlines = open("./caget.tst", "r").readlines() for line in rlines: pvn, sval = [i.strip() for i in line[:-1].split(" ", 1)] tval = str(vals[pvn]) if pvn in (pvnames.float_pv, pvnames.double_pv): # use float precision! tval = "%.5f" % vals[pvn] self.assertEqual(tval, sval) resume_updating()
def get(d, pv_name, size, start, pid): ch = ca.create_channel(pv_name, connect=False, auto_cb=False) if ca.connect_channel(ch, timeout=1.0): d[pv_name] = ca.get(ch, wait=True) else: d[pv_name] = 'not connected' if len(d) == size: print int(round((time.time() - start) * 1000)) os.kill(pid, signal.SIGTERM)
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("-f", "--setupfile", help="setup file (default = monitor.dat)",nargs='?', const=0, default="monitor.dat") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity setup_file = args.setupfile global pvdata global mon_line global pvf global pvfull #read the setup file, which has the form #index TOP PVname Period(s) for line in file(setup_file): #read the lines in the setup file to pvdata monitor list if not (line.startswith("#") or len(line.split())<3): #skip comments and require 3 fields s=line.split() #split input into fields wf=PV(s[pvf.TOP]+":"+s[pvf.NAME]+"_wf") #wf, en are PVs for waveform and enable en=PV(s[pvf.TOP]+":"+s[pvf.NAME]+"_en") pvdata.append([s[0],s[pvf.TOP],s[pvf.NAME],s[pvf.PERIOD],wf,en,[]]) #add to list, with list for IDS #Call doNode() which works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here) #In this case, it calls my_node() for every element - see below. doNode.doNode(pvdata[mon_line][pvf.TOP],do_node=my_node, v=verbose) #now the pvf.ID array has been filled, try to connect to all the elements for n,chid in enumerate(pvdata[mon_line][pvf.ID]): if not ca.connect_channel(chid,timeout=0.001): if verbose: print pvfull[n], "... Not connected, chid = 0" pvdata[mon_line][pvf.ID][n]=0 else: if verbose: print pvfull[n], "... Connected, chid = ",chid pvdata[mon_line].append(numpy.zeros(len(pvdata[mon_line][pvf.ID]))) #create a zero numpy array for the data pvfull = [] #reset the list of names mon_line+=1 #increment the current line number #start a monitor thread for each for l in range(mon_line): t = Thread(target=monitor, args=(l,)) t.start() #do the poll loop here, to cover all monitor threads while mon_line > 0: ca.poll() time.sleep(1.0) print "poll"
def test_Values(self): write('CA test Values (compare 5 values with caget)') os.system('rm ./caget.tst') vals = {} with no_simulator_updates(): for pvn in (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv): os.system('caget -n -f5 %s >> ./caget.tst' % pvn) chid = ca.create_channel(pvn) ca.connect_channel(chid) vals[pvn] = ca.get(chid) rlines = open('./caget.tst', 'r').readlines() for line in rlines: pvn, sval = [i.strip() for i in line[:-1].split(' ', 1)] tval = str(vals[pvn]) if pvn in (pvnames.float_pv, pvnames.double_pv): # use float precision! tval = "%.5f" % vals[pvn] self.assertEqual(tval, sval)
def run_synchronous_get_optimized(pvs): """Run synchronous optimized get test.""" pvschid = [] for pvn in pvs: chid = ca.create_channel(pvn, connect=False, auto_cb=False) pvschid.append(chid) for chid in pvschid: ca.connect_channel(chid) ca.poll() for i in range(600): t0 = time.time() for chid in pvschid: ca.get(chid, wait=False) out = [] for chid in pvschid: out.append(ca.get_complete(chid)) print(f'dtime {(time.time()-t0)*1000:.1f}ms pos {out[0]:.0f}nm')
def test_Values(self): write( 'CA test Values (compare 5 values with caget)') os.system('rm ./caget.tst') vals = {} with no_simulator_updates(): for pvn in (pvnames.str_pv, pvnames.int_pv, pvnames.float_pv, pvnames.enum_pv, pvnames.long_pv): os.system('caget -n -f5 %s >> ./caget.tst' % pvn) chid = ca.create_channel(pvn) ca.connect_channel(chid) vals[pvn] = ca.get(chid) rlines = open('./caget.tst', 'r').readlines() for line in rlines: pvn, sval = [i.strip() for i in line[:-1].split(' ', 1)] tval = str(vals[pvn]) if pvn in (pvnames.float_pv,pvnames.double_pv): # use float precision! tval = "%.5f" % vals[pvn] self.assertEqual(tval, sval)
def _set_params2(self): """Set run params...""" functionName = '_set_params' pvdata = {} for name in self._pvnamelist: chid = ca.create_channel(name, connect=False, auto_cb=False) # note 1 pvdata[name] = [chid, None] for name, data in pvdata.items(): ca.connect_channel(data[0]) ca.poll() for name, data in pvdata.items(): ca.get(data[0], wait=False) # note 2 ca.poll() for name, data in pvdata.items(): val = ca.get_complete(data[0]) pvdata[name][1] = val #return { name: data[1] for name, data in pvdata.items()} ret = dict((name, data[1]) for name, data in pvdata.items()) print(ret) return ret
def run_subprocess(pvs, pipe): pvschid = [] for pv in pvs: chid = ca.create_channel(pv, connect=False, auto_cb=False) pvschid.append(chid) for chid in pvschid: ca.connect_channel(chid) time.sleep(5) for chid in pvschid: ftype = ca.promote_type(chid, use_time=True, use_ctrl=False) ca.poll() while pipe.recv(): for chid in pvschid: ca.get_with_metadata(chid, ftype=ftype, wait=False) out = [] for chid in pvschid: data = ca.get_complete_with_metadata(chid, ftype=ftype) out.append(data['timestamp']) pipe.send(out)
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_CreateChid_CheckTypeCount(): write('Simple Test: create chid, check count, type, host, and access') chid = ca.create_channel(pvnames.double_pv) ret = ca.connect_channel(chid) ca.pend_event(1.e-3) ftype = ca.field_type(chid) count = ca.element_count(chid) host = ca.host_name(chid) rwacc = ca.access(chid) assert chid is not None assert host is not None assert count == 1 assert ftype == 6 assert rwacc == 'read/write'
def testA_CreateChid_CheckTypeCount(self): write('Simple Test: create chid, check count, type, host, and access') chid = ca.create_channel(pvnames.double_pv) ret = ca.connect_channel(chid) ca.pend_event(1.e-3) ftype = ca.field_type(chid) count = ca.element_count(chid) host = ca.host_name(chid) rwacc = ca.access(chid) self.assertIsNot(chid, None) self.assertIsNot(host, None) self.assertEqual(count, 1) self.assertEqual(ftype, 6) self.assertEqual(rwacc,'read/write')
def testA_CreateChid_CheckTypeCount(self): write('Simple Test: create chid, check count, type, host, and access') chid = ca.create_channel(pvnames.double_pv) ret = ca.connect_channel(chid) ca.pend_event(1.e-3) ftype = ca.field_type(chid) count = ca.element_count(chid) host = ca.host_name(chid) rwacc = ca.access(chid) self.assertNotEqual(chid, None) self.assertNotEqual(host, None) self.assertEqual(count, 1) self.assertEqual(ftype, 6) self.assertEqual(rwacc,'read/write')
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))
pvnames = pvnames[:MAX_PVS] add('Read PV list: Will connect to %i PVs' % len(pvnames)) libca = ca.initialize_libca() for name in pvnames: chid = ca.create_channel(name, connect=False, auto_cb=False) results[name] = {'chid': chid} time.sleep(0.001) add("created PVs with ca_create_channel") for name in pvnames: ca.connect_channel(results[name]['chid']) time.sleep(0.001) add("connected to PVs with connect_channel") ca.pend_event(1.e-2) for name in pvnames: chid = results[name]['chid'] val = ca.get(chid, wait=False) results[name]['value'] = val add("did ca.get(wait=False)") ca.poll(2.e-3, 1.0) add("ca.poll() complete")
elif len(sys.argv) == 2: if str(sys.argv[1]) == 'clean': config = open('./config/pv_list_clean.json', 'r') else: config = open('./config/pv_list.json', 'r') else: sys.exit('at most two arguments allowed.') result = {} pv_list = json.loads(config.read()) start = time.time() for pv_name in pv_list: ch = ca.create_channel(pv_name, connect=False, auto_cb=False) result[pv_name] = [ch, None, None] for pv_name, data in result.items(): result[pv_name][1] = ca.connect_channel(data[0], timeout=1.0) ca.poll() for pv_name, data in result.items(): if result[pv_name][1]: ca.get(data[0], wait=False) ca.poll() for pv_name, data in result.items(): if result[pv_name][1]: val = ca.get_complete(data[0]) result[pv_name][2] = val else: result[pv_name][2] = 'not connected' duration = time.time() - start print int(round(duration * 1000))
pvnames = pvnames[:MAX_PVS] dt.add('Read PV list: Will connect to %i PVs' % len(pvnames)) libca = ca.initialize_libca() for name in pvnames: chid = ca.create_channel(name, connect=False, auto_cb=False) results[name] = {'chid': chid} time.sleep(0.001) dt.add("created PVs with ca_create_channel") for name in pvnames: ca.connect_channel(results[name]['chid']) time.sleep(0.001) dt.add("connected to PVs with connect_channel") ca.pend_event(1.e-2) for name in pvnames: chid = results[name]['chid'] val = ca.get(chid, wait=False) results[name]['value'] = val dt.add("did ca.get(wait=False)") ca.pend_event(1.e-2) dt.add("pend complete")
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)))
def main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) #add extra args and opts here parser.add_argument("pv", help="pvname") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global pvname global nChid pvname = args.pv #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here #In this case, it calls my_node() for every element - see below. doNode.doNode(args.top,do_node=my_node, v=verbose) wave=numpy.zeros(nChid) #create an array for all the values pvname_wf = args.top+":"+pvname+"_wf" #make the names of the PVs for waveform and enable switch pvname_en = args.top+":"+pvname+"_en" print pvname_wf,pvname_en pvwf = PV(pvname_wf) #set the PV pven = PV(pvname_en) #set the PV pven.put(1) for i in range(len(allids)): #connect call the channels if not ca.connect_channel(allids[i],timeout=0.001): allids[i]=0 print "Warning didn't connect to PV =", allnames[i], "ignoring this one" ca.poll() #Not sure exactly what this does! n=0 while n < 100000: for i in range(len(allids)): #print i, allids[i] if allids[i] > 0: ca.get(allids[i], wait=False) #Tell them all to start getting but don't wait ca.poll() for i in range(len(allids)): #now finish getting if allids[i] > 0: val = ca.get_complete(allids[i]) wave[i]=val if verbose: #print allnames[i],val pvwf.put(wave) time.sleep(0.5) if not pven.get(): exit() #print n,pven.get() n+=1
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)
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)
import time import sys from epics import ca import pvnames pvname = pvnames.double_pv host = pvnames.double_pv_host chid = ca.create_channel(pvname) ret = ca.connect_channel(chid) ca.pend_event(1.e-3) ftype = ca.field_type(chid) count = ca.element_count(chid) host = ca.host_name(chid) rwacc = ca.access(chid) if ftype == 6 and count == 1 and host.startswith(host) and rwacc.startswith( 'read'): sys.stdout.write('OK!\n') else: sys.stdout.write("Error\n")
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)
import time import sys from epics import ca import pvnames pvname = pvnames.double_pv host = pvnames.double_pv_host chid = ca.create_channel(pvname) ret = ca.connect_channel(chid) ca.pend_event(1.e-3) ftype = ca.field_type(chid) count = ca.element_count(chid) host = ca.host_name(chid) rwacc = ca.access(chid) if ftype ==6 and count == 1 and host.startswith(host) and rwacc.startswith('read'): sys.stdout.write('OK!\n') else: sys.stdout.write("Error\n")
def main(): parser = argparse.ArgumentParser( ) # parser for the inputs - must keep the 2 lines below. parser.add_argument("-f", "--setupfile", help="setup file (default = monitor.dat)", nargs='?', const=0, default="monitor.dat") parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity setup_file = args.setupfile global pvdata global mon_line global pvf global pvfull #read the setup file, which has the form #index TOP PVname Period(s) for line in file( setup_file ): #read the lines in the setup file to pvdata monitor list if not (line.startswith("#") or len(line.split()) < 3): #skip comments and require 3 fields s = line.split() #split input into fields wf = PV(s[pvf.TOP] + ":" + s[pvf.NAME] + "_wf") #wf, en are PVs for waveform and enable en = PV(s[pvf.TOP] + ":" + s[pvf.NAME] + "_en") pvdata.append( [s[0], s[pvf.TOP], s[pvf.NAME], s[pvf.PERIOD], wf, en, []]) #add to list, with list for IDS #Call doNode() which works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here) #In this case, it calls my_node() for every element - see below. doNode.doNode(pvdata[mon_line][pvf.TOP], do_node=my_node, v=verbose) #now the pvf.ID array has been filled, try to connect to all the elements for n, chid in enumerate(pvdata[mon_line][pvf.ID]): if not ca.connect_channel(chid, timeout=0.001): if verbose: print pvfull[n], "... Not connected, chid = 0" pvdata[mon_line][pvf.ID][n] = 0 else: if verbose: print pvfull[n], "... Connected, chid = ", chid pvdata[mon_line].append(numpy.zeros(len(pvdata[mon_line][ pvf.ID]))) #create a zero numpy array for the data pvfull = [] #reset the list of names mon_line += 1 #increment the current line number #start a monitor thread for each for l in range(mon_line): t = Thread(target=monitor, args=(l, )) t.start() #do the poll loop here, to cover all monitor threads while mon_line > 0: ca.poll() time.sleep(1.0)
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_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 main(): parser = argparse.ArgumentParser() # parser for the inputs - must keep the 2 lines below. parser.add_argument("top", help="top node") # must have a top node, -v VERBOSITY is an opion parser.add_argument("-v", "--verbosity", help="increase verbosity", nargs='?', const=0, default=0) #add extra args and opts here parser.add_argument("pv", help="pvname") args = parser.parse_args() #get the input args from the parser global verbose verbose = args.verbosity global pvname global nChid pvname = args.pv #This calls the doNode() (bottom of this file) that works recursively through the tree and calls do_node() #which you may overwrite by calling your own function (eg my_node() shown here #In this case, it calls my_node() for every element - see below. doNode.doNode(args.top,do_node=my_node, v=verbose) wave=numpy.zeros(nChid) #create an array for all the values pvname_wf = args.top+":"+pvname+"_wf" #make the names of the PVs for waveform and enable switch pvname_en = args.top+":"+pvname+"_en" print pvname_wf,pvname_en pvwf = PV(pvname_wf) #set the PV pven = PV(pvname_en) #set the PV pven.put(1) for i in range(len(allids)): #connect call the channels if not ca.connect_channel(allids[i],timeout=0.001): allids[i]=0 print "Warning didn't connect to PV =", allnames[i], "ignoring this one" ca.poll() #Not sure exactly what this does! n=0 while n < 100000: for i in range(len(allids)): #print i, allids[i] if allids[i] > 0: ca.get(allids[i], wait=False) #Tell them all to start getting but don't wait ca.poll() for i in range(len(allids)): #now finish getting if allids[i] > 0: val = ca.get_complete(allids[i]) wave[i]=val #if verbose: #print allnames[i],val pvwf.put(wave) time.sleep(0.5) if not pven.get(): exit() #print n,pven.get() n+=1
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))