From f0be7835917f0cbd9d9f8682201a4cac373e78a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnter=20Quast?= <guenter.quast@online.de>
Date: Mon, 10 Jun 2024 17:03:27 +0200
Subject: [PATCH] moved mimoCoRB callback function redP_mimoCoRB.py

---
 redP_mimoCoRB.py | 29 +++++++++++++++++++++++++++--
 redPoscdaq.py    | 37 +------------------------------------
 2 files changed, 28 insertions(+), 38 deletions(-)

diff --git a/redP_mimoCoRB.py b/redP_mimoCoRB.py
index ba9b876..297e650 100644
--- a/redP_mimoCoRB.py
+++ b/redP_mimoCoRB.py
@@ -1,5 +1,5 @@
 """
-**redP_mimoCoRB**: a simple template to use mimoCoRB with the RedPitaya and redPoscdaq.py 
+**redP_mimoCoRB**: use mimoCoRB with the RedPitaya and redPoscdaq.py 
 
 Input data is provided as numpy-arry of shape (number_of_channels, number_of_samples).
 """
@@ -8,8 +8,33 @@ import time
 import sys
 
 import redPoscdaq as rp
+from mimocorb.buffer_control import rbPut
 
+class redP_mimocorb():            
+    """ Interface to the daq rinbuffer mimoCoRB for redPoscdaq
+    """    
+    def __init__(self, source_list=None, sink_list=None, observe_list=None, config_dict=None,
+                 **rb_info):
+        # initialize mimoCoRB interface 
+        self.action = rbPut(config_dict=config_dict, sink_list=sink_list, **rb_info)
+        self.number_of_channels = len(self.action.sink.dtype)
+        self.events_required = 1000 if "eventcount" not in config_dict else config_dict["eventcount"]
 
+        self.event_count = 0
+        self.active=True
+        
+    def data_sink(self, data):
+        """function called by redPoscdaq  
+        """
+        if (self.events_required == 0 or self.event_count < self.events_required) and self.active:
+           # deliver pulse data and no metadata
+           active = self.action(data, None) # send data
+           self.event_count += 1
+        else:
+           active = self.action(None, None) # send None to signal end
+           print("redPoscdaq exiting") 
+           sys.exit()
+           
 def redP_to_rb(source_list=None, sink_list=None, observe_list=None, config_dict=None, **rb_info):
     """
     Get data from RedPitaya and pass data to buffer
@@ -27,7 +52,7 @@ def redP_to_rb(source_list=None, sink_list=None, observe_list=None, config_dict=
     """
 
     # initialize mimocorb class inside redPoscidaq
-    datasource= rp.redP_mimocorb(config_dict=config_dict, sink_list=sink_list, **rb_info)
+    datasource= redP_mimocorb(config_dict=config_dict, sink_list=sink_list, **rb_info)
     #print("data source initialized")
 
     # start oscilloscope
diff --git a/redPoscdaq.py b/redPoscdaq.py
index cd0f8ed..d13f13f 100755
--- a/redPoscdaq.py
+++ b/redPoscdaq.py
@@ -3,8 +3,7 @@
     application running on a RedPitaya FPGA board
 
     Contains a button to run the oscilloscope in daq mode, i.e. it is restarted 
-    continously. If defined, data is eported to a callback function. A callback
-    class redP_mimocorb() implements an interface to the daq rinbuffer mimoCoRB.      
+    continously. If defined, data is exported via calling a callback function. 
     Optionally, triggered waveforms can be stored a numpy binary file 
     (.npy format).
 
@@ -52,11 +51,6 @@ import matplotlib
 from matplotlib.figure import Figure
 from multiprocessing import Event
 
-# !!! for conditional import from npy_append_array !!!
-def import_mimocorb():
-    global rbPut
-    from mimocorb.buffer_control import rbPut
-
 # !!! for conditional import from npy_append_array !!!
 def import_npy_append_array():
     global NpyAppendArray
@@ -897,36 +891,7 @@ class redP_consumer():
             status_txt = "active: {:.1f}s  trigger rate: {:.2f} Hz,  data rate: {:.4g} MB/s".format(T_active, r, r*l_tot*4e-6)
             print(status_txt, end='\r')
 
-class redP_mimocorb():            
-    def __init__(self, source_list=None, sink_list=None, observe_list=None, config_dict=None,
-                 **rb_info):
-        # import rbPut() from mimoCoRB 
-        import_mimocorb()
-        # initialize mimoCoRB interface 
-        self.action = rbPut(config_dict=config_dict, sink_list=sink_list, **rb_info)
-        self.number_of_channels = len(self.action.sink.dtype)
-        self.events_required = 1000 if "eventcount" not in config_dict else config_dict["eventcount"]
-
-        self.event_count = 0
-        self.active=True
-        
-    def data_sink(self, data):
-        """function called by redPoscdaq  
-        """
-        if (self.events_required == 0 or self.event_count < self.events_required) and self.active:
-           # deliver pulse data and no metadata
-           active = self.action(data, None) # send data
-           self.event_count += 1
-        else:
-           active = self.action(None, None) # send None to signal end
-           print("redPoscdaq exiting") 
-           sys.exit()
-           
 def run_rpControl(callback=None, conf_dict=None):
-    if conf_dict is not None:
-        # need module rbPut() from mimoCoRB, import here 
-        import_mimocorb()
-
     # start redPidaya GUI under Qt5 
     app = QApplication(sys.argv)
     dpi = app.primaryScreen().logicalDotsPerInch()
-- 
GitLab