Skip to content
Snippets Groups Projects
Commit 4ce0def3 authored by esarrey's avatar esarrey
Browse files

Fully working b_sweep

parent 7ac48416
No related branches found
No related tags found
No related merge requests found
Showing
with 175 additions and 49 deletions
......@@ -2,4 +2,7 @@
*__pycache__
data/
dlls/
*.ini
\ No newline at end of file
*.ini
*.vs
*bin/
*obj/
\ No newline at end of file
......@@ -5,6 +5,6 @@
"\\src\\classes",
"\\src\\configs"
],
"SelectedNode": "\\src\\classes\\controltab.py",
"SelectedNode": "\\src",
"PreviewInSolutionExplorer": false
}
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
No preview for this file type
No preview for this file type
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)
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()
......@@ -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')
......
#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
......@@ -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
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
......@@ -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
using System;
using System.Threading;
using MagnetPhysik;
using MagnetPhysik;
namespace SensorApp
{
......@@ -10,11 +8,9 @@ namespace SensorApp
{
HallProbe hally = new HallProbe();
for (int i = 0; i < 100; i++)
{
Console.WriteLine(hally.Tesla);
Thread.Sleep(500);
}
hally.Range = 8;
Console.WriteLine("Field:" + (hally.Tesla).ToString());
}
}
}
}
\ No newline at end of file
<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>

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
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
<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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment