From 2b97c2278740ca85db31b6d1481c08cc3ac7a7d5 Mon Sep 17 00:00:00 2001
From: unknown <asoalexandros@gmail.com>
Date: Fri, 21 Mar 2025 10:32:53 +0100
Subject: [PATCH] Sweep txt and ini file!

---
 hp4155/Custom_SMU/interface_custom.ipynb | 86 +++++++++++++++++++++++
 hp4155/Custom_SMU/lib/help.py            |  3 +-
 hp4155/Custom_SMU/lib/interface.py       |  3 +-
 hp4155/Custom_SMU/main.py                | 88 +++++++++++++++++++++++-
 hp4155/Custom_SMU/test_interface.ipynb   | 38 ++++++++--
 5 files changed, 206 insertions(+), 12 deletions(-)
 create mode 100644 hp4155/Custom_SMU/interface_custom.ipynb

diff --git a/hp4155/Custom_SMU/interface_custom.ipynb b/hp4155/Custom_SMU/interface_custom.ipynb
new file mode 100644
index 0000000..660c39a
--- /dev/null
+++ b/hp4155/Custom_SMU/interface_custom.ipynb
@@ -0,0 +1,86 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "a40693da-961a-434d-89f5-6443c0acb517",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "5fc385773f324e7e8311f6f3ee1528f2",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Tab(children=(GridspecLayout(children=(Label(value='UNIT', layout=Layout(grid_area='widget001', height='auto',…"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "abd9668c0feb4d8da9566970b335cd5d",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Button(description='Start Measurement', style=ButtonStyle())"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "ab085a875eae4ea48042af2fcc1c5b49",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    }
+   ],
+   "source": [
+    "%run main.py"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "62768354-a7ff-4f1c-b26a-27fdb88bd545",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.12.0"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/hp4155/Custom_SMU/lib/help.py b/hp4155/Custom_SMU/lib/help.py
index cf28e8c..2b96c4c 100644
--- a/hp4155/Custom_SMU/lib/help.py
+++ b/hp4155/Custom_SMU/lib/help.py
@@ -3,6 +3,7 @@ import tkinter.messagebox
 import pandas as pd 
 import matplotlib.pyplot as plt
 from IPython.display import clear_output
+from datetime import datetime
 
 # Check the functionalities of smus VAR1,VAR2 and VARD
 def check_sweep_func(smus:list,func:str):
@@ -162,8 +163,6 @@ def create_file(filename):
     root.destroy()
     return file
 
-    
-
 
     
     
\ No newline at end of file
diff --git a/hp4155/Custom_SMU/lib/interface.py b/hp4155/Custom_SMU/lib/interface.py
index f320da6..765993e 100644
--- a/hp4155/Custom_SMU/lib/interface.py
+++ b/hp4155/Custom_SMU/lib/interface.py
@@ -188,7 +188,8 @@ def page_5():
     fifth_page[0,0] = widgets.Text(description = 'MEASUREMENT NAME',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
     fifth_page[1,0] = widgets.Text(description ='PROCESSING NR.',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto')) 
     fifth_page[2,0] = widgets.Text(description ='SAMPLE SERIES',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
-    fifth_page[3,0] = widgets.Text(description ='DUT',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
+    fifth_page[3,0] = widgets.Text(description ='FIELD',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
+    fifth_page[4,0] = widgets.Text(description ='DUT',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
 
     fifth_page[5,0] = widgets.Label("VARIABLES TO SAVE",layout=Layout(height='auto', width='auto'))
     fifth_page[5,1] = widgets.Label("UNIT",layout=Layout(height='auto', width='auto'))
diff --git a/hp4155/Custom_SMU/main.py b/hp4155/Custom_SMU/main.py
index 89ee265..d27315e 100644
--- a/hp4155/Custom_SMU/main.py
+++ b/hp4155/Custom_SMU/main.py
@@ -1,6 +1,8 @@
 import sys
 sys.path.insert(0, './lib')
 sys.path.insert(0, '..') #append parent directory
+import os
+import configparser
 
 from interface import *
 from help import *
@@ -41,7 +43,8 @@ def on_start_clicked(b):
         measurement_name = fifth_page[0,0].value
         processing_nr = fifth_page[1,0].value
         sample_series = fifth_page[2,0].value
-        dut = fifth_page[3,0].value
+        field = fifth_page[3,0].value
+        dut = fifth_page[4,0].value
         integration = third_page[0,1].value
 
         # we need constant smus for all measurements
@@ -161,7 +164,9 @@ def on_start_clicked(b):
             for user_function in user_functions:
                 device.user_function(user_function['name'],user_function['unit'],user_function['expression'])     
 
+            # Set the integration time
             
+            device.integration_time(integration)
             # Setup VAR1 (always in sweep measurements)
             device.setup_var1(var1) # device will check for errors
 
@@ -218,9 +223,88 @@ def on_start_clicked(b):
             # Save results
             df = pd.Dataframe(values)
 
+            filename = f"{sample_series}_{field}_{dut}_{measurement_name}_sweep.txt"
+            txt_file = create_file(filename)
+            ini_file = os.path.splitext(txt_file)[0]+'.ini'
+
+            with open(txt_file,'w') as f:
+                date = str(datetime.today().replace(microsecond=0))
+                f.write(f"{measurement_name} at {date}:"+"\n")
+                f.write("Sample Information\n")
+                f.write(f"Processing Number:{proceccing_nr}"+"\n")
+                f.write(f"Sample Series:{sample_series}"+"\n")
+                f.write(f"Field:{field}"+"\n")
+                f.write(f"DUT:{dut}"+"\n")
+                f.write("\n")
+                f.write(f"Measurement arameters can be found at: {ini_file}"+"\n")
+                f.write("\nResults\n")
             
+            df.to_csv(txt_file,sep=" ",mode='a')
+
+            # export interface to ini file
+            # First the Smus
+            config = configparser.ConfigParser()
+            with open(ini_file,'w') as configfile:
+                config.add_section("THESE ARE THE PARAMETERS OF THE CORRESPONDING MEASUREMENT")
+                config.add_section("THE WHOLE INTERFACE IS SAVED SO FIND WHAT YOU NEED")
+                config.add_section("DO NOT MODIFY THIS FILE")
+                config.add_section(f"MEASUREMENT MODE: {measurement_mode}")
+                config.add_section(f"INTEGRATION TIME: {integration}")
+                
+                # First the smus
+                config.add_section("SMUS")
+                for i, smu in enumerate(smus):
+                    config.add_section(f"SMU{i+1}")
+                    for key,value in smu.items():
+                        config.set(f"SMU{i+1}",key,value)
+
+                # Secondly the user functions
+                config.add_section("USER FUNCTIONS")
+                for i, user_function in enumerate(user_functions):
+                    config.add_section(f"USER FUNCTION {i+1}")
+                    for key,value in user_function.items():
+                        config.set(f"USER FUNCTION {i+1}",key,value)
+
+                # Then the 3rd page
+                config.add_section("VAR1")
+                for key,value in var1.items():
+                    config.set("VAR1",key,value)
+
+                config.add_section("VAR2")
+                for key,value in var2.items():
+                    config.set("VAR2",key,value)
+                
+                config.add_section("VARD")
+                for key, value in vard.items():
+                    config.set("VARD",key,value)
+
+                config.add_section("PULSE"):
+                for key,value in pulse.items():
+                    config.set("PULSE",key,value)
             
-        
+                # Now The constant smus
+                config.add_section('CONSTANT SMUS')
+                for i, cons_smu in enumerate(cons_smus):
+                    config.add_section(f"CONSTANT SMU{i+1}")
+                    for key, value in cons_smu.items():
+                        config.set(f"CONSTANT SMU{i+1}",key,value)
+                
+
+                # Page 4 The axes
+                config.add_section('AXES')
+                for i,axis in enumerate(axes):
+                    config_add_section(f"AXIS {i+1}")
+                    for key,value in axis.items():
+                        config.set(f"AXIS {i+1}",key,value)
+                
+                # Page 5 The varibles
+                config.add_section("SAVED VARIABLES")
+                for i, variable in enumerate(variables):
+                    config.add_section(f"VARIABLE {i+1}")
+                    for key,value in variable.items():
+                        config.set(f"VARIABLE {i+1}",key,value)
+
+                config.write(configfile)
         # Sampling Measurement Mode
         elif measurement_mode=='SAMPLING':
             # sampling parameters
diff --git a/hp4155/Custom_SMU/test_interface.ipynb b/hp4155/Custom_SMU/test_interface.ipynb
index 660c39a..34839db 100644
--- a/hp4155/Custom_SMU/test_interface.ipynb
+++ b/hp4155/Custom_SMU/test_interface.ipynb
@@ -2,14 +2,14 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 1,
-   "id": "a40693da-961a-434d-89f5-6443c0acb517",
+   "execution_count": 2,
+   "id": "8c823003-1b29-4ece-a0cb-e693a1cd0402",
    "metadata": {},
    "outputs": [
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "5fc385773f324e7e8311f6f3ee1528f2",
+       "model_id": "6427bccee9fd48e58312921affdeb9b3",
        "version_major": 2,
        "version_minor": 0
       },
@@ -23,7 +23,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "abd9668c0feb4d8da9566970b335cd5d",
+       "model_id": "a34bc4bbbc7f44eb8a20a124af8cc604",
        "version_major": 2,
        "version_minor": 0
       },
@@ -37,7 +37,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "ab085a875eae4ea48042af2fcc1c5b49",
+       "model_id": "06a413304448487fad402f1b345badb1",
        "version_major": 2,
        "version_minor": 0
       },
@@ -50,13 +50,37 @@
     }
    ],
    "source": [
-    "%run main.py"
+    "import sys\n",
+    "sys.path.insert(0, './lib')\n",
+    "sys.path.insert(0, '..') #append parent directory\n",
+    "import os\n",
+    "\n",
+    "from interface import *\n",
+    "\n",
+    "first_page = page_1()\n",
+    "second_page = page_2()\n",
+    "third_page = page_3()\n",
+    "fourth_page = page_4()\n",
+    "fifth_page = page_5()\n",
+    "\n",
+    "titles = [\"SMUs\",\"User Functions\",\"Parameters\",\"Plotting\",\"Save to file\"]\n",
+    "children = [first_page,second_page,third_page,fourth_page,fifth_page]\n",
+    "tab = widgets.Tab()\n",
+    "tab.children = children\n",
+    "tab.titles = titles\n",
+    "\n",
+    "display(tab)\n",
+    "\n",
+    "start = widgets.Button(description='Start Measurement')\n",
+    "output = widgets.Output()\n",
+    "\n",
+    "display(start,output)"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "62768354-a7ff-4f1c-b26a-27fdb88bd545",
+   "id": "aae3eef8-c2d2-424a-8b10-230f7d8cd67a",
    "metadata": {},
    "outputs": [],
    "source": []
-- 
GitLab