File: pv_disconnect_with_getcb.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 (51 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (2)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# example of using a connection callback that will be called
# for any change in connection status

import epics
import time
import sys
from  pvnames import updating_pv1, updating_pvlist
epics.ca.PREEMPTIVE_CALLBACK = True 
write = sys.stdout.write
def onConnectionChange(pvname=None, conn= None, **kws):
    write('Connection changed: %s conn=%s (%s)\n' % (pvname,  repr(conn), time.ctime()))
    sys.stdout.flush()

def onValueChange(pvname=None, value=None, host=None, **kws):
    write('Value changed: %s = %s (%s)\n' % ( pvname, repr(value), time.ctime()))
    sys.stdout.flush()


# pv1 = epics.PV(updating_pv1, 
#                 connection_callback= onConnectionChange,
#                 callback= onValueChange)
# 
pxs = [epics.PV(thispv, 
                connection_callback= onConnectionChange,
                callback= onValueChange) for thispv in updating_pvlist]

for x in pxs:
    write("%s = %s\n" % (x.pvname, x.get(as_string=True)))

write('Now waiting, watching values and connection changes:\n')
t0 = time.time()
while time.time()-t0 < 300:
    try:
        time.sleep(0.01)
    except KeyboardInterrupt:
        break
#
# write('Some value changes should have been seens\n')
# write('Now, restart the IOC:\n')
# t0 = time.time()
# while time.time()-t0 < 60:
#     time.sleep(0.01)
# 
# write('You should have seen a connection message and new values\n')


write("done!\n")

epics.ca.show_cache()