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

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

    assert zerostr.get(as_string=True) == ''
    numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0])
    assert 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)

    assert zerostr.get(as_string=True) == ''
    numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0, 0])
    assert 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()
Exemplo n.º 2
0
def test_subarray_1elem(pvnames):
    # 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))
    assert isinstance(val, numpy.ndarray)
    assert len(val) == 1

    val = pv.get(count=1, as_numpy=False, use_monitor=False)
    print('val is', val, type(val))
    assert isinstance(val, list)
    assert len(val) == 1
Exemplo n.º 3
0
def test_subarray_zerolen(pvnames):
    subarr1 = PV(pvnames.zero_len_subarr1)
    subarr1.wait_for_connection()

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

    val = subarr1.get(use_monitor=False, as_numpy=True)
    assert isinstance(val, numpy.ndarray), 'no monitor'
    assert len(val) == 0, 'no monitor'
Exemplo n.º 4
0
def test_putwait(pvnames):
    print('Put with wait (using real motor!) \n')
    pv = PV(pvnames.motor1)
    if not pv.wait_for_connection():
        raise TimeoutError('simulated motor connection failed?')

    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
    print('    put took %s sec\n' % dt)
    assert dt > 0.1

    # now with a callback!
    put_callback_called = False

    def onPutdone(pvname=None, **kws):
        print('put done ', pvname, kws)
        nonlocal 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)

    print('    put should be done by now?  %s \n' % put_callback_called)
    assert 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)
    print(
        '    put_complete=%s (should be True), and count=%i (should be>3)\n' %
        (pv.put_complete, count))
    assert pv.put_complete
    assert count > 3
Exemplo n.º 5
0
def test_emptyish_char_waveform_no_monitor(pvnames):
    '''a test of a char waveform of length 1 (NORD=1): value "\0"
    without using auto_monitor
    '''
    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)
    assert zerostr.get(as_string=True) == ''
    numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0])
    assert 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)
    assert zerostr.get(as_string=True) == ''
    numpy.testing.assert_array_equal(zerostr.get(as_string=False), [0, 0])
    assert zerostr.get(as_string=True, as_numpy=False) == ''
    numpy.testing.assert_array_equal(
        zerostr.get(as_string=False, as_numpy=False), [0, 0])
Exemplo n.º 6
0
def test_pyepics_pv(context):
    pv1 = "sim:mtr1"
    ctx = context

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

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

    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)
Exemplo n.º 7
0
def test_putcomplete(pvnames):
    print('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)
    if not p.wait_for_connection():
        raise TimeoutError('simulated motor connection failed?')

    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)
                print('See completion')
                break
            # print('made it to value= %.3f, elapsed time= %.4f sec (count=%i)' % (v, time.time()-t0, count))
    assert len(see_complete) > (len(vals) - 5)