add shortcut for acquisition modules
acq(<goal>) sets goal, starts and waits for completion
This commit is contained in:
@@ -64,6 +64,8 @@ LOG_LEVELS = {
|
||||
'off': logging.ERROR+1}
|
||||
CLR = '\r\x1b[K' # code to move to the left and clear current line
|
||||
|
||||
UNDEF = object()
|
||||
|
||||
|
||||
class Handler(logging.StreamHandler):
|
||||
def emit(self, record):
|
||||
@@ -213,8 +215,8 @@ class Module:
|
||||
clientenv.raise_with_short_traceback(error)
|
||||
return value
|
||||
|
||||
def __call__(self, target=None):
|
||||
if target is None:
|
||||
def __call__(self, target=UNDEF):
|
||||
if target is UNDEF:
|
||||
return self.read()
|
||||
watch_params = ['value', 'status']
|
||||
for pname in watch_params:
|
||||
@@ -222,7 +224,15 @@ class Module:
|
||||
updateEvent=self._watch_parameter,
|
||||
callimmediately=False)
|
||||
|
||||
self.target = target # this sets self._is_driving
|
||||
if 'go' in self._commands:
|
||||
if 'goal' in self._parameters and target is not None:
|
||||
self.goal_enable = True
|
||||
self.goal = target
|
||||
if 'target' in self._parameters:
|
||||
self.target = target
|
||||
self.go()
|
||||
elif 'target' in self._parameters:
|
||||
self.target = target # this sets self._is_driving
|
||||
|
||||
def loop():
|
||||
while self._is_driving:
|
||||
@@ -232,7 +242,10 @@ class Module:
|
||||
loop()
|
||||
except KeyboardInterrupt as e:
|
||||
self._secnode.log.info('-- interrupted --')
|
||||
self.stop()
|
||||
try:
|
||||
self.stop()
|
||||
except Exception as e:
|
||||
print(f'while stopping: {e!r}')
|
||||
try:
|
||||
loop() # wait for stopping to be finished
|
||||
except KeyboardInterrupt:
|
||||
@@ -297,6 +310,8 @@ class Param:
|
||||
|
||||
|
||||
class Command:
|
||||
_obj = None
|
||||
|
||||
def __init__(self, name, modname, secnode):
|
||||
self.name = name
|
||||
self.modname = modname
|
||||
@@ -311,11 +326,14 @@ class Command:
|
||||
result, _ = self.exec(self.modname, self.name, *args)
|
||||
else:
|
||||
result, _ = self.exec(self.modname, self.name, args or None)
|
||||
if self.name == 'go' and self._obj:
|
||||
self._obj._is_driving = self._obj._isBusy()
|
||||
return result
|
||||
|
||||
def __get__(self, obj, owner=None):
|
||||
if obj is None:
|
||||
return self
|
||||
self._obj = obj
|
||||
return self.call
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user