Skip to content
Snippets Groups Projects
Commit 4421661f authored by Andrea Parenti's avatar Andrea Parenti Committed by Jonathan Correa Magdalena
Browse files

Refactor / 2

parent 5ae48f33
No related branches found
No related tags found
2 merge requests!2Draft: Feat/p8003,!1First version
Pipeline #162668 failed
import argparse
import numpy as np
from control import Timepix4control
MASTER_DIR = "/home/timepix4/master"
CFG_DIR = MASTER_DIR + "/control/config"
parser = argparse.ArgumentParser()
parser.add_argument("--DAC_Vthreshold", type=int, default=6622)
parser.add_argument("--DAC_VbiasIkrum", type=int, default=100)
parser.add_argument("--equalisation_file", default="B3_equalisation_HV100.npy")
parser.add_argument(
"--mask_file", default="W15_pixel-mask_200V_20240612_late2.npy")
parser.add_argument("--pad", type=bool, default=False)
args = parser.parse_args()
mytpx4 = Timepix4control(1)
# set DACs and apply equalisation
exec(open(CFG_DIR + '/B3_timing_dacs.py').read())
mytpx4.setDAC("DAC_Vthreshold", args.DAC_Vthreshold)
mytpx4.setDAC("DAC_VbiasIkrum", args.DAC_VbiasIkrum)
with open(CFG_DIR + '/' + args.equalisation_file, 'rb') as f1:
adj_values = np.load(f1)
with open(CFG_DIR + '/' + args.mask_file, 'rb') as f2:
mask_data = np.load(f2)
mytpx4.writepixelregisters(dac_adj=adj_values, mask_bit=mask_data)
mytpx4.slowsetupevents(pad=args.pad)
mytpx4.setting_digital_pixel()
......@@ -68,6 +68,7 @@ class Tempus(Device):
COMMAND = "ssh"
APP_DIR = "/home/timepix4/application"
SCRIPT_DIR = "/home/timepix4/master"
CFG_DIR = "/home/timepix4/master/control/config"
def __init__(self, configuration):
super().__init__(configuration)
......@@ -222,6 +223,7 @@ class Tempus(Device):
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)
......@@ -272,22 +274,46 @@ class Tempus(Device):
@Slot(
displayedName="Configure",
description="Run the configuration sequence. This can take about "
"30 s",
"45 s",
allowedStates={State.ON})
async def configure(self):
self.state = State.CHANGING
self.status = "Configuring TEMPUS"
cmnd = [
self.COMMAND, *self.ARGS, f"{self.SCRIPT_DIR}/karabo_config.py",
f"--DAC_Vthreshold={self.vbiasIkrum.value}",
f"--DAC_VbiasIkrum={self.vbiasIkrum.value}",
f"--equalisation_file={self.equalisationFile}",
f"--mask_file={self.maskFile}",
f"--pad={self.externalSync}"]
self.commandLog = (
f"Configuring TEMPUS:\n{' '.join(cmnd)}\nThis can take about 30 s")
self.background_task = background(
self._execute_command(cmnd, State.ACTIVE, "Configured"))
"Configuring TEMPUS:\nThis will take about 45 s.\n\n")
self.background_task = background(self._configure())
async def _configure(self):
try:
await self.send_command(
f"exec(open('{self.CFG_DIR}/B3_timing_dacs.py').read())")
await self.send_command(
f"mytpx4.setDAC('DAC_Vthreshold', {self.vthreshold.value})")
await self.send_command(
f"mytpx4.setDAC('DAC_VbiasIkrum', {self.vbiasIkrum.value})")
await self.send_command(
f"with open('{self.CFG_DIR}/{self.equalisationFile}', 'rb') "
"as f1: adj_values = np.load(f1)")
await self.send_command( # XXX SyntaxError: invalid syntax
f"with open('{self.CFG_DIR}/{self.maskFile}', 'rb') as f2: "
"mask_data = np.load(f2)")
await self.send_command(
"mytpx4.writepixelregisters(dac_adj=adj_values, "
"mask_bit=mask_data)", sleep_time=30)
await self.send_command(
f"mytpx4.slowsetupevents(pad={self.externalSync})")
await self.send_command("mytpx4.setting_digital_pixel()")
except Exception as e:
self.logger.error(e)
self.state = State.ERROR
self.status = str(e)
self.commandLog = str(e)
@Slot(
displayedName="Acquire",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment