async dset example
This commit is contained in:
@ -22,3 +22,9 @@ record(waveform, "$(P)wf") {
|
|||||||
field(NELM, "10")
|
field(NELM, "10")
|
||||||
field(SCAN, "2 second")
|
field(SCAN, "2 second")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
record(longin, "$(P)async:cnt") {
|
||||||
|
field(DTYP, "Python Device")
|
||||||
|
field(INP , "@test4")
|
||||||
|
field(SCAN, "1 second")
|
||||||
|
}
|
||||||
|
@ -28,7 +28,9 @@ class WfSup(object):
|
|||||||
val=self.arr[:N]
|
val=self.arr[:N]
|
||||||
x=self.x[: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)
|
np.sin(val, out=val)
|
||||||
val[:]*=uniform(0.5,2.0)
|
val[:]*=uniform(0.5,2.0)
|
||||||
val[:]+=2
|
val[:]+=2
|
||||||
|
26
testApp/test4.py
Normal file
26
testApp/test4.py
Normal 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
|
Reference in New Issue
Block a user