From d178c6adef4e7ef9eba6e6779f2e09155e1870c2 Mon Sep 17 00:00:00 2001
From: Runner PC Cavity Lab <johannes.schabbauer@tuwien.ac.at>
Date: Wed, 5 Mar 2025 12:58:18 +0100
Subject: [PATCH] Bugfix: Don't break ADwin code when we use no wait

---
 ADwinProII/blacs_workers.py     | 4 ++--
 ADwinProII/labscript_devices.py | 6 ++++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/ADwinProII/blacs_workers.py b/ADwinProII/blacs_workers.py
index bf67faa..f5956cd 100644
--- a/ADwinProII/blacs_workers.py
+++ b/ADwinProII/blacs_workers.py
@@ -143,7 +143,7 @@ class ADwinProIIWorker(Worker):
             # Send stop time to ADwin
             self.adw.Set_Par(2, int(self.stop_time * CLOCK_T12 / self.PROCESSDELAY))
             # Send wait time and timeout to ADwin (default 0 if no waits)
-            self.adw.Set_Par(3, group.attrs.get("wait_time",0))
+            self.adw.Set_Par(3, group.attrs.get("wait_time",-1))
             self.adw.Set_Par(5, group.attrs.get("wait_timeout",0))
             # Send data to ADwin
             AOUT = group["ANALOG_OUT/VALUES"]
@@ -160,7 +160,7 @@ class ADwinProIIWorker(Worker):
                     self.smart_cache[name] = DOUT[:]
                     self.adw.SetData_Long(DOUT["n_cycles"], module,   1, DOUT.shape[0])
                     self.adw.SetData_Long(DOUT["bitfield"], module+1, 1, DOUT.shape[0])
-                    self.adw.Set_Par(module-1, DOUT.attrs.get("wait_time",0))
+                    self.adw.Set_Par(module-1, DOUT.attrs.get("wait_time",-1))
             PIDs = group["ANALOG_OUT/PID_CHANNELS"]
             if fresh or not np.array_equal(PIDs[:],self.smart_cache["PIDs"]):
                 print("PIDs programmed.")
diff --git a/ADwinProII/labscript_devices.py b/ADwinProII/labscript_devices.py
index c727013..f7697e7 100644
--- a/ADwinProII/labscript_devices.py
+++ b/ADwinProII/labscript_devices.py
@@ -198,8 +198,10 @@ class ADwinProII(PseudoclockDevice):
     
 
     def do_checks(self, outputs):
-        if len(self.trigger_times)>2 or self.trigger_times[1] not in compiler.wait_table:
-            raise NotImplementedError('ADwin does not support retriggering, and only supports one "wait" in the current implementation.')
+        if len(self.trigger_times)>1:
+            # Either only one software trigger (for starting shot as master pseudoclock), or two (where the second one is for the 'wait')
+            if len(self.trigger_times)==2 and self.trigger_times[1] not in compiler.wait_table:
+                raise NotImplementedError('ADwin does not support retriggering, and only supports one "wait" in the current implementation.')
         for output in outputs:
             output.do_checks(self.trigger_times)
 
-- 
GitLab