-
Notifications
You must be signed in to change notification settings - Fork 2
/
PSU.py
71 lines (50 loc) · 2 KB
/
PSU.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pyvisa
class PSU:
"""
Power supply unit control software for Spacedot's Helmholtz cage.
"""
def __init__(self, channel='CH1', model='DP712'):
self.max_current = 3
self.max_voltage = 50
assert model in ['DP712', 'SPD3303C']
connected_devices = pyvisa.ResourceManager().list_resources()
if len(connected_devices) == 2:
if model == 'DP712':
psu = connected_devices[0]
else:
psu = connected_devices[1]
else:
psu = connected_devices[0]
self.channel = channel
self.device = pyvisa.ResourceManager().open_resource(psu)
def set_voltage_and_current(self, voltage, current):
assert voltage <= self.max_voltage
assert current <= self.max_current
command = (':APPLy ' + self.channel + ',' + str(voltage) + ',' + str(current))
self.device.write(command)
def set_voltage(self, voltage):
assert voltage <= self.max_voltage
command = (self.channel + ':VOLT ' + str(voltage))
self.device.write(command)
def set_current(self, current):
assert current <= self.max_current
command = (self.channel + ':CURR ' + str(current))
self.device.write(command)
def get_current(self):
command = ':CURR?'
self.visa_device.write(command)
return self.visa_device.query(command.decode('utf-8'), delay=0.01)
def get_voltage(self):
command = ':VOLT?'
self.visa_device.write(command)
return self.visa_device.query(command.decode('utf-8'), delay=0.01)
def measure_current(self):
command = ':MEAS:CURR?'
self.device.write(command)
return self.visa_device.query(command.decode('utf-8'), delay=0.01)
def measure_voltage(self):
command = ':MEAS:VOLT?'
self.device.write(command)
return self.visa_device.query(command.decode('utf-8'), delay=0.01)
def set_channel(self, channel):
self.channel = channel