def test_get_callback(pvnames, simulator): print("Callback test: changing PV must be updated\n") mypv = PV(pvnames.updating_pv1) NEWVALS = [] def onChanges(pvname=None, value=None, char_value=None, **kw): nonlocal NEWVALS print('PV %s %s, %s Changed!\n' % (pvname, repr(value), char_value)) NEWVALS.append(repr(value)) mypv.add_callback(onChanges) print('Added a callback. Now wait for changes...\n') t0 = time.time() while time.time() - t0 < 3: time.sleep(1.e-4) print(' saw %i changes.\n' % len(NEWVALS)) assert len(NEWVALS) > 3 mypv.clear_callbacks()
def test_waveform_callback_with_count_arg(pvnames, simulator): values = [] wf = PV(pvnames.char_arr_pv, count=32) def onChanges(pvname=None, value=None, char_value=None, **kw): print('PV %s %s, %s Changed!\n' % (pvname, repr(value), char_value)) values.append(value) wf.add_callback(onChanges) print('Added a callback. Now wait for changes...\n') t0 = time.time() while time.time() - t0 < 3: time.sleep(1.e-4) if len(values) > 0: break assert len(values) > 0 assert len(values[0]) == 32 wf.clear_callbacks()
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)