Make the BK9132B driver more idiomatic
This commit is contained in:
parent
743f93cb4c
commit
01645145c4
96
components/PSU/BK_9132B/BK9132B_driver.py
Normal file
96
components/PSU/BK_9132B/BK9132B_driver.py
Normal file
@ -0,0 +1,96 @@
|
||||
import pyvisa
|
||||
import time
|
||||
|
||||
timedelta = 0.02
|
||||
|
||||
class BK_9132B:
|
||||
|
||||
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_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)
|
||||
Loading…
Reference in New Issue
Block a user