From a03559f6ef5af6e51129f216aa813f3e342a0650 Mon Sep 17 00:00:00 2001 From: gboedecker <125995107+gboedecker@users.noreply.github.com> Date: Tue, 17 Feb 2026 16:26:54 +0100 Subject: [PATCH] new ITC5 Python examples --- .../ITC5_ctypes.py | 63 +++++++++++++++++++ .../ITC5_pyvisa.py | 30 +++++++++ .../ITC5x Laser Diode Controllers/README.md | 15 +++++ 3 files changed, 108 insertions(+) create mode 100644 Python/ITC5x Laser Diode Controllers/ITC5_ctypes.py create mode 100644 Python/ITC5x Laser Diode Controllers/ITC5_pyvisa.py create mode 100644 Python/ITC5x Laser Diode Controllers/README.md diff --git a/Python/ITC5x Laser Diode Controllers/ITC5_ctypes.py b/Python/ITC5x Laser Diode Controllers/ITC5_ctypes.py new file mode 100644 index 0000000..2bf5774 --- /dev/null +++ b/Python/ITC5x Laser Diode Controllers/ITC5_ctypes.py @@ -0,0 +1,63 @@ +# -*- coding: utf-8 -*- + +# Title: ITC5000 in Python with CTypes. +# Created Date: 2026 - 02 - 17 +# Last modified date: 2026 - 02 - 17 +# Python Version Used: python3 +# Thorlabs Driver Version: 1.0 +# Notes: This example demonstrates how to control a Thorlabs ITC5 laser diode controller in Python using CTypes library. + + +import time +from ctypes import * + +lib = cdll.LoadLibrary("C:\Program Files\IVI Foundation\VISA\Win64\Bin\TL5000_64.dll") + +#documentation: C:\Program Files (x86)\IVI Foundation\VISA\WinNT\TL5000\Manual + +#Find connected devices and get resource name of the first device found. +resourcecount=c_int(0) +lib.TL5000_findRsrc(0,byref(resourcecount)) +print("Number of devices found: ", resourcecount.value) + +resourcename=create_string_buffer(256) +lib.TL5000_getRsrcName(0,0,byref(resourcename)) +print("Resource name: ", resourcename.value.decode()) + +#initialize device and get handle for further communication. +itc_handle=c_int(0) +res=lib.TL5000_init(resourcename,1,1,byref(itc_handle)) + +if res==0: + print("Device initialized successfully") + #TEC settings + lib.TL5000_setTecTempSensor(itc_handle,2,0)#slot 2 (tec channel), 0(AD590 sensor) + + # Temperature Setpoint + lib.TL5000_setTecTempSetpoint(itc_handle,2,c_double(26.0)) + tempset=c_double() + lib.TL5000_getTecTempSetpoint(itc_handle,2,0,byref(tempset)) + print("Temperature setpoint ",tempset.value) + + #Switch on TEC output + lib.TL5000_setTecOutputState(itc_handle,2,1)#slot 2 (tec channel), 1(on) + + time.sleep(2) + + #Measure temperature + temperature=c_double(0) + lib.TL5000_measTecTemp(itc_handle,2,0,byref(temperature)) + print("Measured temperature: ",temperature.value) + + #Laserdiode settings + lib.TL5000_setLdcOperatingMode(itc_handle,1,0)#0: constant current mode, 1: constant power mode + res=lib.TL5000_setLdcLdCurrSetpoint(itc_handle,1,c_double(0.1))# set current to 0.04 A + + time.sleep(1) + + setcurrent=c_double(0) + res=lib.TL5000_getLdcLdCurrSetpoint(itc_handle,1,0,byref(setcurrent)) + print("Current is set to: ", setcurrent.value) + + #Close connection + lib.TL5000_close(itc_handle) \ No newline at end of file diff --git a/Python/ITC5x Laser Diode Controllers/ITC5_pyvisa.py b/Python/ITC5x Laser Diode Controllers/ITC5_pyvisa.py new file mode 100644 index 0000000..9d6447a --- /dev/null +++ b/Python/ITC5x Laser Diode Controllers/ITC5_pyvisa.py @@ -0,0 +1,30 @@ +# Title: ITC5000 SCPI in Python. +# Created Date: 2026 - 02 - 17 +# Last modified date: 2026 - 02 - 17 +# Python Version Used: python3 +# NI-VISA Driver Version: 2025 +# Notes: This example demonstrates how to control a Thorlabs ITC5 laser diode controller in Python using SCPI commands. + +#Import the PyVISA library to Python. +import pyvisa +import sys + +#Opens a resource manager and shows the available VISA devices. +rm = pyvisa.ResourceManager() + + +#Opens the connection to the device. The variable instr is the handle for the device. +#The 'USB0...' number for a device can e.g. be found in the returned list of rm.list_resources(). +instr = rm.open_resource('USB0::0x1313::0x8281::M01299293::INSTR') + +print("Used device: ",instr.query('*IDN?')) + +#Sets the current setpoint and queries the new setting for confirmation. +#The command instr.write can be used to write data to the device when you do not expect a response from the device. +#instr.write("source:current:level:amplitude 0.065") +instr.write("SOURce1:CURRent 0.05")#laser diode current set to 50mA +print("Set LD current [A]:", instr.query("SOURce1:CURRent?")) + +#These lines will close the resource manager and the handle to the device. +instr.close() +rm.close() \ No newline at end of file diff --git a/Python/ITC5x Laser Diode Controllers/README.md b/Python/ITC5x Laser Diode Controllers/README.md new file mode 100644 index 0000000..8e4c63c --- /dev/null +++ b/Python/ITC5x Laser Diode Controllers/README.md @@ -0,0 +1,15 @@ +# Included Examples + +## ITC5x with ctypes + +This sample code shows how you can control a Thorlabs ITC5 laser diode controller in Python. It uses the CTypes library that has to be installed on the computer. + +## ITC5x with PyVISA + +This sample code shows how you can control a Thorlabs ITC laser diode controller in Python. It uses the PyVISA library that has to be installed on the computer.The PyVISA library is used to send SCPI commands to the controller. + +Please note that the resource name (“USB0::0x1313::…”) in the sample code needs to be adjusted to the used controller type and unit. + +The driver has to be switched to VISA drivers. + +