def test_DoubleVal(self): pvn = pvnames.double_pv chid = ca.create_channel(pvn,connect=True) cdict = ca.get_ctrlvars(chid) write( 'CA testing CTRL Values for a Double (%s)' % (pvn)) self.failUnless('units' in cdict) self.failUnless('precision' in cdict) self.failUnless('severity' in cdict) hostname = ca.host_name(chid) self.failUnless(len(hostname) > 1) count = ca.element_count(chid) self.assertEqual(count,1) ftype= ca.field_type(chid) self.assertEqual(ftype,ca.dbr.DOUBLE) prec = ca.get_precision(chid) self.assertEqual(prec, pvnames.double_pv_prec) units= ca.bytes2str(ca.get_ctrlvars(chid)['units']) self.assertEqual(units, pvnames.double_pv_units) rwacc= ca.access(chid) self.failUnless(rwacc.startswith('read'))
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_DoubleVal(self): pvn = pvnames.double_pv chid = ca.create_channel(pvn,connect=True) cdict = ca.get_ctrlvars(chid) write( 'CA testing CTRL Values for a Double (%s)' % (pvn)) self.failUnless('units' in cdict) self.failUnless('precision' in cdict) self.failUnless('severity' in cdict) hostname = ca.host_name(chid) self.failUnless(len(hostname) > 1) count = ca.element_count(chid) self.assertEqual(count,1) ftype= ca.field_type(chid) self.assertEqual(ftype,ca.dbr.DOUBLE) prec = ca.get_precision(chid) self.assertEqual(prec, pvnames.double_pv_prec) units= ca.BYTES2STR(ca.get_ctrlvars(chid)['units']) self.assertEqual(units, pvnames.double_pv_units) rwacc= ca.access(chid) self.failUnless(rwacc.startswith('read'))
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 test_xArray2(self): write('Array Test: get fewer than max vals with ca.get(count=0)') chid = ca.create_channel(pvnames.double_arrays[0]) maxpts = ca.element_count(chid) npts = max(2, maxpts/2 - 1) dat = numpy.random.normal(size=npts) ca.put(chid, dat) out = ca.get(chid, count=0) self.assertTrue(isinstance(out, numpy.ndarray)) self.assertTrue(len(out) == npts)
def test_xArray2(self): write('Array Test: get fewer than max vals with ca.get(count=0)') chid = ca.create_channel(pvnames.double_arrays[0]) maxpts = ca.element_count(chid) npts = max(2, maxpts/2 - 1) dat = numpy.random.normal(size=npts) ca.put(chid, dat) out = ca.get(chid, count=0) self.assertTrue(isinstance(out, numpy.ndarray)) self.assertEqual(len(out), npts)
def test_xArray2(self): write('Array Test: get fewer than max vals using ca.get(count=0)') chid = ca.create_channel(pvnames.double_arrays[0]) maxpts = ca.element_count(chid) npts = int(max(2, maxpts/2.3 - 1)) dat = numpy.random.normal(size=npts) ca.put(chid, dat) out1 = ca.get(chid) self.assertTrue(isinstance(out1, numpy.ndarray)) self.assertEqual(len(out1), maxpts) out2 = ca.get(chid, count=0) self.assertTrue(isinstance(out2, numpy.ndarray)) self.assertEqual(len(out2), npts)
def test_xArray2(self): write('Array Test: get fewer than max vals using ca.get(count=0)') chid = ca.create_channel(pvnames.double_arrays[0]) maxpts = ca.element_count(chid) npts = int(max(2, maxpts/2.3 - 1)) write('max points is %s' % (maxpts, )) dat = numpy.random.normal(size=npts) write('setting array to a length of npts=%s' % (npts, )) ca.put(chid, dat) out1 = ca.get(chid) self.assertTrue(isinstance(out1, numpy.ndarray)) self.assertEqual(len(out1), npts) out2 = ca.get(chid, count=0) self.assertTrue(isinstance(out2, numpy.ndarray)) self.assertEqual(len(out2), npts)
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 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 test_DoubleVal(): pvn = pvnames.double_pv chid = ca.create_channel(pvn, connect=True) cdict = ca.get_ctrlvars(chid) write('CA testing CTRL Values for a Double (%s)' % (pvn)) assert 'units' in cdict assert 'precision' in cdict assert 'severity' in cdict assert len(ca.host_name(chid)) > 2 assert ca.element_count(chid) == 1 assert ca.field_type(chid) == ca.dbr.DOUBLE assert ca.get_precision(chid) == pvnames.double_pv_prec assert ca.get_ctrlvars(chid)['units'] == pvnames.double_pv_units assert ca.access(chid).startswith('read')
def _internal_cnct_callback(self, conn, **kw): """ Snapshot specific handling of connection status on pyepics connection_callback. Check if PV is array, then call user callback if provided. :param conn: True if connected, False if not connected. :param kw: :return: """ # PV layer of pyepics handles arrays strange. In case of having a waveform with NORD field "1" it will not # interpret it as array. Instead of native "pv.count" which is a NORD field of waveform record it should use # number of may elements "pv.nelm" (NELM field). However this also acts wrong because it simply does following: # if count == 1, then nelm = 1 # The true NELM info can be found with ca.element_count(self.chid). self.is_array = (ca.element_count(self.chid) > 1) # If user specifies his own connection callback, call it here. for clb in self.conn_callbacks.values(): clb(conn=conn, **kw)
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")
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")