File: ca_subscribe2.py

package info (click to toggle)
python-pyepics 3.4.1%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,080 kB
  • sloc: python: 11,184; makefile: 106; javascript: 104; sh: 1
file content (28 lines) | stat: -rw-r--r-- 542 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
import time
import sys

from epics import ca

import pvnames

pvname = pvnames.updating_pv1

def wait(step=0.1, maxtime=30):
    t0 = time.time()
    while time.time()-t0 < maxtime:
        time.sleep(step)

    
def setup_callback(pvname):
    def my_cb(pvname=None, value=None, **kw):
       sys.stdout.write( 'get: %s  value=%s, kw=%s\n' %( pvname, str(value), repr(kw)))
       sys.stdout.flush()

    chid = ca.create_channel(pvname)
    return ca.create_subscription(chid, callback=my_cb)

cb_ref = setup_callback(pvname)

wait()