From 42daaacb30829ba9e7cfae41d2832d0d8c4f25df Mon Sep 17 00:00:00 2001 From: unknown <asoalexandros@gmail.com> Date: Fri, 28 Mar 2025 16:00:50 +0100 Subject: [PATCH] Import from ini file seems to work! --- hp4155/Custom_SMU/debug_ini.ipynb | 309 ++++++++++++++++++++++++++++++ hp4155/Custom_SMU/main.py | 161 ++++++++++++++-- 2 files changed, 458 insertions(+), 12 deletions(-) create mode 100644 hp4155/Custom_SMU/debug_ini.ipynb diff --git a/hp4155/Custom_SMU/debug_ini.ipynb b/hp4155/Custom_SMU/debug_ini.ipynb new file mode 100644 index 0000000..ad29520 --- /dev/null +++ b/hp4155/Custom_SMU/debug_ini.ipynb @@ -0,0 +1,309 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "6ef13cac-e600-42f8-a097-1c26e36fa733", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "d63ab88d4b68403da9e654e44ae37c40", + "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": "02dfee8d8a6e40cda5cfcbb9bab6c8fe", + "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": "07d32030e3d845fda574799105693d2a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Output()" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "import sys\n", + "sys.path.insert(0, './lib')\n", + "sys.path.insert(0, '..') #append parent directory\n", + "import os\n", + "import configparser\n", + "import warnings\n", + "import traceback\n", + "\n", + "from interface import *\n", + "from help import *\n", + "import hp4155a\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", + "ini = widgets.Button(description = 'Import from ini. (Coming Soon)',style = {'description_width': 'initial'},layout=Layout(height='auto', width='auto'))\n", + "output = widgets.Output()\n", + "\n", + "display(widgets.HBox([start,ini]),output)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "f5d81765-2cee-44ea-9e78-786f51d5366b", + "metadata": {}, + "outputs": [], + "source": [ + "def on_ini_clicked(b):\n", + " with output:\n", + " clear_output()\n", + " change_state(first_page,second_page,third_page,fourth_page,fifth_page)\n", + " start.disabled = True\n", + " ini.disabled = True\n", + "\n", + " #load values to the interface\n", + " config = configparser.ConfigParser()\n", + " try:\n", + " file = load_ini()\n", + " except Exception as e:\n", + " error_box(e)\n", + " change_state(first_page,second_page,third_page,fourth_page,fifth_page)\n", + " start.disabled = False\n", + " ini.disabled = False\n", + " return\n", + " try:\n", + " # Now we do exactly the opposite thing dictionaries to widgets\n", + " #read the values from each section\n", + " config.read(file)\n", + "\n", + " # Get the sections \n", + " sections = config.sections()\n", + " # Get the measurement Mode\n", + " measurement_mode = get_mode(sections)\n", + " print(measurement_mode)\n", + "\n", + "\n", + " # Get the constant smus\n", + " for j in range(1,5):\n", + " third_page[21,j].value = config.get(f\"CONSTANT SMU{j}\",'value') \n", + " third_page[22,j].value = config.get(f\"CONSTANT SMU{j}\",'comp')\n", + " \n", + " \n", + " if measurement_mode == 'SWEEP':\n", + " third_page[0,0].value = measurement_mode\n", + " third_page[0,1].value = get_integration(sections)\n", + "\n", + " # Get the SMU channels \n", + " for i in range(1,5):\n", + " first_page[i,1].value = config.get(f\"SMU{i}\",'vname')\n", + " first_page[i,2].value = config.get(f\"SMU{i}\",'iname')\n", + " first_page[i,3].value = config.get(f\"SMU{i}\",'mode')\n", + " first_page[i,4].value = config.get(f\"SMU{i}\",'func')\n", + " first_page[i,5].value = eval(config.get(f\"SMU{i}\",'disabled'))\n", + "\n", + " # Get the maximum 6 user functions\n", + " for i in range(1,7):\n", + " if f\"USER FUNCTION {i}\" in sections:\n", + " second_page[i,0].value = config.get(f\"USER FUNCTION {i}\",'name')\n", + " second_page[i,1].value = config.get(f\"USER FUNCTION {i}\",'unit')\n", + " second_page[i,2].value = config.get(f\"USER FUNCTION {i}\",'expression')\n", + "\n", + " # Get the Sweep units VAR1,VAR2,VARD, PULSE\n", + " # VAR1\n", + " third_page[4,0].value = config.get('VAR1','start')\n", + " third_page[5,0].value = config.get('VAR1','stop')\n", + " third_page[6,0].value = config.get('VAR1','step')\n", + " third_page[7,0].value = config.get('VAR1','comp')\n", + " third_page[8,0].value = config.get('VAR1','pcomp')\n", + " hyst = config.get('VAR1','mode')\n", + " if hyst == 'SING':\n", + " third_page[9,0].value = False\n", + " elif hyst == 'DOUB':\n", + " third_page[9,0].value = True\n", + " else:\n", + " raise Exception(\"Invalid Hysterisis Mode\")\n", + "\n", + " # VAR2\n", + " third_page[4,1].value = config.get('VAR2','start')\n", + " third_page[5,1].value = config.get('VAR2','step')\n", + " third_page[6,1].value = config.get('VAR2','points')\n", + " third_page[7,1].value = config.get('VAR2','comp')\n", + " third_page[8,1].value = config.get('VAR2','pcomp')\n", + "\n", + " # VARD\n", + " third_page[4,2].value = config.get('VARD','offset')\n", + " third_page[5,2].value = config.get('VARD','ratio')\n", + " third_page[7,2].value = config.get('VARD','comp')\n", + " third_page[8,2].value = config.get('VARD','pcomp')\n", + "\n", + " # PULSE\n", + " third_page[4,3].value = config.get('PULSE','period')\n", + " third_page[5,3].value = config.get('PULSE','width')\n", + " third_page[6,3].value = config.get('PULSE','base')\n", + "\n", + "\n", + " # Get the axes\n", + " for j in range(1,4):\n", + " fourth_page[1,j].value = config.get(f\"AXIS {j}\",'name')\n", + " fourth_page[2,j].value = config.get(f\"AXIS {j}\",'scale')\n", + " fourth_page[3,j].value = config.get(f\"AXIS {j}\",'min')\n", + " fourth_page[4,j].value = config.get(f\"AXIS {j}\",'max')\n", + " \n", + " \n", + " # Get the variables\n", + " for i in range(8):\n", + " if f\"VARIABLE {i+1}\" in sections:\n", + " fifth_page[6+i,0].value = config.get(f\"VARIABLE {i+1}\",'name')\n", + " fifth_page[6+i,1].value = config.get(f\"VARIABLE {i+1}\",'unit')\n", + "\n", + " elif measurement_mode == 'SAMPLING':\n", + " third_page[0,0].value = measurement_mode\n", + " third_page[0,1].value = get_integration(sections)\n", + "\n", + " # Get the SMU channels \n", + " for i in range(1,5):\n", + " first_page[i,1].value = config.get(f\"SMU{i}\",'vname')\n", + " first_page[i,2].value = config.get(f\"SMU{i}\",'iname')\n", + " first_page[i,3].value = config.get(f\"SMU{i}\",'mode')\n", + " first_page[i,4].value = config.get(f\"SMU{i}\",'func')\n", + " first_page[i,5].value = eval(config.get(f\"SMU{i}\",'disabled'))\n", + "\n", + " # Get the maximum 6 user functions\n", + " for i in range(1,7):\n", + " if f\"USER FUNCTION {i}\" in sections:\n", + " second_page[i,0].value = config.get(f\"USER FUNCTION {i}\",'name')\n", + " second_page[i,1].value = config.get(f\"USER FUNCTION {i}\",'unit')\n", + " second_page[i,2].value = config.get(f\"USER FUNCTION {i}\",'expression')\n", + "\n", + " # Get the sampling Parameters\n", + " third_page[12,0].value = config.get('SAMPLING PARAMETERS','mode')\n", + " third_page[13,0].value = config.get('SAMPLING PARAMETERS','interval')\n", + " third_page[16,0].value = config.get('SAMPLING PARAMETERS','hold')\n", + " third_page[14,0].value = config.get('SAMPLING PARAMETERS','points')\n", + " third_page[17,0].value = bool(config.get('SAMPLING PARAMETERS','filter'))\n", + " third_page[15,0].value = config.get('SAMPLING PARAMETERS','duration')\n", + "\n", + " # Get the axes\n", + " for j in range(1,4):\n", + " fourth_page[1,j].value = config.get(f\"AXIS {j}\",'name')\n", + " fourth_page[2,j].value = config.get(f\"AXIS {j}\",'scale')\n", + " fourth_page[3,j].value = config.get(f\"AXIS {j}\",'min')\n", + " fourth_page[4,j].value = config.get(f\"AXIS {j}\",'max')\n", + " \n", + " \n", + " # Get the variables\n", + " for i in range(8):\n", + " if f\"VARIABLE {i+1}\" in sections:\n", + " fifth_page[6+i,0].value = config.get(f\"VARIABLE {i+1}\",'name')\n", + " fifth_page[6+i,1].value = config.get(f\"VARIABLE {i+1}\",'unit')\n", + " \n", + " elif measurement_mode == 'STRESS':\n", + " third_page[0,0].value = measurement_mode\n", + " # There is no integration time\n", + " # Get the SMU channels \n", + " for i in range(1,5):\n", + " first_page[i,1].value = config.get(f\"SMU{i}\",'name')\n", + " # There is not iname\n", + " first_page[i,3].value = config.get(f\"SMU{i}\",'mode')\n", + " # Function is set automatically\n", + " first_page[i,5].value = eval(config.get(f\"SMU{i}\",'disabled'))\n", + "\n", + " # Skip The user Functions\n", + "\n", + " # Set the Stress parameters\n", + " third_page[15,0].value = config.get('PARAMETERS','stress time')\n", + " third_page[16,0].value = config.get('PARAMETERS','hold time')\n", + " third_page[17,0].value = bool(config.get('PARAMETERS','filter'))\n", + "\n", + " # Skip the axes and variables\n", + " else:\n", + " raise Exception(\"MEASUREMENT MODE NOT FOUND!\")\n", + "\n", + "\n", + " except Exception as e:\n", + " error_box(traceback.format_exc())\n", + " \n", + " change_state(first_page,second_page,third_page,fourth_page,fifth_page)\n", + " start.disabled = False\n", + " ini.disabled = False\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "5eb42711-7725-435f-acb7-f8f08dbeeb3c", + "metadata": {}, + "outputs": [], + "source": [ + "ini.on_click(on_ini_clicked)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee24c499-d47f-498d-9f32-6bd85ccb4b87", + "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/main.py b/hp4155/Custom_SMU/main.py index 98f8c9c..eac82ec 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() @@ -637,17 +638,153 @@ def on_ini_clicked(b): sections = config.sections() # Get the measurement Mode measurement_mode = get_mode(sections) + print(measurement_mode) + # 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