diff --git a/.gitignore b/.gitignore
index 41925adeb6b9e075d4d92c9466891b5cec5d0493..dee5b83a3721d334006abf764b15235331972896 100644
--- a/.gitignore
+++ b/.gitignore
@@ -237,4 +237,6 @@ cython_debug/
 #  be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
 #  and can be added to the global gitignore or merged into this file.  For a more nuclear
 #  option (not recommended) you can uncomment the following to ignore the entire idea folder.
-#.idea/
\ No newline at end of file
+#.idea/
+
+./tests/py/*
\ No newline at end of file
diff --git a/.idea/captdevicecontrol.iml b/.idea/captdevicecontrol.iml
index 92e4649168f953bb240ff732a1e4466591fa0481..e158d0be0530da2b4822f70266b133b621a67535 100644
--- a/.idea/captdevicecontrol.iml
+++ b/.idea/captdevicecontrol.iml
@@ -8,8 +8,9 @@
       <excludeFolder url="file://$MODULE_DIR$/src/CaptDeviceControl/old" />
       <excludeFolder url="file://$MODULE_DIR$/.venv" />
       <excludeFolder url="file://$MODULE_DIR$/build" />
+      <excludeFolder url="file://$MODULE_DIR$/src/captdevicecontrol.egg-info" />
     </content>
-    <orderEntry type="jdk" jdkName="Python 3.10 (captdevicecontrol)" jdkType="Python SDK" />
+    <orderEntry type="jdk" jdkName="Python 3.12 (captdevicecontrol)" jdkType="Python SDK" />
     <orderEntry type="sourceFolder" forTests="false" />
   </component>
   <component name="PyDocumentationSettings">
diff --git a/.idea/misc.xml b/.idea/misc.xml
index c29ee7b6697d02c42ae45ebec1079c1703f3b22c..a333598a49faf72ed4e0400b3e709ba7253c4176 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
   <component name="Black">
     <option name="sdkName" value="Python 3.11 (.venv312_al) (3)" />
   </component>
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (captdevicecontrol)" project-jdk-type="Python SDK" />
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (captdevicecontrol)" project-jdk-type="Python SDK" />
 </project>
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 04665ae48d6f210a7d6f22067dab0e7dffebf30e..7c268c1045340220c88b39dba3335c5fd65c848f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "captdevicecontrol"
-version = "0.0.1"
+version = "0.1.0"
 authors = [
   { name="Christoph Schmidt", email="cschmidt.fs@gmail.com" },
 ]
@@ -8,7 +8,16 @@ description = "A UI for controlling the Analog Discovery Series"
 readme = "README.md"
 requires-python = ">=3.7"
 dependencies = [
-    'pyside6', 'rich', 'pyyaml','matplotlib', 'numpy', 'pandas', 'scipy', 'pyqtgraph'
+    'matplotlib',
+    'numpy',
+    'pandas',
+    'PySide6',
+    'scipy',
+    'rich',
+    'pyqtgraph',
+    'fswidget@git+https://gitlab.tugraz.at/flexsensor-public/modules/fswidgets.git#egg=develop',
+    'confighandler@git+https://gitlab.tugraz.at/flexsensor-public/modules/confighandler.git#egg=develop',
+    'cmp@git+https://gitlab.tugraz.at/flexsensor-public/modules/cmp.git#egg=develop'
 ]
 classifiers = [
     "Programming Language :: Python :: 3",
@@ -17,4 +26,4 @@ classifiers = [
 ]
 
 [project.urls]
-"Homepage" = "https://gitlab.tugraz.at/flexsensor-public/confighandler"
\ No newline at end of file
+"Homepage" = "https://gitlab.tugraz.at/flexsensor-public/captdevicecontrol"
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 6952b7243a1843153f4f1f0b9b5141de9a34bca5..1b5a61786e1991d6ddc796dc199d2be81401407b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,9 +5,13 @@ PySide6
 scipy
 rich
 pyqtgraph
+
 # add the git repo
-git+https://gitlab.tugraz.at/flexsensor-public/confighandler.git@develop
-git+https://gitlab.tugraz.at/flexsensor-public/fswidgets.git@develop
-#../fswidgets
+git+https://gitlab.tugraz.at/flexsensor-public/modules/fswidgets.git@develop
+git+https://gitlab.tugraz.at/flexsensor-public/modules/confighandler.git@develop
+git+https://gitlab.tugraz.at/flexsensor-public/modules/cmp.git@develop
 
-../../pyside-multiprocessing
\ No newline at end of file
+# Local installs
+#../confighandler
+#../captdevicecontrol
+#../modules/cmp
\ No newline at end of file
diff --git a/src/CaptDeviceControl/controller/mp_AD2Capture/MPCaptDevice.py b/src/CaptDeviceControl/controller/mp_AD2Capture/MPCaptDevice.py
index fa38f2e22c62df592a697951ddbd98ce3cbd8961..b2c5af756bd6632f83adde689de824f0f8775c7d 100644
--- a/src/CaptDeviceControl/controller/mp_AD2Capture/MPCaptDevice.py
+++ b/src/CaptDeviceControl/controller/mp_AD2Capture/MPCaptDevice.py
@@ -68,12 +68,8 @@ class MPCaptDevice(cmp.CProcess):
             self.dwf = cdll.LoadLibrary("libdwf.so")
         self._connected = self.connected()
         self.hdwf = c_int()
-        self._ain_device_state: c_byte = c_byte()
 
-        self._c_available = c_int()
-        self._c_lost = c_int()
-        self._c_corrupted = c_int()
-        self._c_samples = 0
+
 
     @cmp.CProcess.register_for_signal('_changed')
     def device_capturing(self, capturing: bool):
@@ -312,21 +308,21 @@ class MPCaptDevice(cmp.CProcess):
     # Function for setting up the acquisition
     # ==================================================================================================================
     def setup_acquisition(self, sample_rate: float, ain_channel: int):
-        self.dwf.FDwfAnalogInStatus(self.hdwf, c_int(1),
-                                    byref(self._ain_device_state))  # Variable to receive the acquisition state
+        #self.dwf.FDwfAnalogInStatus(self.hdwf, c_int(1),
+        #                            byref(self._ain_device_state))  # Variable to receive the acquisition state
         self.logger.info(f"[Task] Setup for acquisition on channel {ain_channel} with rate {sample_rate} Hz.")
         self.dwf.FDwfAnalogInChannelEnableSet(self.hdwf, c_int(ain_channel), c_int(1))
         self.dwf.FDwfAnalogInChannelRangeSet(self.hdwf, c_int(ain_channel), c_double(5))
         self.dwf.FDwfAnalogInAcquisitionModeSet(self.hdwf, acqmodeRecord)
         self.dwf.FDwfAnalogInFrequencySet(self.hdwf, c_double(sample_rate))
-        self.dwf.FDwfAnalogInRecordLengthSet(self.hdwf, 0)  # -1 infinite record length
-
+        self.dwf.FDwfAnalogInRecordLengthSet(self.hdwf, c_double(1))  # -1 infinite record length
+        self.dwf.FDwfAnalogInConfigure(self.hdwf, c_int(1), c_int(0))
         # Variable to receive the acquisition state
         #self.dwf.FDwfAnalogInStatus(self.hdwf, c_int(1), byref(self._ain_device_state))
-        #self.logger.info(f"[Task] Wait 2 seconds for the offset to stabilize.")
+        self.logger.info(f"[Task] Wait 2 seconds for the offset to stabilize.")
         # wait at least 2 seconds for the offset to stabilize
-        #time.sleep(2)
-        #self.logger.info(f"[Task] Setup for acquisition done.")
+        time.sleep(2)
+        self.logger.info(f"[Task] Setup for acquisition done.")
 
     # ==================================================================================================================
     # Python wrapper for WaveForms API Functions
@@ -385,15 +381,52 @@ class MPCaptDevice(cmp.CProcess):
         :param sample_rate:
         :return: None
         """
+        self.close_device()
+
+        if sys.platform.startswith("win"):
+            dwf = cdll.dwf
+        elif sys.platform.startswith("darwin"):
+            dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
+        else:
+            dwf = cdll.LoadLibrary("libdwf.so")
+
+        cDevice = c_int()
+        hdwf = c_int()
+        filter, type = (c_int32(enumfilterType.value | enumfilterDemo.value | enumfilterUSB.value), 'USB')
+        dwf.FDwfEnum(filter, byref(cDevice))
+        dwf.FDwfDeviceOpen(c_int(3), byref(hdwf))
+
+        ain_channel = int(0)
+        self.logger.debug("Generating AM sine wave...")
+        dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(ain_channel), c_int(0), c_int(1))  # carrier
+        dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(ain_channel), c_int(0), c_int(1))  # sine
+        dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(ain_channel), c_int(0), c_double(1))
+        dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(ain_channel), c_int(0), c_double(1))
+        dwf.FDwfAnalogOutConfigure(hdwf, c_int(ain_channel), c_int(1))
+        time.sleep(1)
+        self.logger.debug(f"Sine wave on output channel {ain_channel} configured.")
+
         # FDwfAnalogInStatus(HDWF hdwf, BOOL fReadData, DwfState* psts)
-        self.setup_acquisition(ain_channel=ain_channel, sample_rate=sample_rate)
+        self.logger.info(f"[Task] Setup for acquisition on channel {ain_channel} with rate {sample_rate} Hz.")
+        dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(ain_channel), c_int(1))
+        dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(ain_channel), c_double(5))
+        dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
+        dwf.FDwfAnalogInFrequencySet(hdwf, c_double(sample_rate))
+        dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(9999))  # -1 infinite record length
+
+        # Variable to receive the acquisition state
+        # self.dwf.FDwfAnalogInStatus(self.hdwf, c_int(1), byref(self._ain_device_state))
+        self.logger.info(f"[Task] Wait 2 seconds for the offset to stabilize.")
+        # wait at least 2 seconds for the offset to stabilize
+        time.sleep(2)
+        self.logger.info(f"[Task] Setup for acquisition done.")
 
         # Creates a Sin Wave on the Analog Out Channel 0
-        self.setup_sine_wave(channel=0)
+
         self.logger.info("Configuring acquisition. Starting oscilloscope.")
 
         # Configures the instrument and start or stop the acquisition. To reset the Auto trigger timeout, set
-        self.dwf.FDwfAnalogInConfigure(self.hdwf, c_int(0), c_int(1))
+        self.dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))
         self.logger.info("Device configured. Starting acquisition.")
 
         time_capture_started = 0
@@ -401,13 +434,18 @@ class MPCaptDevice(cmp.CProcess):
         capture_started = False
         capture_ended = False
 
-        n_samples = int((sample_rate*2))
-        rgd_samples = (c_double * n_samples)()
-        #num_sent_samples = 0
-        try:
-            self.dwf.FDwfAnalogOutReset(self.hdwf, c_int(0))
 
 
+        cAvailable = c_int()
+        cLost = c_int()
+        cCorrupted = c_int()
+        cSamples = 0
+        sts  = c_byte()
+
+
+        try:
+            #self.dwf.FDwfAnalogOutReset(self.hdwf, c_int(0))
+            dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
             while self.kill_capture_flag.value == int(False):
                 self._c_samples = 0
 
@@ -416,87 +454,79 @@ class MPCaptDevice(cmp.CProcess):
 
                 # Checks the state of the acquisition. To read the data from the device, set fReadData to TRUE. For
                 # single acquisition mode, the data will be read only when the acquisition is finished
-                self.dwf.FDwfAnalogInStatus(self.hdwf, c_int(1), byref(self._ain_device_state))
+
 
                 if self._c_samples == 0 and (
-                        self._ain_device_state == DwfStateConfig or
-                        self._ain_device_state == DwfStatePrefill or
-                        self._ain_device_state == DwfStateArmed):
+                        sts == DwfStateConfig or
+                        sts == DwfStatePrefill or
+                        sts == DwfStateArmed):
                     # self.logger.info("Device in idle state. Waiting for acquisition to start.")
                     continue  # Acquisition not yet started.
 
-                self.dwf.FDwfAnalogInStatusRecord(self.hdwf,
-                                                  byref(self._c_available),
-                                                  byref(self._c_lost), byref(self._c_corrupted)
-                                                  )
-                self._c_samples += self._c_lost.value
-                #if self._c_lost.value:
-                #    self._samples_lost += self._c_lost.value
-                #if self._c_corrupted.value:
-                #    self._samples_corrupted += self._c_corrupted.value
-
+                dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
                 # self.dwf.FDwfAnalogInStatusSamplesValid(self.hdwf, byref(self.cValid))
-                if self._c_available.value == 0:
-                    pass
+                if cAvailable.value == 0:
                     #print("Nothing available")
-                    #continue
-
-                else:
-                    if self._c_samples + self._c_available.value > n_samples:
-                        self._c_available = c_int(n_samples - self._c_samples)
-
-                    # print(f"Available: {self._c_available.value}")
-                    # if cSamples + cAvailable.value > self.ad2capt_model.n_samples:
-                    #    cAvailable = c_int(self.ad2capt_model.n_samples - cSamples)
-                    # time_rgdsamples_start = time.time()
-
-                    # arr = [None] * cAvailable.value
-                    # time_rgdsamples_stop = time.time()
-                    # time_rgdsamples = time_rgdsamples_stop - time_rgdsamples_start
-                    # print(f"rgd_samples took {time_rgdsamples} seconds")
-                    rgd_samples = (c_double * self._c_available.value)()
-                    # Get the data from the device and store it in rgd_samples
-                    self.dwf.FDwfAnalogInStatusData(self.hdwf,
-                                                    c_int(ain_channel),
-                                                    rgd_samples,
-                                                    self._c_available)
-                    #print(f"Got data from device: {self._c_available.value}")
-                    self._c_samples += self._c_available.value
-                    iteration_time = time.time() - time_start
+                    continue
+
+                print(f"Available: {cAvailable.value}")
+                # if cSamples + cAvailable.value > self.ad2capt_model.n_samples:
+                #    cAvailable = c_int(self.ad2capt_model.n_samples - cSamples)
+                # time_rgdsamples_start = time.time()
+
+                # arr = [None] * cAvailable.value
+                # time_rgdsamples_stop = time.time()
+                # time_rgdsamples = time_rgdsamples_stop - time_rgdsamples_start
+                # print(f"rgd_samples took {time_rgdsamples} seconds")
+                rgd_samples = (c_double * cAvailable.value)()
+                # Get the data from the device and store it in rgd_samples
+                dwf.FDwfAnalogInStatusData(hdwf,
+                                                c_int(ain_channel),
+                                                byref(rgd_samples),
+                                                cAvailable)
+
+                #self._c_samples += self._c_available.value
+                iteration_time = time.time() - time_start
+                print(f"Got data from device: len {cAvailable.value},"
+                      f"time {iteration_time} seconds.")
 
                 # Convert the data to a numpy array and put it into the queue
                 # self.logger.info("Convert data to numpy array and put it into the queue.")
 
                 #    num_sent_samples = 0
-                arr = np.array(rgd_samples)
-                #print(f"I send {len(arr)} samples to the queue.")
-                self.stream_data_queue.put(arr)
-
-                if self.start_capture_flag.value == int(True):
-                    if not capture_started:
-                        self.device_capturing(True)
-                        time_capture_started = time.time()
-                        self.logger.info(
-                            "**************************** Starting command received. Acquisition started.")
-                        capture_started = True
-                        capture_ended = False
-                        capture_samples = 0
-                    #capture_samples = capture_samples + len(arr)
-                    #self.capture_data_queue.put(arr)
-                elif self.start_capture_flag.value == int(False):
-
-                    if not capture_ended and capture_started:
-                        self.device_capturing(False)
-                        time_capture_stopped = time.time()
-                        time_captured = time_capture_stopped - time_capture_started
-                        self.logger.info(
-                            "**************************** Stopping command received. Acquisition stopped.")
-                        self.logger.info(
-                            f"Acquisition stopped after {time_captured} seconds. Captured {capture_samples} "
-                            f"samples. Resulting in a time of {capture_samples / sample_rate} s.")
-                        capture_ended = True
-                        capture_started = False
-                        #self.capture_data_queue.put(arr)
+                if len(rgd_samples) > 0:
+                    #arr =
+                    print(f"I send {len(np.array(rgd_samples))} samples to the queue.")
+                    self.stream_data_queue.put(np.array(rgd_samples))
+                    #np.delete(arr
+                else:
+                    print(f"rgd_samples is empty.")
+
+                # if self.start_capture_flag.value == int(True):
+                #     if not capture_started:
+                #         self.device_capturing(True)
+                #         time_capture_started = time.time()
+                #         self.logger.info(
+                #             "**************************** Starting command received. Acquisition started.")
+                #         capture_started = True
+                #         capture_ended = False
+                #         capture_samples = 0
+                #     #capture_samples = capture_samples + len(arr)
+                #     #self.capture_data_queue.put(arr)
+                # elif self.start_capture_flag.value == int(False):
+                #
+                #     if not capture_ended and capture_started:
+                #         self.device_capturing(False)
+                #         time_capture_stopped = time.time()
+                #         time_captured = time_capture_stopped - time_capture_started
+                #         self.logger.info(
+                #             "**************************** Stopping command received. Acquisition stopped.")
+                #         self.logger.info(
+                #             f"Acquisition stopped after {time_captured} seconds. Captured {capture_samples} "
+                #             f"samples. Resulting in a time of {capture_samples / sample_rate} s.")
+                #         capture_ended = True
+                #         capture_started = False
+                #         #self.capture_data_queue.put(arr)
                 # self._c_samples += self._c_available.value
 
 
@@ -512,10 +542,10 @@ class MPCaptDevice(cmp.CProcess):
     # ==================================================================================================================
     def setup_sine_wave(self, channel: int = 0):
         self.logger.debug("Generating AM sine wave...")
-        self.dwf.FDwfAnalogOutNodeEnableSet(self.hdwf, c_int(0), c_int(0), c_int(1))  # carrier
-        self.dwf.FDwfAnalogOutNodeFunctionSet(self.hdwf, c_int(0), c_int(0), c_int(1))  # sine
-        self.dwf.FDwfAnalogOutNodeFrequencySet(self.hdwf, c_int(0), c_int(0), c_double(0.1))
-        self.dwf.FDwfAnalogOutNodeAmplitudeSet(self.hdwf, c_int(0), c_int(0), c_double(1))
+        self.dwf.FDwfAnalogOutNodeEnableSet(self.hdwf, c_int(channel), c_int(0), c_int(1))  # carrier
+        self.dwf.FDwfAnalogOutNodeFunctionSet(self.hdwf, c_int(channel), c_int(0), c_int(1))  # sine
+        self.dwf.FDwfAnalogOutNodeFrequencySet(self.hdwf, c_int(channel), c_int(0), c_double(1))
+        self.dwf.FDwfAnalogOutNodeAmplitudeSet(self.hdwf, c_int(channel), c_int(0), c_double(1))
         # dwf.FDwfAnalogOutNodeOffsetSet(hdwf, c_int(0), c_int(0), c_double(0.5))
         # dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), c_int(2), c_int(1))  # AM
         # dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), c_int(2), c_int(3))  # triangle
diff --git a/src/CaptDeviceControl/view/AD2CaptDeviceView.py b/src/CaptDeviceControl/view/AD2CaptDeviceView.py
index 93aa47b51004a0c12b335db918af26768b71222c..46dfb253a481d39da5173f7426e7223bc78aa557 100644
--- a/src/CaptDeviceControl/view/AD2CaptDeviceView.py
+++ b/src/CaptDeviceControl/view/AD2CaptDeviceView.py
@@ -404,7 +404,7 @@ class ControlWindow(QMainWindow):
         self.scope_original.clear()
         # print(self.ad2device.recorded_samples)
         self.scope_original.plot(
-            np.array(self.controller.streaming_data_dqueue)[::100],
+            np.array(self.controller.streaming_data_dqueue),#[::100],
             pen=pg.mkPen(width=1))
         self._ui.lcd_unconsumed_stream.display(self.model.unconsumed_stream_samples)
 
diff --git a/tests/py/AnalogIn_Record.py b/tests/py/AnalogIn_Record.py
index aaa75a5cd2a1bf6a6aa8f7c2f132d6a31ee5ecd4..2d81d06b82f9065bf0b46fbe60488169605a0aa5 100644
--- a/tests/py/AnalogIn_Record.py
+++ b/tests/py/AnalogIn_Record.py
@@ -22,11 +22,17 @@ elif sys.platform.startswith("darwin"):
 else:
     dwf = cdll.LoadLibrary("libdwf.so")
 
+# delete record.csv7
+file = "record.csv"
+import os
+if os.path.exists(file):
+    os.remove(file)
+
 #declare ctype variables
 hdwf = c_int()
 sts = c_byte()
-hzAcq = c_double(100000)
-nSamples = 200000
+hzAcq = c_double(1000)
+nSamples = int(hzAcq.value)*2
 rgdSamples = (c_double*nSamples)()
 cAvailable = c_int()
 cLost = c_int()
@@ -41,7 +47,10 @@ print("DWF Version: "+str(version.value))
 
 #open device
 print("Opening first device")
-dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))
+cDevice = c_int()
+filter, type = (c_int32(enumfilterType.value | enumfilterDemo.value | enumfilterUSB.value), 'USB')
+dwf.FDwfEnum(filter, byref(cDevice))
+dwf.FDwfDeviceOpen(c_int(3), byref(hdwf))
 
 if hdwf.value == hdwfNone.value:
     szerr = create_string_buffer(512)
@@ -53,10 +62,10 @@ if hdwf.value == hdwfNone.value:
 dwf.FDwfDeviceAutoConfigureSet(hdwf, c_int(0)) # 0 = the device will only be configured when FDwf###Configure is called
 
 print("Generating sine wave...")
-dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_int(1))
-dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), AnalogOutNodeCarrier, funcSine)
-dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(1))
-dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), AnalogOutNodeCarrier, c_double(2))
+dwf.FDwfAnalogOutNodeEnableSet(hdwf, c_int(0), c_int(0), c_int(1))
+dwf.FDwfAnalogOutNodeFunctionSet(hdwf, c_int(0), c_int(0), funcSine)
+dwf.FDwfAnalogOutNodeFrequencySet(hdwf, c_int(0), c_int(0), c_double(1))
+dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, c_int(0), c_int(0), c_double(2))
 dwf.FDwfAnalogOutConfigure(hdwf, c_int(0), c_int(1))
 
 #set up acquisition
@@ -64,7 +73,7 @@ dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_int(1))
 dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5))
 dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
 dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq)
-dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(nSamples/hzAcq.value)) # -1 infinite record length
+dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(0)) # -1 infinite record length
 dwf.FDwfAnalogInConfigure(hdwf, c_int(1), c_int(0))
 
 #wait at least 2 seconds for the offset to stabilize
@@ -75,31 +84,38 @@ dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))
 
 cSamples = 0
 
-while cSamples < nSamples:
-    dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
-    if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
-        # Acquisition not yet started.
-        continue
+f = open(file, "w")
+
+try:
+    while True:
+        dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
+        if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
+            # Acquisition not yet started.
+            continue
+
+        dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
 
-    dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
-    
-    cSamples += cLost.value
+        cSamples += cLost.value
 
-    if cLost.value :
-        fLost = 1
-    if cCorrupted.value :
-        fCorrupted = 1
+        if cLost.value :
+            fLost = 1
+        if cCorrupted.value :
+            fCorrupted = 1
 
-    if cAvailable.value==0 :
-        continue
+        if cAvailable.value==0 :
+            continue
 
-    if cSamples+cAvailable.value > nSamples :
-        cAvailable = c_int(nSamples-cSamples)
-    
-    dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data
-    #dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgdSamples, sizeof(c_double)*cSamples), cAvailable) # get channel 2 data
-    cSamples += cAvailable.value
+        #if cSamples+cAvailable.value > nSamples :
+        #    cAvailable = c_int(nSamples-cSamples)
+        rgdSamples = (c_double*cAvailable.value)()
+        dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples), cAvailable) # get channel 1 data
 
+        for v in rgdSamples:
+            f.write("%s\n" % v)
+
+        #cSamples += cAvailable.value
+except KeyboardInterrupt:
+    print("Ctrl+C pressed")
 dwf.FDwfAnalogOutReset(hdwf, c_int(0))
 dwf.FDwfDeviceCloseAll()
 
@@ -108,13 +124,15 @@ if fLost:
     print("Samples were lost! Reduce frequency")
 if fCorrupted:
     print("Samples could be corrupted! Reduce frequency")
+f.close()
 
-f = open("record.csv", "w")
-for v in rgdSamples:
-    f.write("%s\n" % v)
+# open csv with numpy
+f = open(file, "r")
+arr = numpy.genfromtxt(f, delimiter=',')
+print(len(arr))
 f.close()
   
-plt.plot(numpy.fromiter(rgdSamples, dtype = numpy.float))
+plt.plot(arr)
 plt.show()