import pyvisa import time timedelta = 0.05 class Keithley_2230G: 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) self.set_Output(1, False) time.sleep(0.1) self.set_Output(2, False) time.sleep(0.1) self.set_Output(3, False) time.sleep(0.1) def __del__(self): self.rm.close() def read_Voltage(self): #reads applied voltage of all three channels simultaneously. Output has format [V1, V2, V3]. command = f':MEAS:VOLT? ALL' data = str(self.inst.query(command)) data = data.split(', ') #Split string in single objects data = [float(i) for i in data] time.sleep(timedelta) return data def read_Current(self): #reads applied current of all three channels simultaneously. Output has format [I1, I2, I3]. command = f':MEAS:CURR? ALL' data = str(self.inst.query(command)) data = data.split(', ') #Split string in single objects data = [float(i) for i in data] time.sleep(timedelta) return data def read_Power(self): #reads applied power of all three channels simultaneously. Output has format [P1, P2, P3]. command = f':MEAS:POW? ALL' data = str(self.inst.query(command)) data = data.split(', ') #Split string in single objects data = [float(i) for i in data] time.sleep(timedelta) return data def set_Voltage(self, CH, Voltage): #sets Voltage in Volt for channel CH #Selects channel which voltage should be changed: command = f':INST:SEL CH{CH}' self.inst.write(command) time.sleep(timedelta) #Sets voltage of selected channel: command = f':SOURCE:VOLT {Voltage}V' self.inst.write(command) time.sleep(timedelta) def set_Current(self, CH, Current): #sets Current in Ampere for channel CH #Selects channel which current should be changed: command = f':INST:SEL CH{CH}' self.inst.write(command) time.sleep(timedelta) #Sets current of selected channel: command = f':SOURCE:CURR {Current}A' self.inst.write(command) time.sleep(timedelta) def set_Output(self, CH, On): #sets Output of channel CH on or off. # On -> On = True, # Off -> On = False #Selects channel which output should be changed: command = f':INST:SEL CH{CH}' self.inst.write(command) time.sleep(timedelta) #Sets output of selected channel: if On == True: command = 'SOURCE:OUTP:ENAB ON' self.inst.write(command) time.sleep(timedelta) command = 'SOUR:OUTP ON' #in case all three channels were disabled the device sets output = off automatically. Enabling one channel again will not turn on the output again. We have to do it by hand. self.inst.write(command) elif On == False: command = 'SOURCE:OUTP:ENAB OFF' self.inst.write(command) time.sleep(timedelta)