From ba2b5ac786064b9d10a01118492f33aabf43c721 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Mon, 23 Sep 2024 14:53:55 +0200 Subject: [PATCH] frappy.client.interactive: improve order of callbacks the user would expect that updates are shown in the order they appeared in the SECoP connection. For this register_callback needs an additional parameter to suppress initial callback. Change-Id: Id1d7605d739b02ec799b3768ae2399558969c381 --- frappy/client/__init__.py | 4 ++-- frappy/client/interactive.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/frappy/client/__init__.py b/frappy/client/__init__.py index 9299a0c..198844e 100644 --- a/frappy/client/__init__.py +++ b/frappy/client/__init__.py @@ -188,7 +188,7 @@ class ProxyClient: # caches (module, parameter) = value, timestamp, readerror (internal names!) self.cache = Cache() # dict returning Cache.undefined for missing keys - def register_callback(self, key, *args, **kwds): + def register_callback(self, key, *args, callimmediately=None, **kwds): """register callback functions - key might be either: @@ -206,7 +206,7 @@ class ProxyClient: raise TypeError(f"unknown callback: {', '.join(kwds)}") # immediately call for some callback types - if cbname in ('updateItem', 'updateEvent'): + if cbname in ('updateItem', 'updateEvent') and callimmediately is not False: if key is None: # case generic callback cbargs = [(m, p, d) for (m, p), d in self.cache.items()] else: diff --git a/frappy/client/interactive.py b/frappy/client/interactive.py index 062e138..bec330b 100644 --- a/frappy/client/interactive.py +++ b/frappy/client/interactive.py @@ -216,14 +216,16 @@ class Module: def __call__(self, target=None): if target is None: return self.read() + for pname in 'value', 'status': + self._secnode.register_callback((self._name, pname), + callimmediately=False, + updateEvent=self._watch_parameter) + self.target = target # this sets self._is_driving - type(self).value.prev = None # show at least one value def loop(): while self._is_driving: self._driving_event.wait() - self._watch_parameter(self._name, 'value', mininterval=self._secnode.mininterval) - self._watch_parameter(self._name, 'status') self._driving_event.clear() try: loop() @@ -237,9 +239,11 @@ class Module: pass clientenv.raise_with_short_traceback(e) finally: - self._watch_parameter(self._name, 'status') + # self._watch_parameter(self._name, 'status') self._secnode.readParameter(self._name, 'value') - self._watch_parameter(self._name, 'value', forced=True) + # self._watch_parameter(self._name, 'value', forced=True) + self._secnode.unregister_callback((self._name, 'value'), updateEvent=self._watch_parameter) + self._secnode.unregister_callback((self._name, 'status'), updateEvent=self._watch_parameter) return self.value def __repr__(self):