import pyvisa import time timedelta = 0.02 class BK_9174B: 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, baud_rate=57600) #Default baud_rate is 9600 but this results in an error. except: print(f'could not connect to {adress}') return time.sleep(1) def __del__(self): self.rm.close() def read_Voltage(self): #reads applied voltage of both channels simultaneously. Output has format [V1, V2]. command1 = f':MEAS:VOLT?' command2 = f':MEAS:VOLT 2?' data1 = str(self.inst.query(command1)) time.sleep(timedelta) data2 = str(self.inst.query(command2)) data = [float(data1), float(data2)] time.sleep(timedelta) return data def read_Current(self): #reads applied current of both channels simultaneously. Output has format [I1, I2]. command1 = f':MEAS:CURR?' command2 = f':MEAS:CURR 2?' data1 = str(self.inst.query(command1)) time.sleep(timedelta) data2 = str(self.inst.query(command2)) data = [float(data1), float(data2)] time.sleep(timedelta) return data def set_Voltage(self, CH, Voltage): #sets Voltage in Volt for channel CH if CH==1: command = f':VOLT {Voltage}' self.inst.write(command) time.sleep(timedelta) if CH==2: command = f':VOLT2 {Voltage}' self.inst.write(command) time.sleep(timedelta) def set_Current(self, CH, Current): #sets Current in Ampere for channel CH if CH==1: command = f':CURR {Current}' self.inst.write(command) time.sleep(timedelta) if CH==2: command = f':CURR2 {Current}' self.inst.write(command) time.sleep(timedelta) def set_Output(self, CH, On): #sets Output of channel CH on or off. # ON = True -> Turns output on # ON = False -> Turns output off if CH==1: if On == True: command = ':OUT ON' self.inst.write(command) elif On == False: command = ':OUT OFF' self.inst.write(command) if CH==2: if On == True: command = ':OUT2 ON' self.inst.write(command) elif On == False: command = ':OUT2 OFF' self.inst.write(command) time.sleep(timedelta) def set_Voltage_slewrate(self, CH, slewrate): #sets slew rate of channel CH, [slewrate] = V/ms if CH==1: command = f':OUT:SR:VOLT {slewrate}' self.inst.write(command) time.sleep(timedelta) if CH==2: command = f':OUT:SR:VOLT2 {slewrate}' self.inst.write(command) time.sleep(timedelta)