From bd9aa7d253b118649b6ac271007451c8f38e01c0 Mon Sep 17 00:00:00 2001
From: Guenter Quast <guenter.quast@online.de>
Date: Fri, 7 Jun 2024 09:32:24 +0200
Subject: [PATCH] added config dict

---
 redPoscdaq.py | 40 +++++++++++++++++++++++++++++++++-------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/redPoscdaq.py b/redPoscdaq.py
index b4c83cb..efb96ff 100755
--- a/redPoscdaq.py
+++ b/redPoscdaq.py
@@ -99,20 +99,26 @@ class rpControl(QMainWindow, Ui_MCPHA):
     """
 
     rates = {0:1, 1: 4, 2: 8, 3: 16, 4: 32, 5: 64, 6: 128, 7: 256}
-    def __init__(self, callback=None):
+    def __init__(self, callback=None, conf_dict=None):
         """
            Args: 
 
-             callback: function receiving recorded waveforms
+             callback: function receiving recorded waveforms  
+             conf_dict: a configuration dictionary
         """
         super(rpControl, self).__init__()
 
         plt.style.use("default") # set graphics style
 
         self.callback_function = callback
-        self.callback = True
+        self.confd = {} if conf_dict is None else conf_dict
+        self.callback = True if callback is not None else False
         # get command line arguments
         self.parse_args()
+#        if conf_dict is None:        
+#           self.parse_args()
+#        else:
+#           self.parse_confd()
         # set physical units (for axis labels)
         self.get_physical_units()
         self.setupUi(self)
@@ -172,7 +178,7 @@ class rpControl(QMainWindow, Ui_MCPHA):
 
     def parse_args(self):
         parser = argparse.ArgumentParser(description=__doc__)
-        parser.add_argument('-c', '--connect_ip', type=str,
+        parser.add_argument('-c', '--connect_ip', type=str, default = '192.168.178.109',
             help='connect IP address of RedPitaya')
         # for oscilloscope display
         parser.add_argument('-i', '--interval', type=int, default=500,
@@ -210,7 +216,27 @@ class rpControl(QMainWindow, Ui_MCPHA):
         self.trigger_slope = 0 if args.trigger_slope == 'rising' else 1
         # other parameters
         self.filename = args.file
-      
+
+    def parse_confd(self):
+        # all relevant parameters are here
+        self.daq_mode = False # True
+        if "ip_address" in self.confd:
+            self.ip_address = self.confd["ip_address"]
+        self.sample_size = 2048 if "number_of_samples" in self.confd else self.confd["number_of_samples"]
+        self.pretrigger_fraction = 0.05 if "pre_trigger_samples" in self.confd \
+            else self.confd["pre_trigger_samples"]/self.sample_size
+        self.trigger_mode = 0 if "trigger_mode" not in self.confd else\
+            1 if self.confd["trigger_mode"] == "auto" else 0
+        self.trigger_source = 1  if "trigger_channel" not in self.confd \
+            else int(self.confd["trigger_channel"])
+        self.trigger_level = 500 if "trigger_level" not in self.confd else self.confd["trigger_level"]
+        self.trigger_slope = 0 if "trigger_direction" not in self.confd else\
+            0 if self.confd["trigger_direction"] == "rising" else 1
+        self.readInterval = 1000 # used to control update of oscilloscope display
+        # other parameters
+        self.filename = ''  # file name for data export 
+
+        
     def get_physical_units(self):
         """get physical units corresponding to ADC units and channel numbers
         """
@@ -878,12 +904,12 @@ class redP_mimocorb():
            print("redPoscdaq exiting") 
            sys.exit()
            
-def run_rpControl(callback=None):
+def run_rpControl(callback=None, conf_dict=None):
     # start redPidaya GUI under Qt5 
     app = QApplication(sys.argv)
     dpi = app.primaryScreen().logicalDotsPerInch()
     matplotlib.rcParams["figure.dpi"] = dpi
-    application = rpControl(callback=callback)
+    application = rpControl(callback=callback, conf_dict=conf_dict)
     application.show()
     sys.exit(app.exec_())
 
-- 
GitLab