async dset example

This commit is contained in:
Michael Davidsaver
2013-03-30 20:22:35 -04:00
parent 0be6dc6295
commit dac67e79ee
3 changed files with 35 additions and 1 deletions

View File

@ -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")
}

View File

@ -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

26
testApp/test4.py Normal file
View File

@ -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