File: test_pv_callback.py

package info (click to toggle)
python-pyepics 3.5.7%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,336 kB
  • sloc: python: 10,539; makefile: 112; javascript: 104; sh: 53
file content (29 lines) | stat: -rw-r--r-- 641 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import epics
import sys
import pvnames

pvname = pvnames.updating_pv1 # motor1
write = sys.stdout.write

def wait(timeout=10):
    t0 = time.time()
    while time.time() - t0 < timeout:
        time.sleep(1.e-4)

change_count = 0
def onChanges(pvname=None, value=None, char_value=None, **kw):
    global change_count
    change_count += 1
    try:
        write( 'PV %s %s, %s Changed!\n' % (pvname, repr(value), char_value))
    except:
        pass

def test_pv_callback():
    mypv = epics.get_pv(pvname)
    global change_count
    mypv.get_ctrlvars()
    mypv.add_callback(onChanges)
    wait(5)
    assert change_count > 5