craft-software/Legacy/Instrument_Drivers/drivers/Lakeshore218.py
2025-07-04 15:52:40 +02:00

44 lines
1.5 KiB
Python

import pyvisa
import time
class LakeShore218:
def __init__(self,adress):
#establish connection to device with pyvisa. The device is initiallized with visa adress "adress"
self.rm = pyvisa.ResourceManager()
try:
self.inst = self.rm.open_resource(adress)
except:
print(f'could not connect to {adress}')
return
time.sleep(1)
def __del__(self):
self.rm.close()
def read(self,CH):
#reads temperature Data in Kelvin from channels specified in CH. CH can be 1-8 for integer output of Channel CH.
#if CH=0 the output is a List of all 8 channels. CH can be a List (e.g. [1,4,7]) for the output of a List of specific channels.
if isinstance(CH, int): #if CH is a integer: Read a single channel
if CH>=0 and CH<9:
command = f'KRDG? {CH}'
data = str(self.inst.query(command))
data = data.split(',') #Split string in single objects (important for CH=0)
data = [float(i) for i in data]
time.sleep(0.1)
elif isinstance(CH, list): #if CH is a list: Read all specified channels manually.
data = []
for i in CH:
command = f'KRDG? {i}'
data_single = float(self.inst.query(command))
data.append(data_single)
time.sleep(0.1)
else:
data = [0]
return data