-
Notifications
You must be signed in to change notification settings - Fork 3
/
DP832.py
123 lines (104 loc) · 4 KB
/
DP832.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# Author: Kearney Lackas
# References
# - http://www.batronix.com/pdf/Rigol/ProgrammingGuide/DP800_ProgrammingGuide_EN.pdf
# - https://github.com/freq0ut/Python-PyVisa
# - http://juluribk.com/2015/05/08/controlling-rigol-dp832-with-python/
# Instructions
# - Download and install National Instruments VISA software (https://www.ni.com/visa/)
# - Download and install PyVISA (eg. "pip install -U pyvisa" from command line)
from visa import *
import time
_delay = 0.01 # in seconds
class DP832:
def __init__(self, usb_or_serial='USB0'):
try:
self.rm = ResourceManager()
self.instrument_list = self.rm.list_resources()
self.address = [elem for elem in self.instrument_list if (elem.find('USB') != -1 and elem.find(
usb_or_serial) != -1)] # Search a instrument with USB and serial number in the instrument list
if self.address.__len__() == 0:
self.status = "Not Connected"
# print("Could not connect to device")
else:
self.address = self.address[0]
self.device = self.rm.open_resource(self.address)
# print("Connected to " + self.address)
self.status = "Connected"
self.connected_with = 'USB'
except VisaIOError:
self.status = "Not Connected"
# print("PyVISA is not able to find any devices")
def select_output(self, chan):
# define a CHANNEL SELECT function
command = ':INST:NSEL %s' % chan
self.device.write(command)
time.sleep(_delay)
def toggle_output(self, chan, state):
# define a TOGGLE OUTPUT function
command = ':OUTP CH%s,%s' % (chan, state)
self.device.write(command)
time.sleep(_delay)
def set_voltage(self, chan, val):
# define a SET VOLTAGE function
command = ':INST:NSEL %s' % chan
self.device.write(command)
time.sleep(_delay)
command = ':VOLT %s' % val
self.device.write(command)
time.sleep(_delay)
def set_current(self, chan, val):
# define a SET CURRENT function
command = ':INST:NSEL %s' % chan
self.device.write(command)
time.sleep(_delay)
command = ':CURR %s' % val
self.device.write(command)
time.sleep(_delay)
def set_ovp(self, chan, val):
# define a SET VOLT PROTECTION function
command = ':INST:NSEL %s' % chan
self.device.write(command)
time.sleep(_delay)
command = ':VOLT:PROT %s' % val
self.device.write(command)
time.sleep(_delay)
def toggle_ovp(self, state):
# define a TOGGLE VOLTAGE PROTECTION function
command = ':VOLT:PROT:STAT %s' % state
self.device.write(command)
time.sleep(_delay)
def set_ocp(self, chan, val):
# define a SET CURRENT PROTECTION function
command = ':INST:NSEL %s' % chan
self.device.write(command)
time.sleep(_delay)
command = ':CURR:PROT %s' % val
self.device.write(command)
time.sleep(_delay)
def toggle_ocp(self, state):
# define a TOGGLE CURRENT PROTECTION function
command = ':CURR:PROT:STAT %s' % state
self.device.write(command)
time.sleep(_delay)
def measure_voltage(self, chan):
# define a MEASURE VOLTAGE function
command = ':MEAS:VOLT? CH%s' % chan
volt = self.device.query(command)
volt = float(volt)
time.sleep(_delay)
return volt
def measure_current(self, chan):
# define a MEASURE CURRENT function
command = ':MEAS:CURR? CH%s' % chan
curr = self.device.query(command)
curr = float(curr)
time.sleep(_delay)
return curr
def measure_power(self, chan):
# define a MEASURE POWER function
command = ':MEAS:POWE? CH%s' % chan
power = self.device.query(command)
power = float(power)
time.sleep(_delay)
return power