Acquisition in new daq
This commit is contained in:
@@ -2,6 +2,7 @@ import requests
|
||||
from pathlib import Path
|
||||
from time import sleep
|
||||
from ..devices_general.detectors import PvDataStream
|
||||
from ..acquisition.utilities import Acquisition
|
||||
|
||||
|
||||
class Daq:
|
||||
@@ -36,8 +37,20 @@ class Daq:
|
||||
self._event_master = event_master
|
||||
self._detectors_event_code = detectors_event_code
|
||||
|
||||
def acquire(self, file_name=None, Npulses=100, JF_factor=1, bsread_padding=0):
|
||||
pass
|
||||
def acquire(self, file_name=None, Npulses=100):
|
||||
acquisition = Acquisition(
|
||||
acquire=None,
|
||||
acquisition_kwargs={"file_names": outputfilenames, "Npulses": Npulses},
|
||||
hold=False,
|
||||
)
|
||||
def acquire():
|
||||
runno, file_names = acquire_pulses()
|
||||
acquisition.acquisition_kwargs.update({'file_names':file_names})
|
||||
|
||||
acquisition.set_acquire_foo(acquire)
|
||||
return acquisition
|
||||
|
||||
|
||||
|
||||
def acquire_pulses(self, Npulses, label=None, wait=True, **kwargs):
|
||||
ix = self.start(label=label, **kwargs)
|
||||
|
||||
@@ -16,10 +16,14 @@ class Acquisition:
|
||||
self.acquisition_kwargs = acquisition_kwargs
|
||||
for key, val in acquisition_kwargs.items():
|
||||
self.__dict__[key] = val
|
||||
self._acquire = acquire
|
||||
self._stopper = stopper
|
||||
self._thread = PropagatingThread(target=self._acquire)
|
||||
self._get_result = get_result
|
||||
if acquire:
|
||||
self.set_acquire_foo(acquire,hold=hold)
|
||||
|
||||
def set_acquire_foo(self,acquire,hold=True):
|
||||
self._acquire = acquire
|
||||
self._thread = PropagatingThread(target=self._acquire)
|
||||
if not hold:
|
||||
self._thread.start()
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import sys
|
||||
import select
|
||||
import tty
|
||||
import termios
|
||||
import time
|
||||
|
||||
arrow_up = '\x1b[A'
|
||||
arrow_UP = '\x1b[2A'
|
||||
arrow_down = '\x1b[B'
|
||||
arrow_right = '\x1b[C'
|
||||
arrow_left = '\x1b[D'
|
||||
shift_arrow_up = '\x1b[1;2A'
|
||||
shift_arrow_down = '\x1b[1;2B'
|
||||
shift_arrow_right = '\x1b[1;2C'
|
||||
shift_arrow_left = '\x1b[1;2D'
|
||||
|
||||
def isData():
|
||||
return select.select([sys.stdin], [], [], 1) == ([sys.stdin], [], [])
|
||||
|
||||
def getc():
|
||||
""" Non blocking get character """
|
||||
old_settings = termios.tcgetattr(sys.stdin)
|
||||
c=None
|
||||
try:
|
||||
tty.setcbreak(sys.stdin.fileno())
|
||||
if isData():
|
||||
c = sys.stdin.read(1)
|
||||
finally:
|
||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
|
||||
return c
|
||||
|
||||
|
||||
def wait_input():
|
||||
""" wait for a character and returns it """
|
||||
old_settings = termios.tcgetattr(sys.stdin)
|
||||
c=None
|
||||
try:
|
||||
tty.setcbreak(sys.stdin.fileno())
|
||||
while (not isData()):
|
||||
time.sleep(0.001)
|
||||
c = sys.stdin.read(1)
|
||||
if ( (c == '\x1b') ):
|
||||
cc = sys.stdin.read(2)
|
||||
if cc =='[1':
|
||||
c = c + cc + sys.stdin.read(3)
|
||||
else:
|
||||
c = c + cc
|
||||
return c
|
||||
finally:
|
||||
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
|
||||
return c
|
||||
|
||||
def wait_char(char='q'):
|
||||
""" wait for a specific character, default is q """
|
||||
c = None
|
||||
while (c != char):
|
||||
c=wait_input()
|
||||
# print "got |%s| but waiting for |%s|" % (c,char)
|
||||
|
||||
class KeyPress:
|
||||
def __init__(self,esc_key="q"):
|
||||
self.esc_key=esc_key
|
||||
self.last_key = None
|
||||
|
||||
def waitkey(self):
|
||||
a = wait_input()
|
||||
self.last_key=a
|
||||
return a
|
||||
|
||||
def isu(self):
|
||||
return (self.last_key==arrow_up)
|
||||
def isd(self):
|
||||
return (self.last_key==arrow_down)
|
||||
def isl(self):
|
||||
return (self.last_key==arrow_left)
|
||||
def isr(self):
|
||||
return (self.last_key==arrow_right)
|
||||
def issu(self):
|
||||
return (self.last_key==shift_arrow_up)
|
||||
def issd(self):
|
||||
return (self.last_key==shift_arrow_down)
|
||||
def issl(self):
|
||||
return (self.last_key==shift_arrow_left)
|
||||
def issr(self):
|
||||
return (self.last_key==shift_arrow_right)
|
||||
def isq(self):
|
||||
return (self.last_key==self.esc_key)
|
||||
def iskey(self,what):
|
||||
return (self.last_key==what)
|
||||
#wait_char('\x37')
|
||||
#s=wait_input()
|
||||
#print (s==arrow_up)
|
||||
|
||||
if (__name__ == "__main__"):
|
||||
while(1):
|
||||
print "press a key (q to exit)"
|
||||
a=wait_input()
|
||||
print "|%s|" % a
|
||||
if (a=="q"): break
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
def tweak_new(motor, step=0.1):
|
||||
help = "q = exit; up = step*2; down = step/2, left = neg dir, right = pos dir\n"
|
||||
help = help + "g = go abs, s = set"
|
||||
print "tweaking motor %s (pv=%s)" % (motor.name, motor.pvname)
|
||||
print "current position %s" % (motor.wm_string())
|
||||
step = float(step)
|
||||
oldstep = 0
|
||||
k = KeyPress.KeyPress()
|
||||
while k.isq() is False:
|
||||
if oldstep != step:
|
||||
nstr = "stepsize: %f" % step
|
||||
notice(nstr)
|
||||
sys.stdout.flush()
|
||||
oldstep = step
|
||||
k.waitkey()
|
||||
if k.isu():
|
||||
step = step * 2.0
|
||||
elif k.isd():
|
||||
step = step / 2.0
|
||||
elif k.isr():
|
||||
motor.umvr(step, show_previous=False)
|
||||
elif k.isl():
|
||||
motor.umvr(-step, show_previous=False)
|
||||
elif k.iskey("g"):
|
||||
print "enter absolute position (char to abort go to)"
|
||||
sys.stdout.flush()
|
||||
v = sys.stdin.readline()
|
||||
try:
|
||||
v = float(v.strip())
|
||||
motor.umv(v)
|
||||
except:
|
||||
print "value cannot be converted to float, exit go to mode ..."
|
||||
sys.stdout.flush()
|
||||
elif k.iskey("s"):
|
||||
print "enter new set value (char to abort setting)"
|
||||
sys.stdout.flush()
|
||||
v = sys.stdin.readline()
|
||||
try:
|
||||
v = float(v[0:-1])
|
||||
motor.set(v)
|
||||
except:
|
||||
print "value cannot be converted to float, exit go to mode ..."
|
||||
sys.stdout.flush()
|
||||
elif k.isq():
|
||||
break
|
||||
else:
|
||||
print help
|
||||
print "final position: %s" % motor.wm_string()
|
||||
Reference in New Issue
Block a user