Skip to content

Commit

Permalink
Merge pull request #236 from iago-rst/thorlabs-kls1550
Browse files Browse the repository at this point in the history
Add Thorlabs KLS1550 laser driver
  • Loading branch information
astafan8 authored Aug 23, 2023
2 parents 2336e34 + 0c027c2 commit 0f0006e
Show file tree
Hide file tree
Showing 3 changed files with 403 additions and 0 deletions.
190 changes: 190 additions & 0 deletions docs/examples/Thorlabs_KLS1550.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5658297a",
"metadata": {},
"source": [
"# QCoDeS example with Thorlabs KLS1550 laser source\n",
"(same .dll as for KLS101, KLSnnn)"
]
},
{
"cell_type": "markdown",
"id": "1a175bbe",
"metadata": {},
"source": [
"## Initialisation\n",
"Import all required libraries for driving the devices."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e1d78fec",
"metadata": {},
"outputs": [],
"source": [
"import qcodes as qc\n",
"from qcodes_contrib_drivers.drivers.Thorlabs.Kinesis import Thorlabs_Kinesis\n",
"from qcodes_contrib_drivers.drivers.Thorlabs.KLS1550 import Thorlabs_KLS1550"
]
},
{
"cell_type": "markdown",
"id": "59f40438",
"metadata": {},
"source": [
"Create an instance of `Thorlabs_Kinesis` which is a wrapper for the device dll (passed as an argument to the object) that starts up the Kinesis server. The DLL needs be installed from https://www.thorlabs.com/software_pages/viewsoftwarepage.cfm?code=Motion_Control under \"Kinesis software\"."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58c7f162",
"metadata": {},
"outputs": [],
"source": [
"kinesis = Thorlabs_Kinesis(\"Thorlabs.MotionControl.KCube.LaserSource.dll\", sim=False)\n",
"print(kinesis.device_list())"
]
},
{
"cell_type": "markdown",
"id": "c318ee9d",
"metadata": {},
"source": [
"Create an instance of `Thorlabs_KLS1550` which is the device driver object, opening the device and starting polling (requesting device information) at 200 milisecods loops (must know the serial number shown on the device)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f3b0d44a",
"metadata": {},
"outputs": [],
"source": [
"qc.Instrument.close_all()\n",
"laser = Thorlabs_KLS1550(\n",
" name=\"laser\",\n",
" serial_number=\"...\",\n",
" polling_speed=200, \n",
" kinesis=kinesis)"
]
},
{
"cell_type": "markdown",
"id": "23bbe1b8",
"metadata": {},
"source": [
"## Turning the laser output on/off\n",
"Set the parameter `output_enabled` to True for \"laser on\" and False for \"laser off\". Note that the laser will only turn on if the safety switch is also on."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be1b61a4",
"metadata": {},
"outputs": [],
"source": [
"laser.output_enabled.set(True) # laser turns on"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6bf23da9",
"metadata": {},
"outputs": [],
"source": [
"laser.output_enabled.set(False) # laser turns off"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2f603470",
"metadata": {},
"outputs": [],
"source": [
"laser.output_enabled.get() # Check laser output status"
]
},
{
"cell_type": "markdown",
"id": "c58d355f",
"metadata": {},
"source": [
"## Setting the laser output power\n",
"Set the laser output power in Watts and get the current power value from the device (also in Watts)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d4d690cd",
"metadata": {},
"outputs": [],
"source": [
"laser.power.set(1e-3) # Set power to 1 mW"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e852001",
"metadata": {},
"outputs": [],
"source": [
"laser.power.get() # Gets laser power reading"
]
},
{
"cell_type": "markdown",
"id": "b497e7c7",
"metadata": {},
"source": [
"## Disconnecting\n",
"Disconnect the device from the driver (but not the server, it still shows under `device_list`), stopping polling and closing the device (both for Kinesis server and qcodes)."
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7333f215",
"metadata": {},
"outputs": [],
"source": [
"laser.close()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (qcodes)",
"language": "python",
"name": "qcodes"
},
"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.11.4"
},
"toc-autonumbering": false,
"toc-showcode": true,
"toc-showmarkdowntxt": false,
"nbsphinx": {
"execute": "never"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
81 changes: 81 additions & 0 deletions qcodes_contrib_drivers/drivers/Thorlabs/KLS1550.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
from qcodes import Instrument
import qcodes.utils.validators as vals

from .Kinesis import Thorlabs_Kinesis


class Thorlabs_KLS1550(Instrument):
def __init__(
self,
name: str,
serial_number: str,
polling_speed_ms: int,
kinesis: Thorlabs_Kinesis,
**kwargs,
):
super().__init__(name, **kwargs)
# Save Kinesis server reference
self.kinesis = kinesis

# Initialization
self.serial_number = serial_number
self.polling_speed_ms = polling_speed_ms
self.kinesis.open_laser(self.serial_number)
self.kinesis.start_polling(self.serial_number, self.polling_speed_ms)
self.info = self.kinesis.laser_info(self.serial_number)
self.model = self.info[0].value.decode("utf-8")
self.version = self.info[4].value

# Parameters
self.add_parameter(
"output_enabled",
get_cmd=self._get_output_enabled,
set_cmd=self._set_output_enabled,
vals=vals.Bool(),
unit="",
label="Laser output on/off",
docstring="Turn laser output on/off. Note that laser key switch must be on to turn laser output on.",
)

self.add_parameter(
"power",
get_cmd=self._get_power,
set_cmd=self._set_power,
vals=vals.Numbers(0, 0.007), # [ATTENTION] max power for simulator is 10mW
unit="W",
label="Power output",
)

self.connect_message()

def get_idn(self):
return {
"vendor": "Thorlabs",
"model": self.model,
"firmware": self.version,
"serial": self.serial_number,
}

def _get_output_enabled(self):
# First status bit represents 'output enabled'
return bool(self.kinesis.laser_status_bits(self.serial_number) & 1)

def _set_output_enabled(self, value: bool):
if value:
self.kinesis.laser_enable_output(self.serial_number)
else:
self.kinesis.laser_disable_output(self.serial_number)

def _get_power(self):
return self.kinesis.get_laser_power(self.serial_number)

def _set_power(self, power_W: float):
self.kinesis.set_laser_power(self.serial_number, power_W)

def disconnect(self):
self.kinesis.stop_polling(self.serial_number)
self.kinesis.close_laser(self.serial_number)

def close(self):
self.disconnect()
super().close()
Loading

0 comments on commit 0f0006e

Please sign in to comment.