Beispiel #1
0
    def test_emptyish_char_waveform_monitor(self):
        '''a test of a char waveform of length 1 (NORD=1): value "\0"
        with using auto_monitor
        '''
        with no_simulator_updates():
            zerostr = PV(pvnames.char_arr_pv, auto_monitor=True)
            zerostr.wait_for_connection()

            zerostr.put([0], wait=True)
            time.sleep(0.2)

            self.assertEquals(zerostr.get(as_string=True), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0])
            self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '')
            numpy.testing.assert_array_equal(
                zerostr.get(as_string=False, as_numpy=False), [0])

            zerostr.put([0, 0], wait=True)
            time.sleep(0.2)

            self.assertEquals(zerostr.get(as_string=True), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False),
                                             [0, 0])
            self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '')
            numpy.testing.assert_array_equal(
                zerostr.get(as_string=False, as_numpy=False), [0, 0])

        zerostr.disconnect()
Beispiel #2
0
    def test_subarray_zerolen(self):
        subarr1 = PV(pvnames.zero_len_subarr1)
        subarr1.wait_for_connection()

        val = subarr1.get(use_monitor=True, as_numpy=True)
        self.assertIsInstance(val, numpy.ndarray, msg='using monitor')
        self.assertEquals(len(val), 0, msg='using monitor')
        # caproto returns things in big endian, not native type
        # self.assertEquals(val.dtype, numpy.float64, msg='using monitor')

        val = subarr1.get(use_monitor=False, as_numpy=True)
        self.assertIsInstance(val, numpy.ndarray, msg='no monitor')
        self.assertEquals(len(val), 0, msg='no monitor')
Beispiel #3
0
    def test_subarray_1elem(self):
        with no_simulator_updates():
            # pv = PV(pvnames.zero_len_subarr1)
            pv = PV(pvnames.double_arr_pv)
            pv.wait_for_connection()

            val = pv.get(count=1, use_monitor=False)
            print('val is', val, type(val))
            self.assertIsInstance(val, numpy.ndarray)
            self.assertEqual(len(val), 1)

            val = pv.get(count=1, as_numpy=False, use_monitor=False)
            print('val is', val, type(val))
            self.assertIsInstance(val, list)
            self.assertEqual(len(val), 1)
Beispiel #4
0
    def test_putwait(self):
        write('Put with wait (using real motor!) \n')
        pv = PV(pvnames.motor1)
        # this works with a real motor, fail if it doesn't connect quickly
        if not pv.wait_for_connection(timeout=0.2):
            self.skipTest('Unable to connect to real motor record')

        val = pv.get()

        t0 = time.time()
        if val < 5:
            pv.put(val + 1.0, wait=True)
        else:
            pv.put(val - 1.0, wait=True)
        dt = time.time() - t0
        write('    put took %s sec\n' % dt)
        self.failUnless(dt > 0.1)

        # now with a callback!
        global put_callback_called
        put_callback_called = False

        def onPutdone(pvname=None, **kws):
            print('put done ', pvname, kws)
            global put_callback_called
            put_callback_called = True

        val = pv.get()
        if val < 5:
            pv.put(val + 1.0, callback=onPutdone)
        else:
            pv.put(val - 1.0, callback=onPutdone)

        t0 = time.time()
        while time.time() - t0 < dt * 1.50:
            time.sleep(0.02)

        write('    put should be done by now?  %s \n' % put_callback_called)
        self.failUnless(put_callback_called)

        # now using pv.put_complete
        val = pv.get()
        if val < 5:
            pv.put(val + 1.0, use_complete=True)
        else:
            pv.put(val - 1.0, use_complete=True)
        t0 = time.time()
        count = 0
        while time.time() - t0 < dt * 1.50:
            if pv.put_complete:
                break
            count = count + 1
            time.sleep(0.02)
        write(
            '    put_complete=%s (should be True), and count=%i (should be>3)\n'
            % (pv.put_complete, count))
        self.failUnless(pv.put_complete)
        self.failUnless(count > 3)
Beispiel #5
0
def test_thread_pv(threading_broadcaster):
    from caproto.threading.client import Context, PV

    pv1 = "XF:31IDA-OP{Tbl-Ax:X1}Mtr.VAL"
    # pv2 = "XF:31IDA-OP{Tbl-Ax:X2}Mtr.VAL"

    # Some user function to call when subscriptions receive data.
    called = []

    def user_callback(*, value, **kwargs):
        print()
        print('-- user callback', value)
        called.append(True)

    ctx = Context(threading_broadcaster, log_level='DEBUG')
    ctx.register()

    time_pv = PV(pv1, context=ctx, form='time')
    ctrl_pv = PV(pv1, context=ctx, form='ctrl')

    time_pv.wait_for_connection()
    time_pv.add_callback(user_callback)
    print('time read', time_pv.get())
    print('ctrl read', ctrl_pv.get())

    time_pv.put(3, wait=True)
    time_pv.put(6, wait=True)

    time.sleep(0.1)
    assert time_pv.get() == 6
    assert called

    print('read', time_pv.get())
    print('done')

    repr(time_pv)

    for k, v in PV.__dict__.items():
        if isinstance(v, property):
            getattr(time_pv, k)
            getattr(ctrl_pv, k)
Beispiel #6
0
    def test_emptyish_char_waveform_no_monitor(self):
        '''a test of a char waveform of length 1 (NORD=1): value "\0"
        without using auto_monitor
        '''
        with no_simulator_updates():
            zerostr = PV(pvnames.char_arr_pv, auto_monitor=False)
            zerostr.wait_for_connection()

            # elem_count = 128, requested count = None, libca returns count = 1
            zerostr.put([0], wait=True)
            self.assertEquals(zerostr.get(as_string=True), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0])
            self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False, as_numpy=False), [0])

            # elem_count = 128, requested count = None, libca returns count = 2
            zerostr.put([0, 0], wait=True)
            self.assertEquals(zerostr.get(as_string=True), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0, 0])
            self.assertEquals(zerostr.get(as_string=True, as_numpy=False), '')
            numpy.testing.assert_array_equal(zerostr.get(as_string=False, as_numpy=False), [0, 0])
Beispiel #7
0
    def test_putcomplete(self):
        write('Put with wait and put_complete (using real motor!) \n')
        vals = (1.35, 1.50, 1.44, 1.445, 1.45, 1.453, 1.446, 1.447, 1.450, 1.450, 1.490, 1.5, 1.500)
        p = PV(pvnames.motor1)
        # this works with a real motor, fail if it doesn't connect quickly
        if not p.wait_for_connection(timeout=0.2):
            self.skipTest('Unable to connect to real motor record')

        see_complete = []
        for v in vals:
            t0 = time.time()
            p.put(v, use_complete=True)
            count = 0
            for i in range(100000):
                time.sleep(0.001)
                count = count + 1
                if p.put_complete:
                    see_complete.append(True)
                    break
                # print( 'made it to value= %.3f, elapsed time= %.4f sec (count=%i)' % (v, time.time()-t0, count))
        self.failUnless(len(see_complete) > (len(vals) - 5))