# pyright: basic import pyvisa import time TIMEDELTA = 0.02 class BK_9132B: def __init__(self, address, useSim=False): #establish connection to device with pyvisa. The device is initiallized with visa adress "adress" # if useSim: self.rm = pyvisa.ResourceManager(visa_library="@sim") # else: # self.rm= pyvisa.ResourceManager() try: # print(self.rm.list_resources()) self.inst = self.rm.open_resource(address) finally: time.sleep(1) # MG: why waste a second here?! # except: # raise ValueError(f'could not connect to {address}') 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 CH{CH}' self.inst.write(command) time.sleep(TIMEDELTA) #Sets voltage of selected channel: command = f':SOUR:VOLT {Voltage}' 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 CH{CH}' self.inst.write(command) time.sleep(TIMEDELTA) #Sets current of selected channel: command = f':SOUR:CURR {Current}' 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 CH{CH}' self.inst.write(command) time.sleep(TIMEDELTA) #Sets output of selected channel: if On == True: command = ':SOUR:CHAN:OUTP ON' self.inst.write(command) elif On == False: command = ':SOUR:CHAN:OUTP OFF' self.inst.write(command) time.sleep(TIMEDELTA)