Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    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])
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
def monitor(
    mon_line
):  #this is run as a thread to monitor a specific pv for many elements
    global pvdata
    global pvf

    while mon_line > -1:  #ie infinite loop
        if not pvdata[mon_line][pvf.EN].get():  #if not enabled just wait 1s
            print "Not enabled: ", pvdata[mon_line][
                pvf.TOP] + ":" + pvdata[mon_line][pvf.NAME] + "_wf"
            time.sleep(1.0)
        else:  #if enabled
            for chid in pvdata[mon_line][pvf.ID]:  #for all the chids
                if chid > 0:  #if the channel is connected
                    ca.get(chid, wait=False
                           )  #Tell them all to start getting but don't wait
            for n, chid in enumerate(
                    pvdata[mon_line][pvf.ID]):  #for all the chids
                if chid > 0:  #if the channel is connected
                    pvdata[mon_line][pvf.ARRAY][n] = ca.get_complete(
                        chid)  #get the value to the array
            pvdata[mon_line][pvf.WF].put(
                pvdata[mon_line][pvf.ARRAY])  #put to the waveform
            #print "mon_line",mon_line,pvdata[mon_line][pvf.PERIOD]
            time.sleep(float(
                pvdata[mon_line][pvf.PERIOD]))  #wait for the refresh period
Ejemplo n.º 7
0
 def test_xArray1(self):
     write('Array Test: get(wait=False) / get_complete()')
     chid = ca.create_channel(pvnames.double_arrays[0])
     val0 = ca.get(chid)
     aval = ca.get(chid, wait=False)
     self.assertTrue(aval is  None)
     val1 = ca.get_complete(chid)
     self.assertTrue(all(val0 == val1))
Ejemplo n.º 8
0
 def test_xArray1(self):
     write('Array Test: get(wait=False) / get_complete()')
     chid = ca.create_channel(pvnames.double_arrays[0])
     val0 = ca.get(chid)
     aval = ca.get(chid, wait=False)
     self.assertTrue(aval is  None)
     val1 = ca.get_complete(chid)
     self.assertTrue(all(val0 == val1))
Ejemplo n.º 9
0
 def test_xArray3(self):
     write('Array Test: get char array as string')
     chid = ca.create_channel(pvnames.char_arrays[0])
     val = ca.get(chid)
     self.assertTrue(isinstance(val, numpy.ndarray))
     char_val = ca.get(chid, as_string=True)
     self.assertTrue(isinstance(char_val, str))
     conv = ''.join([chr(i) for i in val])
     self.assertEqual(conv, char_val)
Ejemplo n.º 10
0
def test_xArray3():
    write('Array Test: get char array as string')
    chid = ca.create_channel(pvnames.char_arrays[0])
    val = ca.get(chid)
    assert isinstance(val, numpy.ndarray)
    char_val = ca.get(chid, as_string=True)
    assert isinstance(char_val, str)
    conv = ''.join([chr(i) for i in val])
    assert conv == char_val
Ejemplo n.º 11
0
 def test_xArray3(self):
     write('Array Test: get char array as string')
     chid = ca.create_channel(pvnames.char_arrays[0])
     val = ca.get(chid, count=0)
     self.assertTrue(isinstance(val, numpy.ndarray))
     char_val = ca.get(chid, as_string=True)
     self.assertTrue(isinstance(char_val, str))
     conv = ''.join([chr(i) for i in val])
     self.assertTrue(conv == char_val)
Ejemplo n.º 12
0
 def test_putwait(self):
     'test put with wait'
     pvn = pvnames.non_updating_pv
     chid = ca.create_channel(pvn, connect=True)
     o  = ca.put(chid, -1, wait=True)
     val = ca.get(chid)
     self.assertEqual(val, -1)
     o  = ca.put(chid, 2, wait=True)
     val = ca.get(chid)
     self.assertEqual(val, 2)
Ejemplo n.º 13
0
 def test_putwait(self):
     'test put with wait'
     pvn = pvnames.non_updating_pv
     chid = ca.create_channel(pvn, connect=True)
     o  = ca.put(chid, -1, wait=True)
     val = ca.get(chid)
     self.assertEqual(val, -1)
     o  = ca.put(chid, 2, wait=True)
     val = ca.get(chid)
     self.assertEqual(val, 2)
Ejemplo n.º 14
0
def test_putwait():
    'test put with wait'
    pvn = pvnames.non_updating_pv
    chid = ca.create_channel(pvn, connect=True)
    o = ca.put(chid, -1, wait=True)
    time.sleep(0.01)
    assert ca.get(chid) == -1

    ca.put(chid, 2, wait=True)
    assert ca.get(chid) == 2
Ejemplo n.º 15
0
 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)
Ejemplo n.º 16
0
    def test_Array0(self):
        write('Array Test: get double array as numpy array, ctypes Array, and list')
        chid = ca.create_channel(pvnames.double_arrays[0])
        aval = ca.get(chid)
        cval = ca.get(chid, as_numpy=False)

        self.assertTrue(isinstance(aval, numpy.ndarray))
        self.assertTrue(len(aval) > 2)

        self.assertTrue(isinstance(cval, ctypes.Array))
        self.assertTrue(len(cval) > 2)
        lval = list(cval)
        self.assertTrue(isinstance(lval, list))
        self.assertTrue(len(lval) > 2)
        self.assertTrue(lval == list(aval))
Ejemplo n.º 17
0
 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)
Ejemplo n.º 18
0
    def test_Array0(self):
        write('Array Test: get double array as numpy array, ctypes Array, and list')
        chid = ca.create_channel(pvnames.double_arrays[0])
        aval = ca.get(chid)
        cval = ca.get(chid, as_numpy=False)

        self.assertTrue(isinstance(aval, numpy.ndarray))
        self.assertTrue(len(aval) > 2)

        self.assertTrue(isinstance(cval, ctypes.Array))
        self.assertTrue(len(cval) > 2)
        lval = list(cval)
        self.assertTrue(isinstance(lval, list))
        self.assertTrue(len(lval) > 2)
        self.assertTrue(lval == list(aval))
Ejemplo n.º 19
0
def test_CreateChidWithConn():
    write('Simple Test: create chid with conn callback')
    chid = ca.create_channel(pvnames.int_pv, callback=onConnect)
    val = ca.get(chid)
    global CONN_DAT
    conn = CONN_DAT.get(pvnames.int_pv, None)
    assert conn
Ejemplo n.º 20
0
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
Ejemplo n.º 21
0
def get_read_CMD():
    """
    Receive Value for Read CMD
    """
    getReadCMD = ca.get(chSendRead)
    valGotten = convert_receive_read_value(getReadCMD)
    return valGotten
Ejemplo n.º 22
0
def get_write_CMD():
    """
    Receive Value for Write CMD
    """
    getWriteCMD = ca.get(chSendWrite)
    valGotten = convert_receive_write_value(getWriteCMD)
    return valGotten
Ejemplo n.º 23
0
    def testA_CreateChidWithConn(self):
        write("Simple Test: create chid with conn callback")
        chid = ca.create_channel(pvnames.int_pv, callback=onConnect)
        val = ca.get(chid)

        global CONN_DAT
        conn = CONN_DAT.get(pvnames.int_pv, None)
        self.assertEqual(conn, True)
Ejemplo n.º 24
0
    def testA_CreateChidWithConn(self):
        write('Simple Test: create chid with conn callback\n')
        chid = ca.create_channel(pvnames.int_pv, callback=onConnect)
        val = ca.get(chid)

        global CONN_DAT
        conn = CONN_DAT.get(pvnames.int_pv, None)
        self.assertEqual(conn, True)
def _compare_pvs(pvs, values):
    """."""
    while True:
        vals = []
        for pv in pvs:
            ca.get(pv.chid, wait=False)
        for pv in pvs:
            val = ca.get_complete(pv.chid)
            if val is None:
                raise ValueError('val is None')
            vals.append(val)
        vals = np.asarray(vals, dtype=float)
        eq = np.allclose(vals, values, atol=1e-7)
        if eq:
            break
        # else:
        #     print(np.max(vals - values))
        time.sleep(0.001)
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
 def testA_GetNonExistentPV(self):
     write('Simple Test: get on a non-existent PV')
     chid = ca.create_channel('Definitely-Not-A-Real-PV')
     val, out = None, False
     try:
         val = ca.get(chid)
     except ca.ChannelAccessException:
         out = True
     assert(out)
Ejemplo n.º 28
0
def monitor(mon_line):                               #this is run as a thread to monitor a specific pv for many elements
    global pvdata
    global pvf

    while mon_line > -1:                                 #ie infinite loop
        if not pvdata[mon_line][pvf.EN].get():               #if not enabled just wait 1s
            print "Not enabled: ",pvdata[mon_line][pvf.TOP]+":"+pvdata[mon_line][pvf.NAME]+"_wf"
            time.sleep(1.0)
        else:                                                #if enabled
            for chid in pvdata[mon_line][pvf.ID]:                #for all the chids
                if chid > 0:                                        #if the channel is connected
                    ca.get(chid, wait=False)                           #Tell them all to start getting but don't wait
            for n,chid in enumerate(pvdata[mon_line][pvf.ID]):   #for all the chids
                if chid > 0:                                        #if the channel is connected
                    pvdata[mon_line][pvf.ARRAY][n]=ca.get_complete(chid)#get the value to the array
            pvdata[mon_line][pvf.WF].put(pvdata[mon_line][pvf.ARRAY])#put to the waveform      
            #print "mon_line",mon_line,pvdata[mon_line][pvf.PERIOD]
            time.sleep(float(pvdata[mon_line][pvf.PERIOD]))          #wait for the refresh period
Ejemplo n.º 29
0
def get_version_CMD():
    """
    Get Hardware and Software Version
    """
    getVersionCMD = calculate_send_read_CMD(5, 1)
    ca.put(chGetVersion, getVersionCMD)
    time.sleep(0.1)
    versionArr = ca.get(chGetVersion)
    versionGotten = convert_receive_read_value(versionArr)
    return versionGotten
Ejemplo n.º 30
0
def get_sn_CMD():
    """
    Get Serial Number
    """
    getSNCMD = calculate_send_read_CMD(5, 2)
    ca.put(chGetSN, getSNCMD)
    time.sleep(0.1)
    snArr = ca.get(chGetSN)
    snGotten = convert_receive_read_value(snArr)
    return snGotten
Ejemplo n.º 31
0
def get_unit_CMD():
    """
    Get Pressure Unit
    """
    getUnitCMD = calculate_send_read_CMD(5, 4)
    ca.put(chGetUnit, getUnitCMD)
    time.sleep(0.1)
    unitArr = ca.get(chGetUnit)
    unitGotten = convert_receive_read_value(unitArr)
    return unitGotten
Ejemplo n.º 32
0
def get_pn_CMD():
    """
    Get Part Number
    """
    getPNCMD = calculate_send_read_CMD(5, 3)
    ca.put(chGetPN, getPNCMD)
    time.sleep(0.1)
    pnArr = ca.get(chGetPN)
    pnGotten = convert_receive_read_value(pnArr)
    return pnGotten
Ejemplo n.º 33
0
def get_press1_CMD():
    """
    Get Pressure Data in CH.1
    """
    getPressCMD1 = calculate_send_read_CMD(1, 29)
    ca.put(chGetPress1, getPressCMD1)
    time.sleep(0.1)
    pressArr1 = ca.get(chGetPress1)
    pressGotten1 = convert_receive_read_value(pressArr1)
    return pressGotten1
Ejemplo n.º 34
0
def get_press2_CMD():
    """
    Get Pressure Data in CH.2
    """
    getPressCMD2 = calculate_send_read_CMD(2, 29)
    ca.put(chGetPress2, getPressCMD2)
    time.sleep(0.1)
    pressArr2 = ca.get(chGetPress2)
    pressGotten2 = convert_receive_read_value(pressArr2)
    return pressGotten2
Ejemplo n.º 35
0
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')
Ejemplo n.º 36
0
    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)
Ejemplo n.º 37
0
    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)
Ejemplo n.º 38
0
 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
Ejemplo n.º 39
0
    def ReturnVisitID(self):
        try:
            if self.visit_id == None:
                if ca.isConnected(self.chid):
                    return ca.get(self.chid)
                else:
                    raise EnvironmentError('Cannot connect to epics')
            else:
                return self.visit_id

        except Exception as ex:
            self.conn.rollback()
            template = "An exception of type {0} occured. {1!r}"
            message = template.format(type(ex).__name__, ex.args)
            self.logger.error(message)
Ejemplo n.º 40
0
 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()
Ejemplo n.º 41
0
 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)
Ejemplo n.º 42
0
 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)
Ejemplo n.º 43
0
    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))
Ejemplo n.º 44
0
    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 updateGwStats(self):
     self.vctotal = ca.get(self.gw_vctotal)
     self.pvtotal = ca.get(self.gw_pvtotal)
     self.connected = ca.get(self.gw_connected)
     self.active = ca.get(self.gw_active)
     self.inactive = ca.get(self.gw_inactive)
Ejemplo n.º 46
0
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")

for name in pvnames:
    results[name]['value'] = ca.get_complete(results[name]['chid'])

add("ca.get_complete() for all PVs")

f = open('fastconn_pvdata.sav', 'w')
for name, val in results.items():
    f.write("%s %s\n" % (name.strip(), val['value']))
f.close()
Ejemplo n.º 47
0
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")

for name in pvnames:
    chid = results[name]['chid']    
    val = ca.get_complete(chid)
    results[name]['value'] =  val
    

dt.add("unpacked PV values")
 
f = open('fastconn_pvdata.sav', 'w')
Ejemplo n.º 48
0
    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))
    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))
Ejemplo n.º 50
0
 def testA_GetNonExistentPV(self):
     write('Simple Test: get on a non-existent PV')
     chid = ca.create_channel('Definitely-Not-A-Real-PV')
     val = ca.get(chid)
     self.assertEqual(val, None)
Ejemplo n.º 51
0
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