diff --git a/.gitignore b/.gitignore index d28ae8ab93ed5d693391ad32633d1110969fd884..45dc3c05122df1982a843f24ef4842d4f08a0e84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ *__pycache__ data/ dlls/ -*.ini \ No newline at end of file +*.ini +*.vs +*bin/ +*obj/ \ No newline at end of file diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index bbb289ec7f888ad8d87d2e34ec8dde7c4f8bdfba..53f919484e05c4753f1493c6e60b604f914073b6 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -5,6 +5,6 @@ "\\src\\classes", "\\src\\configs" ], - "SelectedNode": "\\src\\classes\\controltab.py", + "SelectedNode": "\\src", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/.vs/minimoke/FileContentIndex/015f0ba8-f9eb-4fb3-8476-f512bae48cd3.vsidx b/.vs/minimoke/FileContentIndex/015f0ba8-f9eb-4fb3-8476-f512bae48cd3.vsidx deleted file mode 100644 index 714d6a9852513c5a4473628c94ba2ca2945b68ec..0000000000000000000000000000000000000000 Binary files a/.vs/minimoke/FileContentIndex/015f0ba8-f9eb-4fb3-8476-f512bae48cd3.vsidx and /dev/null differ diff --git a/.vs/minimoke/FileContentIndex/0be09d6d-0426-4af2-bc57-cfa37326716c.vsidx b/.vs/minimoke/FileContentIndex/0be09d6d-0426-4af2-bc57-cfa37326716c.vsidx deleted file mode 100644 index 33bb2c830d296742c083522eb36d10aee13d396e..0000000000000000000000000000000000000000 Binary files a/.vs/minimoke/FileContentIndex/0be09d6d-0426-4af2-bc57-cfa37326716c.vsidx and /dev/null differ diff --git a/.vs/minimoke/FileContentIndex/2099b974-40cc-4214-ac4a-e988077b281f.vsidx b/.vs/minimoke/FileContentIndex/2099b974-40cc-4214-ac4a-e988077b281f.vsidx deleted file mode 100644 index b9d9f206bef70b9e762ba6f30484a262a3981ed3..0000000000000000000000000000000000000000 Binary files a/.vs/minimoke/FileContentIndex/2099b974-40cc-4214-ac4a-e988077b281f.vsidx and /dev/null differ diff --git a/.vs/minimoke/FileContentIndex/d83fd0c8-b937-441d-9691-f2de6420a626.vsidx b/.vs/minimoke/FileContentIndex/d83fd0c8-b937-441d-9691-f2de6420a626.vsidx deleted file mode 100644 index d005c7508d8746d707340afab198f132a04b3131..0000000000000000000000000000000000000000 Binary files a/.vs/minimoke/FileContentIndex/d83fd0c8-b937-441d-9691-f2de6420a626.vsidx and /dev/null differ diff --git a/.vs/minimoke/v17/.wsuo b/.vs/minimoke/v17/.wsuo index ec85072c95ebb78e21297f627dc5bda11eed08a5..5d1c69e4bf2fb683d17e73b622966d935f56d427 100644 Binary files a/.vs/minimoke/v17/.wsuo and b/.vs/minimoke/v17/.wsuo differ diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite index 3a9037579e96cb40ae4f99c9a04191c8055e9fe8..3c073a60d44e469bb26e35a19f9b85368deed5f3 100644 Binary files a/.vs/slnx.sqlite and b/.vs/slnx.sqlite differ diff --git a/client.py b/client.py new file mode 100644 index 0000000000000000000000000000000000000000..54bf361a0c6cd2788aa9105e3a38a9fed8124fd7 --- /dev/null +++ b/client.py @@ -0,0 +1,12 @@ +from msl.loadlib import Client64 + + +class Client(Client64): + + def __init__(self): + # pass the server file we just created in module32=, the host am using is localhost, leave port as none for self assigning + super(Client, self).__init__(module32='server', host="127.0.0.1", port=None) + + # define a function that calls the an existing server function and passes the args + def fsl_command(self, com, doc): + return self.request32('fsl_command', com, doc) diff --git a/cshargapp.c b/cshargapp.c deleted file mode 100644 index 251dfd9a7d60eb0269e817b6e7fdae8d2ce57295..0000000000000000000000000000000000000000 --- a/cshargapp.c +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Threading; -using MagnetPhysik; - -namespace SensorApp -{ - class Program - { - static void Main(string[] args) - { - HallProbe hally = new HallProbe(); - - for (int i = 0; i < 100; i++) - { - Console.WriteLine(hally.Tesla); - Thread.Sleep(500); - } - } - } -} diff --git a/hall_probe.py b/hall_probe.py deleted file mode 100644 index 69b9812f5c41abce41b95a406c2601e2d576d5c1..0000000000000000000000000000000000000000 --- a/hall_probe.py +++ /dev/null @@ -1,14 +0,0 @@ -import subprocess -import time - -# Call the 32-bit application -process = subprocess.Popen(['path/to/SensorApp.exe'], stdout=subprocess.PIPE, text=True) - -# Read and print output -for x in range(100): - output = process.stdout.readline().strip() # strip() removes the newline - print("Field[T]: ", output) - time.sleep(0.5) - -# Make sure the process has finished -process.communicate() diff --git a/main.py b/main.py index b0cc767a0d9bf682118c87f2482949b6d2fff799..76203594e1106b0f5e0529e8514ada174c7912fe 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,6 @@ from pylablib.devices import Thorlabs from pymeasure.experiment import unique_filename from pymeasure.experiment import Results -from pymeasure.display.widgets import TableWidget from pymeasure.display.Qt import QtWidgets import logging @@ -27,20 +26,11 @@ class MainWindow(UIWindown): displays=['acq_time', 'freq'], x_axis='Iteration', y_axis='Voltage', - widget_list=tuple([TableWidget("Experiment Table", - B_Sweep.DATA_COLUMNS, - by_column=True, - ), - ControlTab("Manual control")]), + widget_list=tuple([ControlTab("Manual control")]), directory_input=True ) self.setWindowTitle('Mini MOKE') self.directory = 'data' - try: - for device in Thorlabs.list_kinesis_devices(): - log.info("Thorlab device connected: ",device[1], "with serial number: ", device[0]) - except: - pass def queue(self, procedure=None): direc = self.directory + '/' + datetime.now().strftime('%Y-%m') diff --git a/server.py b/server.py new file mode 100644 index 0000000000000000000000000000000000000000..7a35913e2b15d3526a53281ce577ee49a954ee98 --- /dev/null +++ b/server.py @@ -0,0 +1,15 @@ +#server.py +from msl.loadlib import Server32 + + +class Server(Server32): + # the init takes mandatory host and port as arguments + def __init__(self, host, port, **kwargs): + # using windll since this application is being run in windows, other options such as cdll exists + # this assumes that the dll file is in the same directory as this file + super(Server, self).__init__('C:/Program Files (x86)/Magnet-Physik/USB Teslameter/MagnetPhysik.Usb.dll', 'net', host, port) + + # define a function that is to be called with the required arguments + def fsl_command(self, com, doc): + #the server32 exposes the loaded dll as lib, which you can then use to call the dll functions and pass the required arguments + return 0 \ No newline at end of file diff --git a/src/classes/controltab.py b/src/classes/controltab.py index f36e2fd61c343b152b958995762b23faadfe7b38..95857afc6d35e2a4060fbf43ca47b3df0738bc22 100644 --- a/src/classes/controltab.py +++ b/src/classes/controltab.py @@ -30,17 +30,17 @@ class ControlTab(TabWidget, QtWidgets.QWidget): layout.addWidget(self.go_button, 0, 3) self.x_label = QtWidgets.QLabel("X Position:") - self.x_value = QtWidgets.QLabel(self.stage.get_x_pos()) + self.x_value = QtWidgets.QLabel(self.stage.get_x_pos_str()) layout.addWidget(self.x_label, 1, 0) layout.addWidget(self.x_value, 1, 1) self.y_label = QtWidgets.QLabel("Y Position:") - self.y_value = QtWidgets.QLabel(self.stage.get_y_pos()) + self.y_value = QtWidgets.QLabel(self.stage.get_y_pos_str()) layout.addWidget(self.y_label, 2, 0) layout.addWidget(self.y_value, 2, 1) self.z_label = QtWidgets.QLabel("Focus Position:") - self.z_value = QtWidgets.QLabel(self.stage.get_z_pos()) + self.z_value = QtWidgets.QLabel(self.stage.get_z_pos_str()) layout.addWidget(self.z_label, 3, 0) layout.addWidget(self.z_value, 3, 1) @@ -175,6 +175,6 @@ class ControlTab(TabWidget, QtWidgets.QWidget): self.update_positions() def update_positions(self): - self.x_value.setText(self.stage.get_x_pos()) - self.y_value.setText(self.stage.get_y_pos()) - self.z_value.setText(self.stage.get_z_pos()) \ No newline at end of file + self.x_value.setText(self.stage.get_x_pos_str()) + self.y_value.setText(self.stage.get_y_pos_str()) + self.z_value.setText(self.stage.get_z_pos_str()) \ No newline at end of file diff --git a/src/classes/hall_sensor.py b/src/classes/hall_sensor.py index dfacb354b2bab6d1e443318048f81cdaaf783287..e6e4b00d3b2745a84357fea117eb80999eb0321c 100644 --- a/src/classes/hall_sensor.py +++ b/src/classes/hall_sensor.py @@ -1,20 +1,31 @@ -import time -import sys -import clr -import platform - -# Load the DLL -sys.path.append(r"C:/Program Files (x86)/Magnet-Physik/USB Teslameter/") -clr.AddReference("MagnetPhysik.Usb") - -from MagnetPhysik import HallProbe +import subprocess +from time import sleep class HallSensor(): def __init__(self): - self.hall_probe = HallProbe() + pass def read_mT(self): """ Returns the value measured by the sensor in mT """ - return self.hall_probe.Tesla / 1000. \ No newline at end of file + process = subprocess.Popen(['src/hallsensor/read/bin/Release/net6.0/read.exe'], stdout=subprocess.PIPE, text=True) + line = "" + for i in range(100): + line = process.stdout.readline().strip() + if (line.startswith('Field')): + break + return float(line.split(':')[1]) * 1000. + + def zeroing(self): + """ + Zeroing the probe, should be done at 0 magnetic field + """ + process = subprocess.Popen(['src/hallsensor/zeroing/bin/Release/net6.0/zeroing.exe'], stdout=subprocess.PIPE, text=True) + line = "" + for i in range(100): + line = process.stdout.readline().strip() + if (line.startswith('Done')): + return True + sleep(0.02) + return False \ No newline at end of file diff --git a/src/classes/stage.py b/src/classes/stage.py index 352329a1046a76ebe4c3797f35f703381caf03f3..d14d796407a3fec02d287d04c6b649318e863dac 100644 --- a/src/classes/stage.py +++ b/src/classes/stage.py @@ -144,20 +144,38 @@ class Stage(): # GET THE POSITION ################################################################# - def get_x_pos(self): + def get_x_pos_str(self) -> str: if self.open: return f"{(self.motor_x.get_position(scale=False) - self.offset_x) / 46694.:.{3}f}mm" else: return "?" - def get_y_pos(self): + def get_y_pos_str(self) -> str: if self.open: return f"{(self.motor_y.get_position(scale=False) - self.offset_y) / 46694.:.{3}f}mm" else: return "?" - def get_z_pos(self): + def get_z_pos_str(self) -> str: if self.open: return f"{(self.motor_z.get_position(scale=False) - self.offset_z) / 46694.:.{3}f}mm" else: - return "?" \ No newline at end of file + return "?" + + def get_x_pos(self) -> float: + if self.open: + return (self.motor_x.get_position(scale=False) - self.offset_x) / 46694. + else: + return float('nan') + + def get_y_pos(self) -> float: + if self.open: + return (self.motor_y.get_position(scale=False) - self.offset_y) / 46694. + else: + return float('nan') + + def get_z_pos(self) -> float: + if self.open: + return (self.motor_z.get_position(scale=False) - self.offset_z) / 46694. + else: + return float('nan') \ No newline at end of file diff --git a/src/hallsensor/read/Program.cs b/src/hallsensor/read/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..5c71008f29b7fc3ee6f375734608872ef103c807 --- /dev/null +++ b/src/hallsensor/read/Program.cs @@ -0,0 +1,16 @@ +using MagnetPhysik; + +namespace SensorApp +{ + class Program + { + static void Main(string[] args) + { + HallProbe hally = new HallProbe(); + + hally.Range = 8; + + Console.WriteLine("Field:" + (hally.Tesla).ToString()); + } + } +} \ No newline at end of file diff --git a/src/hallsensor/read/read.csproj b/src/hallsensor/read/read.csproj new file mode 100644 index 0000000000000000000000000000000000000000..b462c618db62e4a0da9c5e2445815193af917a9a --- /dev/null +++ b/src/hallsensor/read/read.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <Reference Include="MagnetPhysik.Usb"> + <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Magnet-Physik\USB Teslameter\MagnetPhysik.Usb.dll</HintPath> + </Reference> + </ItemGroup> + +</Project> diff --git a/src/hallsensor/read/read.sln b/src/hallsensor/read/read.sln new file mode 100644 index 0000000000000000000000000000000000000000..c0481ea85ab9aa8be57dcea3e2b7df6f902e9e09 --- /dev/null +++ b/src/hallsensor/read/read.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33723.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "read", "read.csproj", "{B43E7DBF-F27A-4A85-B7BE-AA15D3623492}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B43E7DBF-F27A-4A85-B7BE-AA15D3623492}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B43E7DBF-F27A-4A85-B7BE-AA15D3623492}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B43E7DBF-F27A-4A85-B7BE-AA15D3623492}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B43E7DBF-F27A-4A85-B7BE-AA15D3623492}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {12BD2CD8-C47E-4E85-9CD3-60A276BB70A7} + EndGlobalSection +EndGlobal diff --git a/src/hallsensor/zeroing/Program.cs b/src/hallsensor/zeroing/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..aacd50557c30a719c7af581bc2958510619c54d2 --- /dev/null +++ b/src/hallsensor/zeroing/Program.cs @@ -0,0 +1,18 @@ +using MagnetPhysik; + +namespace SensorApp +{ + class Program + { + static void Main(string[] args) + { + HallProbe hally = new HallProbe(); + + hally.Zero = true; + + while (hally.Zero) { } + + Console.WriteLine("Done"); + } + } +} \ No newline at end of file diff --git a/src/hallsensor/zeroing/zeroing.csproj b/src/hallsensor/zeroing/zeroing.csproj new file mode 100644 index 0000000000000000000000000000000000000000..b462c618db62e4a0da9c5e2445815193af917a9a --- /dev/null +++ b/src/hallsensor/zeroing/zeroing.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <Reference Include="MagnetPhysik.Usb"> + <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Magnet-Physik\USB Teslameter\MagnetPhysik.Usb.dll</HintPath> + </Reference> + </ItemGroup> + +</Project> diff --git a/src/hallsensor/zeroing/zeroing.sln b/src/hallsensor/zeroing/zeroing.sln new file mode 100644 index 0000000000000000000000000000000000000000..165a6add5950af5acfdad4fae874d1abb3c77e34 --- /dev/null +++ b/src/hallsensor/zeroing/zeroing.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33723.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "zeroing", "zeroing.csproj", "{85BC8862-612D-4A2B-B01C-82BD931B11E0}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {85BC8862-612D-4A2B-B01C-82BD931B11E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85BC8862-612D-4A2B-B01C-82BD931B11E0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85BC8862-612D-4A2B-B01C-82BD931B11E0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85BC8862-612D-4A2B-B01C-82BD931B11E0}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {903BD3EF-37F9-4E2A-B36E-853EBF911C38} + EndGlobalSection +EndGlobal diff --git a/src/procedures/b_sweep.py b/src/procedures/b_sweep.py index d2958d329983284ab1122b2af21bad2e7553c197..9dee8b9b73fa1acc83d4c09685b65b981ab2e0cd 100644 --- a/src/procedures/b_sweep.py +++ b/src/procedures/b_sweep.py @@ -7,6 +7,7 @@ from pymeasure.experiment import Procedure, IntegerParameter, FloatParameter from ..classes.stage import Stage from ..classes.dac import DAC +from ..classes.hall_sensor import HallSensor log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) @@ -15,8 +16,8 @@ class B_Sweep(Procedure): name = "B-Sweep" acq_time = FloatParameter('Aquisition time', units='s', default=1) freq = FloatParameter('Aquisition Frequency', units='Hz', default=50) - b_min = FloatParameter('From B (max 6A)', units='A', minimum=0., maximum=6., default=0) - b_max = FloatParameter('To B (max 6A)', units='A', minimum=0., maximum=6., default=5) + b_min = FloatParameter('From B (max 6A)', units='A', minimum=-6., maximum=6., default=0) + b_max = FloatParameter('To B (max 6A)', units='A', minimum=-6., maximum=6., default=5) b_step = FloatParameter('Step', units='A', default=0.1) x = FloatParameter('Position x', units='mm', default=0) y = FloatParameter('Position y', units='mm', default=0) @@ -31,8 +32,9 @@ class B_Sweep(Procedure): voltage = DAC("ai0") field = DAC("ao1") + hall_sensor = HallSensor() - b_values = np.linspace(self.b_min, self.b_max, int((self.b_max-self.b_min)//self.b_step + 1), endpoint=True) + b_values = np.linspace(self.b_min, self.b_max, int(np.abs(self.b_max-self.b_min)//self.b_step + 2), endpoint=True) field.write(self.b_min) @@ -61,7 +63,10 @@ class B_Sweep(Procedure): data = { 'Iteration': i, + 'X Position': stage.get_x_pos(), + 'Y Position': stage.get_y_pos(), 'Magnetic Field [A]': b_values[i], + 'Magnetic Field [mT]': hall_sensor.read_mT(), 'Voltage': np.mean(average_voltage) } diff --git a/src/procedures/x_sweep.py b/src/procedures/x_sweep.py index ed8ba067b5e5af1c5a49869b4334670c58efb40f..9194f1e9600dc08022495f50ebe44136acd62984 100644 --- a/src/procedures/x_sweep.py +++ b/src/procedures/x_sweep.py @@ -7,6 +7,7 @@ from pymeasure.experiment import Procedure, IntegerParameter, FloatParameter from ..classes.stage import Stage from ..classes.dac import DAC +from ..classes.hall_sensor import HallSensor log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) @@ -31,8 +32,9 @@ class X_Sweep(Procedure): voltage = DAC("ai0") field = DAC("ao1") + hall_sensor = HallSensor() - x_positions = np.linspace(self.x_min, self.x_max, int((self.x_max-self.x_min)//self.x_step+1), endpoint=True) + x_positions = np.linspace(self.x_min, self.x_max, int((self.x_max-self.x_min)//self.x_step+2), endpoint=True) field.write(self.field) @@ -60,6 +62,9 @@ class X_Sweep(Procedure): data = { 'Iteration': i, 'X Position': x_positions[i], + 'Y Position': stage.get_y_pos(), + 'Magnetic Field [A]': field, + 'Magnetic Field [mT]': hall_sensor.read_mT(), 'Voltage': np.mean(average_voltage) } diff --git a/src/procedures/y_sweep.py b/src/procedures/y_sweep.py index 2acdef5309f98dd17b8812a8a11aa324a38ac4f4..531d2f285e3fd76c63fe20c1ebbb4d3cccbafa25 100644 --- a/src/procedures/y_sweep.py +++ b/src/procedures/y_sweep.py @@ -7,6 +7,7 @@ from pymeasure.experiment import Procedure, IntegerParameter, FloatParameter from ..classes.stage import Stage from ..classes.dac import DAC +from ..classes.hall_sensor import HallSensor log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) @@ -31,8 +32,9 @@ class Y_Sweep(Procedure): voltage = DAC("ai0") field = DAC("ao1") + hall_sensor = HallSensor() - y_positions = np.linspace(self.y_min, self.y_max, int((self.y_max-self.y_min)//self.y_step+1), endpoint=True) + y_positions = np.linspace(self.y_min, self.y_max, int((self.y_max-self.y_min)//self.y_step+2), endpoint=True) field.write(self.field) @@ -59,7 +61,10 @@ class Y_Sweep(Procedure): sleep(1/self.freq) data = { 'Iteration': i, + 'X Position': stage.get_x_pos(), 'Y Position': y_positions[i], + 'Magnetic Field [A]': field, + 'Magnetic Field [mT]': hall_sensor.read_mT(), 'Voltage': np.mean(average_voltage) }