From c07ab61428333789d8506dc1cfbd8f162de4a057 Mon Sep 17 00:00:00 2001
From: Runner PC Cavity Lab <johannes.schabbauer@tuwien.ac.at>
Date: Thu, 13 Feb 2025 10:01:43 +0100
Subject: [PATCH] Fastcomtec: Incresed wait times again, still don't know for
 sure what is the optimal (and most robust) delay

---
 FastComtecMCS8A/blacs_workers.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/FastComtecMCS8A/blacs_workers.py b/FastComtecMCS8A/blacs_workers.py
index d7c93d2..538e683 100644
--- a/FastComtecMCS8A/blacs_workers.py
+++ b/FastComtecMCS8A/blacs_workers.py
@@ -28,6 +28,7 @@ class MCS8AWorker(Worker):
         if getattr(self.device.get_acq_status(),"started") == 1:
             time.sleep(1)
         self.device.halt_measurement()
+        self.dataindex=0
 
         # load (default) config
         if not os.path.realpath(self.config_path) == self.config_path.replace("/","\\"):
@@ -59,7 +60,9 @@ class MCS8AWorker(Worker):
         # TODO: How to handle parameters (start new measurment when they changed, or treat parameters statically)
         with h5py.File(h5_file,'r') as f: 
             stop_time = f["devices/" + f["connection table"].attrs["master_pseudoclock"]].attrs["stop_time"]
-        if getattr(self.device.get_acq_status(),"started") != 1 or time.perf_counter()-getattr(self,"start_time",-self.maxduration)>self.maxduration-stop_time-2:
+        if getattr(self.device.get_acq_status(),"started") != 1 or time.perf_counter()-getattr(self,"start_time",-self.maxduration)>self.maxduration-stop_time-3:
+            if self.dataindex==0:
+                self.device.halt_measurement()
             while getattr(self.device.get_acq_status(),"started") == 1:
                 # If the current measurement doesn't have enought time left for this shot, wait until measurment ends. 
                 time.sleep(0.1)
@@ -74,7 +77,7 @@ class MCS8AWorker(Worker):
             # self.device.erase_measruement() # Don't erase because this takes super long for some reason
             self.device.start_measurement()
             self.start_time = time.perf_counter()
-            time.sleep(1) # some buffer time to make sure the measurement already started for sure
+            time.sleep(2) # some buffer time to make sure the measurement already started for sure
             # TODO: What's the minimum time to wait here?
 
         # Save where to find the measurement data (which file and within file)
-- 
GitLab