From 8484d83a2abd525feb3d5a5caa4e2f13c1dcc76d Mon Sep 17 00:00:00 2001
From: Leolab Cavity CAD PC <quantuminfo.leolab@gmail.com>
Date: Fri, 24 Jan 2025 18:13:29 +0100
Subject: [PATCH] periodic SPCM measurements in labscript are working with
 these configurations

---
 FastComtecMCS8A/blacs_workers.py | 37 ++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 11 deletions(-)

diff --git a/FastComtecMCS8A/blacs_workers.py b/FastComtecMCS8A/blacs_workers.py
index d22c004..61a5473 100644
--- a/FastComtecMCS8A/blacs_workers.py
+++ b/FastComtecMCS8A/blacs_workers.py
@@ -18,24 +18,31 @@ import numpy as np
 class MCS8AWorker(Worker):
 
     def init(self):
-        self.data_path_tmp = "C:\\mcs8x64\\MCS8A_measurement.tmp.mpa"
+        self.base_dir = "C:/mcs8x64/"
+        self.data_mame_tmp = "CHN2_tmp"
+        self.data_path_tmp = self.base_dir + self.data_mame_tmp + ".dat"
         self.device = fastcomtec_api.FastComTec()
         print("Connected...")
-        print("Status: ", self.device.get_acq_status())
+        # print("Status: ", self.device.get_acq_status())
 
         # load (default) config
         if not os.path.realpath(self.config_path) == self.config_path.replace("/","\\"):
             self.config_path = os.path.dirname(os.path.realpath(__file__)) + "\\" + self.config_path
-
-        self.device.load_config(self.config_path)
-
+        print("test123")
+        # self.device.load_config(self.config_path)
+        print(f"Data file path: {self.data_mame_tmp}")
+        # self.device._send_dll_command(f"mpaname={self.data_path_tmp}") # mpa might be slow
+        self.device._send_dll_command("MC_B")
+        self.device._send_dll_command(f"datname={self.data_mame_tmp}")
+        self.device._send_dll_command("fmt=dat") 
         self.smart_cache = {}
 
         print('init completed')
     
     def transition_to_buffered(self, device_name, h5_file, initial_values, fresh):
+        
         self.h5file = h5_file # save for 'transition_to_manual'
-
+        """
         with h5py.File(h5_file,'r') as f:
             command_group = f[f"devices/{self.device_name}/commands"]
             for command in command_group.attrs:
@@ -44,14 +51,19 @@ class MCS8AWorker(Worker):
                 self.smart_cache[command] = command_group.attrs[command]
                 if command_group.attrs[command] is not None:
                     command = f"{command}={command_group.attrs[command]}"
+                print(f"sending: {command}")
                 self.device._send_dll_command(command)
                 print(f"Programmed command '{command}'")
-
+        """
         try:
-            os.remove(self.data_path_tmp)
+            os.remove(self.base_dir + self.data_mame_tmp + ".mp")
         except FileNotFoundError:
             pass
-        self.device.erase_measruement()
+        
+        # self.device.erase_measruement()
+        # self.device._send_dll_command("bitshift=11")
+        ran = 256
+        self.device._send_dll_command(f"range={ran}")
         self.device.start_measurement()
         return {}
 
@@ -60,12 +72,15 @@ class MCS8AWorker(Worker):
 
         # load data and write to file
         # .... TODO
-
+        self.device._send_dll_command("savedat")
         with h5py.File(self.h5file, 'r+') as f:
             group = f.require_group(f"data/{self.device_name}/")
             
             # save photon counts
-            data = np.random.randint(0,2,size=1000) # testing
+            # data = np.random.randint(0,2,size=1000) # testing
+            # data = np.loadtxt(self.data_path_tmp)
+            data = np.fromfile(self.data_path_tmp, dtype=np.uint32)
+            print(data.sum())
             group.create_dataset("photon_counts", compression = config.compression, data=data) # maybe save as binary dtype
 
             # save parameters
-- 
GitLab