From 8b1de211fcd8803c356fe53f870d65e14196afdc Mon Sep 17 00:00:00 2001 From: Andrea Parenti <andrea.parenti@xfel.eu> Date: Tue, 21 Jan 2025 13:55:17 +0100 Subject: [PATCH] Refactor / 3 --- pyproject.toml | 3 +-- scripts/karabo_acquire.py | 18 ---------------- src/tempus/Tempus.py | 43 +++++++++++++++++++++++---------------- 3 files changed, 26 insertions(+), 38 deletions(-) delete mode 100644 scripts/karabo_acquire.py diff --git a/pyproject.toml b/pyproject.toml index 439db79..76fc4c6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,5 +20,4 @@ authors = [ ] description = "" readme = "README.md" -dependencies = [ -] +dependencies = ['paramiko'] diff --git a/scripts/karabo_acquire.py b/scripts/karabo_acquire.py deleted file mode 100644 index c300b04..0000000 --- a/scripts/karabo_acquire.py +++ /dev/null @@ -1,18 +0,0 @@ -import argparse - -from control import Timepix4control - -parser = argparse.ArgumentParser() -parser.add_argument("--shutter_time", type=int, default=20000) -parser.add_argument("--t0_time", type=float, default=0.0001) -parser.add_argument("--extratime", type=int, default=100000) -parser.add_argument("--pad", type=bool, default=False) -args = parser.parse_args() - -mytpx4 = Timepix4control(1) - -mytpx4.external_shutter(delay=False, shutter_time=args.shutter_time) -if args.pad: - mytpx4.external_t0_sync(delay=False, t0_time=args.t0_time) - -mytpx4.slowtakeevents(extratime=args.extratime, pad=args.pad) diff --git a/src/tempus/Tempus.py b/src/tempus/Tempus.py index 5caa58d..389561a 100644 --- a/src/tempus/Tempus.py +++ b/src/tempus/Tempus.py @@ -220,19 +220,10 @@ class Tempus(Device): async def _initialize(self): try: - await self.send_command(f"cd {self.SCRIPT_DIR}") - await self.send_command("python3") - await self.send_command("import os") - await self.send_command("import numpy as np") - await self.send_command( - "from control import Timepix4control", sleep_time=2) - await self.send_command("os.system('devmem2 0x80010004 w 0x2')") await self.send_command("os.system('devmem2 0x80010004 w 0x0')") await self.send_command("os.system('devmem2 0x80010004 w 0x2')") - await self.send_command( - "mytpx4 = Timepix4control(1)", sleep_time=5) await self.send_command( f"os.system('{self.APP_DIR}/Timepix4_Init.py')", sleep_time=3) await self.send_command("mytpx4.initialisechip()", sleep_time=1) @@ -323,18 +314,24 @@ class Tempus(Device): self.state = State.ACQUIRING self.background_task = background(self._acquire()) - async def _acquire(self): - cmnd = [ - self.COMMAND, *self.ARGS, f"{self.SCRIPT_DIR}/karabo_acquire.py", - f"--shutter_time={self.shutterTime.value}", - f"--t0_time={self.t0Time.value}", - f"--pad={self.externalSync}"] - self.commandLog = f"Starting acquisition:\n{' '.join(cmnd)}" + async def _acquire(self): # XXX test + await self.send_command( + "mytpx4.external_shutter(delay=False, " + f"shutter_time={self.shutterTime.value})") # XXX sleep_time + + if self.externalSync: + await self.send_command( + "mytpx4.external_t0_sync(delay=False, " + f"t0_time={self.t0Time.value})") # XXX sleep_time + for i in range(self.nAcquisitions.value): + self.status = f"Acquisition #{i}" + await self.send_command( + "mytpx4.slowtakeevents(extratime=100000, " + f"pad={self.externalSync})", sleep_time=self.shutterTime.value) if not self.do_acquire: break - await self._execute_command( - cmnd, State.ACQUIRING, f"Acquisition #{i}") + self.state = State.ACTIVE self.status = "Acquisition done" @@ -414,6 +411,16 @@ class Tempus(Device): msg = f"Connected to {self.controllerIp}" self.logger.info(msg) self.status = msg + + await self.send_command(f"cd {self.SCRIPT_DIR}") + await self.send_command("python3") + await self.send_command("import os") + await self.send_command("import numpy as np") + await self.send_command( + "from control import Timepix4control", sleep_time=2) + await self.send_command( + "mytpx4 = Timepix4control(1)", sleep_time=5) + self.state = State.INIT except Exception as e: self.client = None -- GitLab