From 03820a5a0555202ac68d3680cb8ca39a2a0a70d2 Mon Sep 17 00:00:00 2001
From: unknown <asoalexandros@gmail.com>
Date: Mon, 31 Mar 2025 11:34:51 +0200
Subject: [PATCH] Import from ini also integrated to the release version

---
 hp4155/Custom_SMU/interface_custom.ipynb |  48 ++++++-
 hp4155/Custom_SMU/main.py                | 160 +++++++++++++++++++++--
 2 files changed, 189 insertions(+), 19 deletions(-)

diff --git a/hp4155/Custom_SMU/interface_custom.ipynb b/hp4155/Custom_SMU/interface_custom.ipynb
index 138fcb8..043a6f6 100644
--- a/hp4155/Custom_SMU/interface_custom.ipynb
+++ b/hp4155/Custom_SMU/interface_custom.ipynb
@@ -7,12 +7,46 @@
    "metadata": {},
    "outputs": [
     {
-     "ename": "SyntaxError",
-     "evalue": "'(' was never closed (main.py, line 27)",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[1;36m  File \u001b[1;32m~\\labcode\\hp4155\\Custom_SMU\\main.py:27\u001b[1;36m\u001b[0m\n\u001b[1;33m    ini = widgets.Button(description = 'Import from ini. (Coming Soon)',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto')\u001b[0m\n\u001b[1;37m                        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m '(' was never closed\n"
-     ]
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "fdd75ac6ae5f48bd88118fe3c5f63751",
+       "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": "ff8460761b0c47cb891e414876fd5c54",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "HBox(children=(Button(description='Start Measurement', style=ButtonStyle()), Button(description='Import from i…"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
+    },
+    {
+     "data": {
+      "application/vnd.jupyter.widget-view+json": {
+       "model_id": "5545d590d0884f65aa5d12dea03a6919",
+       "version_major": 2,
+       "version_minor": 0
+      },
+      "text/plain": [
+       "Output()"
+      ]
+     },
+     "metadata": {},
+     "output_type": "display_data"
     }
    ],
    "source": [
@@ -22,7 +56,7 @@
   {
    "cell_type": "code",
    "execution_count": null,
-   "id": "b4134f36-9202-45f5-ad20-b71dfc315edd",
+   "id": "432e90a3-d6c4-4718-9b1f-0b9fd77e2383",
    "metadata": {},
    "outputs": [],
    "source": []
diff --git a/hp4155/Custom_SMU/main.py b/hp4155/Custom_SMU/main.py
index 98f8c9c..6049c85 100644
--- a/hp4155/Custom_SMU/main.py
+++ b/hp4155/Custom_SMU/main.py
@@ -4,6 +4,7 @@ sys.path.insert(0, '..') #append parent directory
 import os
 import configparser
 import warnings
+import traceback
 
 from interface import *
 from help import *
@@ -24,7 +25,7 @@ tab.titles = titles
 display(tab)
 
 start = widgets.Button(description='Start Measurement')
-ini = widgets.Button(description = 'Import from ini. (Coming Soon)',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))
+ini = widgets.Button(description = 'Import from ini.')
 output = widgets.Output()
 
 display(widgets.HBox([start,ini]),output)
@@ -256,8 +257,8 @@ def on_start_clicked(b):
                 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}")
+                config.add_section(f"MEASUREMENT MODE:{measurement_mode}")
+                config.add_section(f"INTEGRATION TIME:{integration}")
                 
                 # First the smus
                 config.add_section("SMUS")
@@ -445,8 +446,8 @@ def on_start_clicked(b):
                 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}")
+                config.add_section(f"MEASUREMENT MODE:{measurement_mode}")
+                config.add_section(f"INTEGRATION TIME:{integration}")
                 
                 # First the smus
                 config.add_section("SMUS")
@@ -467,6 +468,9 @@ def on_start_clicked(b):
                 for key,value in parameters.items():
                     config.set('SAMPLING PARAMETERS',key,str(value))
 
+                # Sampling time
+                config.set('SAMPLING PARAMETERS','duration',str(duration))
+
                 # Now the constant smus
                 config.add_section('CONSTANT SMUS')
                 for i, cons_smu in enumerate(cons_smus):
@@ -578,7 +582,7 @@ def on_start_clicked(b):
                 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"MEASUREMENT MODE:{measurement_mode}")
                 
                 # First the smus
                 config.add_section("SMUS")
@@ -608,9 +612,6 @@ def on_start_clicked(b):
         ini.disabled = False
         return # just to be sure
 
-# This should be tested at the end.
-# After the ini files have been created
-"""
 def on_ini_clicked(b):
     with output:
         clear_output()
@@ -638,16 +639,151 @@ def on_ini_clicked(b):
             # Get the measurement Mode
             measurement_mode = get_mode(sections)
 
+
             # Get the constant smus
             for j in range(1,5):
                 third_page[21,j].value = config.get(f"CONSTANT SMU{j}",'value') 
                 third_page[22,j].value = config.get(f"CONSTANT SMU{j}",'comp')
                 
-
+            
             if measurement_mode == 'SWEEP':
                 third_page[0,0].value = measurement_mode
                 third_page[0,1].value = get_integration(sections)
 
-"""                
+                # Get the SMU channels 
+                for i in range(1,5):
+                    first_page[i,1].value = config.get(f"SMU{i}",'vname')
+                    first_page[i,2].value = config.get(f"SMU{i}",'iname')
+                    first_page[i,3].value = config.get(f"SMU{i}",'mode')
+                    first_page[i,4].value = config.get(f"SMU{i}",'func')
+                    first_page[i,5].value = eval(config.get(f"SMU{i}",'disabled'))
+
+                # Get the maximum 6 user functions
+                for i in range(1,7):
+                    if f"USER FUNCTION {i}" in sections:
+                        second_page[i,0].value = config.get(f"USER FUNCTION {i}",'name')
+                        second_page[i,1].value = config.get(f"USER FUNCTION {i}",'unit')
+                        second_page[i,2].value = config.get(f"USER FUNCTION {i}",'expression')
+
+                # Get the Sweep units VAR1,VAR2,VARD, PULSE
+                # VAR1
+                third_page[4,0].value = config.get('VAR1','start')
+                third_page[5,0].value = config.get('VAR1','stop')
+                third_page[6,0].value = config.get('VAR1','step')
+                third_page[7,0].value = config.get('VAR1','comp')
+                third_page[8,0].value = config.get('VAR1','pcomp')
+                hyst = config.get('VAR1','mode')
+                if hyst == 'SING':
+                    third_page[9,0].value = False
+                elif hyst == 'DOUB':
+                    third_page[9,0].value = True
+                else:
+                    raise Exception("Invalid Hysterisis Mode")
+
+                # VAR2
+                third_page[4,1].value = config.get('VAR2','start')
+                third_page[5,1].value = config.get('VAR2','step')
+                third_page[6,1].value = config.get('VAR2','points')
+                third_page[7,1].value = config.get('VAR2','comp')
+                third_page[8,1].value = config.get('VAR2','pcomp')
+
+                # VARD
+                third_page[4,2].value = config.get('VARD','offset')
+                third_page[5,2].value = config.get('VARD','ratio')
+                third_page[7,2].value = config.get('VARD','comp')
+                third_page[8,2].value = config.get('VARD','pcomp')
+
+                # PULSE
+                third_page[4,3].value = config.get('PULSE','period')
+                third_page[5,3].value = config.get('PULSE','width')
+                third_page[6,3].value = config.get('PULSE','base')
+
+
+                # Get the axes
+                for j in range(1,4):
+                    fourth_page[1,j].value = config.get(f"AXIS {j}",'name')
+                    fourth_page[2,j].value = config.get(f"AXIS {j}",'scale')
+                    fourth_page[3,j].value = config.get(f"AXIS {j}",'min')
+                    fourth_page[4,j].value = config.get(f"AXIS {j}",'max')
+                
+                
+                # Get the variables
+                for i in range(8):
+                    if f"VARIABLE {i+1}" in sections:
+                        fifth_page[6+i,0].value = config.get(f"VARIABLE {i+1}",'name')
+                        fifth_page[6+i,1].value = config.get(f"VARIABLE {i+1}",'unit')
+
+            elif measurement_mode == 'SAMPLING':
+                third_page[0,0].value = measurement_mode
+                third_page[0,1].value = get_integration(sections)
+
+                # Get the SMU channels 
+                for i in range(1,5):
+                    first_page[i,1].value = config.get(f"SMU{i}",'vname')
+                    first_page[i,2].value = config.get(f"SMU{i}",'iname')
+                    first_page[i,3].value = config.get(f"SMU{i}",'mode')
+                    first_page[i,4].value = config.get(f"SMU{i}",'func')
+                    first_page[i,5].value = eval(config.get(f"SMU{i}",'disabled'))
+
+                # Get the maximum 6 user functions
+                for i in range(1,7):
+                    if f"USER FUNCTION {i}" in sections:
+                        second_page[i,0].value = config.get(f"USER FUNCTION {i}",'name')
+                        second_page[i,1].value = config.get(f"USER FUNCTION {i}",'unit')
+                        second_page[i,2].value = config.get(f"USER FUNCTION {i}",'expression')
+
+                # Get the sampling Parameters
+                third_page[12,0].value = config.get('SAMPLING PARAMETERS','mode')
+                third_page[13,0].value = config.get('SAMPLING PARAMETERS','interval')
+                third_page[16,0].value = config.get('SAMPLING PARAMETERS','hold')
+                third_page[14,0].value = config.get('SAMPLING PARAMETERS','points')
+                third_page[17,0].value = bool(config.get('SAMPLING PARAMETERS','filter'))
+                third_page[15,0].value = config.get('SAMPLING PARAMETERS','duration')
+
+                # Get the axes
+                for j in range(1,4):
+                    fourth_page[1,j].value = config.get(f"AXIS {j}",'name')
+                    fourth_page[2,j].value = config.get(f"AXIS {j}",'scale')
+                    fourth_page[3,j].value = config.get(f"AXIS {j}",'min')
+                    fourth_page[4,j].value = config.get(f"AXIS {j}",'max')
+                
+                
+                # Get the variables
+                for i in range(8):
+                    if f"VARIABLE {i+1}" in sections:
+                        fifth_page[6+i,0].value = config.get(f"VARIABLE {i+1}",'name')
+                        fifth_page[6+i,1].value = config.get(f"VARIABLE {i+1}",'unit')
             
-start.on_click(on_start_clicked)
\ No newline at end of file
+            elif measurement_mode == 'STRESS':
+                third_page[0,0].value = measurement_mode
+                # There is no integration time
+                # Get the SMU channels 
+                for i in range(1,5):
+                    first_page[i,1].value = config.get(f"SMU{i}",'name')
+                    # There is not iname
+                    first_page[i,3].value = config.get(f"SMU{i}",'mode')
+                    # Function is set automatically
+                    first_page[i,5].value = eval(config.get(f"SMU{i}",'disabled'))
+
+                # Skip The user Functions
+
+                # Set the Stress parameters
+                third_page[15,0].value = config.get('PARAMETERS','stress time')
+                third_page[16,0].value = config.get('PARAMETERS','hold time')
+                third_page[17,0].value = bool(config.get('PARAMETERS','filter'))
+
+                # Skip the axes and variables
+            else:
+                raise Exception("MEASUREMENT MODE NOT FOUND!")
+
+
+        except Exception as e:
+            error_box(traceback.format_exc())
+                
+        change_state(first_page,second_page,third_page,fourth_page,fifth_page)
+        start.disabled = False
+        ini.disabled = False
+       
+                     
+start.on_click(on_start_clicked)
+ini.on_click(on_ini_clicked)
\ No newline at end of file
-- 
GitLab