From 0ecf59c532d2e0cdec129cc7ea9404da64b72ad2 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Mon, 8 Jul 2024 13:30:22 +0900 Subject: [PATCH 1/3] move thorlabskpz and define KPZ101 class --- pymeasure/instruments/thorlabs/__init__.py | 1 + .../instruments/thorlabs/thorlabskpz101.py | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 pymeasure/instruments/thorlabs/thorlabskpz101.py diff --git a/pymeasure/instruments/thorlabs/__init__.py b/pymeasure/instruments/thorlabs/__init__.py index 24ffaadd53..9045b63385 100644 --- a/pymeasure/instruments/thorlabs/__init__.py +++ b/pymeasure/instruments/thorlabs/__init__.py @@ -24,3 +24,4 @@ from .thorlabspm100usb import ThorlabsPM100USB from .thorlabspro8000 import ThorlabsPro8000 +from .thorlabskpz101 import KPZ101 \ No newline at end of file diff --git a/pymeasure/instruments/thorlabs/thorlabskpz101.py b/pymeasure/instruments/thorlabs/thorlabskpz101.py new file mode 100644 index 0000000000..86cabd1192 --- /dev/null +++ b/pymeasure/instruments/thorlabs/thorlabskpz101.py @@ -0,0 +1,85 @@ +# Author: Amelie Deshazer +# Date: 2024-07-03 +# Purpose: This script will control the piezoelectric stage to move the reference arm. + +import logging + +log = logging.getLogger(__name__) +log.addHandler(logging.NullHandler()) + +import clr + +clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.DeviceManagerCLI") +clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericMotorCLI.dll") +clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericPiezoCLI.dll") +clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.KCube.PiezoCLI.dll") + +from Thorlabs.MotionControl.DeviceManagerCLI import * +from Thorlabs.MotionControl.GenericMotorCLI import * +from Thorlabs.MotionControl.GenericPiezoCLI import * +from Thorlabs.MotionControl.KCube.PiezoCLI import * +from System import Decimal +import time + +print("reading the class...") +class KPZ101(): + def __init__(self): + DeviceManagerCLI.BuildDeviceList() + serial_number = '' #must add serial number + self.device = KCubePiezo.CreateKCubePiezo(serial_number) + + self.device.Connect(serial_number) + + info_device = self.device.GetDeviceInfo() + print(info_device.Description) + + + self.device.StartPolling(250) + time.sleep(0.25) + log.info("Device polling started") + print("Device polling started") #for debugging purposes + + self.device.EnableDevice() + time.sleep(0.25) + log.info("Device enabled") + print("Device enabled") #for debugging purposes + + device_config = self.device.GetPiezoConfiguration() + print("Device configuration is %s" % device_config) #for debugging purposes + log.print("Device configuration is %s" % device_config) + + device_settings = self.device.PiezoDeviceSettings() + + def move_home(self): + self.device.SetZero() + log.info("Device moved to home position") + print("Device moved to home position") #for debugging purposes + + def max_voltage(self): + max_voltage = self.device.GetVoltageOutputMax() + return max_voltage + + def set_voltage(self,voltage): + #self.device.SetVoltageOutput(voltage) + # checks bounds of voltage parameter + if voltage != Decimal(0) & voltage <= self.max_voltage(): + self.device.SetVoltageOutput(voltage) + time.sleep(1.0) + log.info("Voltage set to %s" % voltage) + print("Voltage set to %s" % voltage) #for debugging purposes + + else: + print(f"Voltage must be between 0 and {self.max_voltage()}") + log.error(f"Voltage must be between 0 and {self.max_voltage()}") + + def disconnect(self): + self.device.StopPolling() + self.device.Disconnet() + log.info("Device has been disconnected") + print("Device has been disconnected") #for debugging purposes + + + + + + From 1279b1fcd36d32e0ff90b0b8e2e7e3cc4c173212 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Tue, 9 Jul 2024 13:09:20 +0900 Subject: [PATCH 2/3] delete print statements. Fix debug errors --- .../instruments/thorlabs/thorlabskpz101.py | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/pymeasure/instruments/thorlabs/thorlabskpz101.py b/pymeasure/instruments/thorlabs/thorlabskpz101.py index 86cabd1192..dcd5212d5b 100644 --- a/pymeasure/instruments/thorlabs/thorlabskpz101.py +++ b/pymeasure/instruments/thorlabs/thorlabskpz101.py @@ -8,6 +8,7 @@ log.addHandler(logging.NullHandler()) import clr +import System clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.DeviceManagerCLI") clr.AddReference(r"C:\Program Files\Thorlabs\Kinesis\Thorlabs.MotionControl.GenericMotorCLI.dll") @@ -21,62 +22,57 @@ from System import Decimal import time -print("reading the class...") + class KPZ101(): def __init__(self): DeviceManagerCLI.BuildDeviceList() - serial_number = '' #must add serial number + serial_number = '29252556' #must add serial number self.device = KCubePiezo.CreateKCubePiezo(serial_number) self.device.Connect(serial_number) info_device = self.device.GetDeviceInfo() - print(info_device.Description) + log.info(info_device.Description) self.device.StartPolling(250) time.sleep(0.25) log.info("Device polling started") - print("Device polling started") #for debugging purposes self.device.EnableDevice() time.sleep(0.25) - log.info("Device enabled") - print("Device enabled") #for debugging purposes + log.info("Device enabled") - device_config = self.device.GetPiezoConfiguration() - print("Device configuration is %s" % device_config) #for debugging purposes - log.print("Device configuration is %s" % device_config) + device_config = self.device.GetPiezoConfiguration(serial_number) + log.info("Device configuration is %s" % device_config) - device_settings = self.device.PiezoDeviceSettings() + device_settings = self.device.PiezoDeviceSettings def move_home(self): self.device.SetZero() log.info("Device moved to home position") - print("Device moved to home position") #for debugging purposes def max_voltage(self): - max_voltage = self.device.GetVoltageOutputMax() + max_voltage = self.device.GetMaxOutputVoltage() return max_voltage def set_voltage(self,voltage): - #self.device.SetVoltageOutput(voltage) - # checks bounds of voltage parameter - if voltage != Decimal(0) & voltage <= self.max_voltage(): - self.device.SetVoltageOutput(voltage) + voltage = Decimal(voltage) + + min_volt = System.Decimal(0) + max_volt = self.max_voltage() + if voltage != min_volt and voltage <= max_volt: + self.device.SetOutputVoltage(voltage) time.sleep(1.0) log.info("Voltage set to %s" % voltage) - print("Voltage set to %s" % voltage) #for debugging purposes else: - print(f"Voltage must be between 0 and {self.max_voltage()}") - log.error(f"Voltage must be between 0 and {self.max_voltage()}") + log.error(f"Voltage must be between 0 and {max_volt}") def disconnect(self): self.device.StopPolling() - self.device.Disconnet() + self.device.Disconnect() log.info("Device has been disconnected") - print("Device has been disconnected") #for debugging purposes From 68d526ee005a79767896cf4d996ce4a3b27ad493 Mon Sep 17 00:00:00 2001 From: adeshazer123 Date: Wed, 10 Jul 2024 13:34:23 +0900 Subject: [PATCH 3/3] add method to get voltage --- pymeasure/instruments/thorlabs/thorlabskpz101.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pymeasure/instruments/thorlabs/thorlabskpz101.py b/pymeasure/instruments/thorlabs/thorlabskpz101.py index dcd5212d5b..ebdb801ec0 100644 --- a/pymeasure/instruments/thorlabs/thorlabskpz101.py +++ b/pymeasure/instruments/thorlabs/thorlabskpz101.py @@ -56,6 +56,10 @@ def max_voltage(self): max_voltage = self.device.GetMaxOutputVoltage() return max_voltage + def get_voltage(self): + voltage = self.device.GetOutputVoltage() + return voltage + def set_voltage(self,voltage): voltage = Decimal(voltage)