From dac67e79ee5e35519b20fdce3502c24415c12fe5 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 30 Mar 2013 20:22:35 -0400 Subject: [PATCH] async dset example --- testApp/test1.db | 6 ++++++ testApp/test3.py | 4 +++- testApp/test4.py | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 testApp/test4.py diff --git a/testApp/test1.db b/testApp/test1.db index 9325efc..c685b8c 100644 --- a/testApp/test1.db +++ b/testApp/test1.db @@ -22,3 +22,9 @@ record(waveform, "$(P)wf") { field(NELM, "10") field(SCAN, "2 second") } + +record(longin, "$(P)async:cnt") { + field(DTYP, "Python Device") + field(INP , "@test4") + field(SCAN, "1 second") +} diff --git a/testApp/test3.py b/testApp/test3.py index c966ed4..ec44a47 100644 --- a/testApp/test3.py +++ b/testApp/test3.py @@ -28,7 +28,9 @@ class WfSup(object): val=self.arr[:N] x=self.x[:N] - val[:] = pha*x + # calculate inplace: uniform(0.5,2.0)*sin(pha*x)+2 + val[:] = x + val[:] *= pha np.sin(val, out=val) val[:]*=uniform(0.5,2.0) val[:]+=2 diff --git a/testApp/test4.py b/testApp/test4.py new file mode 100644 index 0000000..c200deb --- /dev/null +++ b/testApp/test4.py @@ -0,0 +1,26 @@ + +import threading + +AsyncComplete = object() + +class Counter(object): + def __init__(self, rec, args): + self.val = rec.field('VAL') + self.nextval = None + self.timer = None + def detach(self, rec): + if self.timer: + self.timer.cancel() + + def process(self, rec, reason): + if reason is AsyncComplete: + self.val.putval(self.nextval) + + else: + self.nextval = self.val.getval()+1 + self.timer = threading.Timer(0.2, rec.asyncFinish, kwargs={'reason':AsyncComplete}) + rec.asyncStart() + self.timer.start() + + +build = Counter