def caput(self, value): cothread.CallbackResult( catools.caput, self.pv, value, wait=True, timeout=None, datatype=self.get_datatype()) # now do a caget value = cothread.CallbackResult( catools.caget, self.rbv, format=self.ca_format, datatype=self.get_datatype()) self.update_value(value)
def caput(self): if self.params.wait: cmd = "caput -c -w 1000" else: cmd = "caput" self.log_info("%s %s %s", cmd, self.params.pv, self.params.value) cothread.CallbackResult( catools.caput, self.params.pv, self.params.value, wait=self.params.wait, timeout=None) if self.params.status_pv: value = cothread.CallbackResult( catools.caget, self.params.status_pv, datatype=catools.DBR_STRING) assert value == self.params.good_status, \ "Action failed with status %r" % (value,)
def updatePv(self, topic, payload): logger.debug("ca: send to %s" % self.pv) try: value = self.conv.decode(topic, payload) if value is not None: cothread.CallbackResult(caput, self.pv, value) except Exception as e: logger.error("Trouble in updatePv with " + self.pv + ": " + str(e)) logger.debug(traceback.format_exc())
def connect_pvs(self, _): # make the connection in cothread's thread pvs = [self.params.pv] if self.params.status_pv: pvs.append(self.params.status_pv) ca_values = cothread.CallbackResult(catools.caget, pvs) # check connection is ok for i, v in enumerate(ca_values): assert v.ok, "CA connect failed with %s" % v.state_strings[v.state]
def Thread(): for pv in sys.argv[1:]: print(pv, '=>', end=' ') try: v = cothread.CallbackResult(caget, pv) print(v) except: print('failed') traceback.print_exc() cothread.Callback(cothread.Quit)
def caput(self, value): try: l = len(value) except TypeError: if isinstance(value, bool): value = int(value) self.log_info("caput -c -w 1000 %s %s", self.params.pv, value) else: v = " ".join(str(x) for x in value) self.log_info("caput -a -w 1000 %s %d %s", self.params.pv, l, v) cothread.CallbackResult(catools.caput, self.params.pv, value, wait=True, timeout=None, datatype=self.get_datatype()) # now do a caget value = cothread.CallbackResult(catools.caget, self.params.rbv, format=self.ca_format, datatype=self.get_datatype()) self.update_value(value)
def connect_pvs(self, _=None): # release old monitor self.close_monitor() # make the connection in cothread's thread, use caget for initial value pvs = [self.params.rbv] if self.params.pv: pvs.append(self.params.pv) ca_values = cothread.CallbackResult(catools.caget, pvs, format=self.ca_format, datatype=self.get_datatype()) # check connection is ok for i, v in enumerate(ca_values): assert v.ok, "CA connect failed with %s" % v.state_strings[v.state] self.update_value(ca_values[0]) self.log_debug("ca values connected %s", ca_values) # now setup monitor on rbv self.monitor = cothread.CallbackResult(catools.camonitor, self.params.rbv, self.on_update, format=self.ca_format, datatype=self.get_datatype(), notify_disconnect=True)
def handle_request(self, controller, request): cothread.CallbackResult(super().handle_request, controller, request)
def make_view(self, controller, data, child_name): return cothread.CallbackResult(super().make_view, controller, data, child_name)
def block_view(self, mri): return cothread.CallbackResult(super().block_view, mri)
def make_proxy(self, comms, mri): # Need to do this in cothread's thread cothread.CallbackResult(self._make_proxy, comms, mri)
def main(): print("Loading malcolm...") from malcolm.profiler import Profiler args = parse_args() # Make some log config using command line args or defaults log_config = make_logging_config(args) # Start it off, and tell it to stop when we quit listener = make_async_logging(log_config) listener.start() atexit.register(listener.stop) # Setup profiler dir profiler = Profiler() # profiler.start() # If using p4p then set cothread to use the right ca libs before it is try: import epicscorelibs.path.cothread # noqa except ImportError: pass # Import the Malcolm process q = queue.Queue() t = threading.Thread(target=try_prepare_locals, args=(q, args)) t.start() process = q.get(timeout=65) if isinstance(process, Exception): # Startup failed, exit now sys.exit(1) # Now its safe to import Malcolm and cothread import cothread from malcolm.core import Context from malcolm.modules.builtin.blocks import proxy_block # Make a user context class UserContext(Context): def post(self, path, params=None, timeout=None, event_timeout=None): try: return super().post(path, params, timeout, event_timeout) except KeyboardInterrupt: self.post([path[0], "abort"]) def _make_proxy(self, comms, mri): self._process.add_controller(proxy_block(comms=comms, mri=mri)[-1]) def make_proxy(self, comms, mri): # Need to do this in cothread's thread cothread.CallbackResult(self._make_proxy, comms, mri) def block_view(self, mri): return cothread.CallbackResult(super().block_view, mri) def make_view(self, controller, data, child_name): return cothread.CallbackResult(super().make_view, controller, data, child_name) def handle_request(self, controller, request): cothread.CallbackResult(super().handle_request, controller, request) self = UserContext(process) header = f"""Welcome to iMalcolm. self.mri_list: {self.mri_list} # To create a view of an existing Block block = self.block_view("<mri>") # To create a proxy of a Block in another Malcolm self.make_proxy("<client_comms_mri>", "<mri>") block = self.block_view("<mri>") # To view state of Blocks in a GUI !firefox localhost:8008""" try: import IPython except ImportError: import code code.interact(header, local=locals()) else: IPython.embed(header=header) if profiler.running and not profiler.stopping: profiler.stop() cothread.CallbackResult(process.stop, timeout=0.1) cothread.CallbackResult(cothread.Quit)
def block_view(self, mri): return cothread.CallbackResult( super(UserContext, self).block_view, mri)
def main(): from malcolm.compat import queue from malcolm.profiler import Profiler args = parse_args() # Make some log config, either fron command line or log_config = make_logging_config(args) # Start it off, and tell it to stop when we quit listener = make_async_logging(log_config) listener.start() atexit.register(listener.stop) # Setup profiler dir profiler = Profiler() # profiler.start() # If using p4p then set cothread to use the right ca libs before it is try: import epicscorelibs.path.cothread except ImportError: pass # Import the Malcolm process q = queue.Queue() t = threading.Thread(target=try_prepare_locals, args=(q, args)) t.start() process = q.get(timeout=65) if isinstance(process, Exception): # Startup failed, exit now sys.exit(1) # Now its safe to import Malcolm and cothread import cothread from malcolm.core import Context from malcolm.modules.builtin.blocks import proxy_block # Make a user context class UserContext(Context): def post(self, path, params=None, timeout=None, event_timeout=None): try: return super(UserContext, self).post(path, params, timeout, event_timeout) except KeyboardInterrupt: self.post([path[0], "abort"]) def _make_proxy(self, comms, mri): self._process.add_controller(proxy_block(comms=comms, mri=mri)[-1]) def make_proxy(self, comms, mri): # Need to do this in cothread's thread cothread.CallbackResult(self._make_proxy, comms, mri) def block_view(self, mri): return cothread.CallbackResult( super(UserContext, self).block_view, mri) def make_view(self, controller, data, child_name): return cothread.CallbackResult( super(UserContext, self).make_view, controller, data, child_name) def handle_request(self, controller, request): cothread.CallbackResult( super(UserContext, self).handle_request, controller, request) self = UserContext(process) header = """Welcome to iMalcolm. self.mri_list: %s Try: hello = self.block_view("HELLO") hello.greet("me") or gui(self.block_view("COUNTER")) or self.make_proxy("localhost:8008", "HELLO") self.block_view("HELLO").greet("me") """ % (self.mri_list, ) try: import IPython except ImportError: import code code.interact(header, local=locals()) else: IPython.embed(header=header) if profiler.running and not profiler.stopping: profiler.stop() cothread.CallbackResult(process.stop) cothread.CallbackResult(cothread.Quit)
def close_monitor(self, _=None): if self.monitor is not None: cothread.CallbackResult(self.monitor.close) self.monitor = None