-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDP832_iontrap1.py
230 lines (198 loc) · 7.95 KB
/
DP832_iontrap1.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Author: QF Lao
# References
# - http://www.batronix.com/pdf/Rigol/ProgrammingGuide/DP800_ProgrammingGuide_EN.pdf
# - https://www.rigol.com/Images/DP800_ProgrammingGuide_CN_tcm4-3044.pdf
# - https://github.com/freq0ut/Python-PyVisa
# - https://pyvisa.readthedocs.io/en/latest/
# - http://juluribk.com/controlling-rigol-dp832-with-python/
# - https://github.com/kearneylackas/DP832-Python/blob/master/DP832.py
# Instructions
# - Download and install National Instruments VISA software (https://www.ni.com/zh-cn/support/downloads/drivers/download.ni-visa.html#442805)
# - Download and install PyVISA (eg. "pip install -U pyvisa" from command line)
# Python Function
# - find() (https://www.runoob.com/python/att-string-find.html)
from pyvisa import *
import time
_delay = 0.01 # in seconds
class DP832_Flip:
def __init__(self):
try:
self.rm = ResourceManager()
self.instrument_list = self.rm.list_resources()
self.address = [elem for elem in self.instrument_list if (elem.find('TCPIP') != -1 and elem.find('192.168.1.109') != -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 = 'LAN'
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
class DP832_Oven_PMT:
def __init__(self):
try:
self.rm = ResourceManager()
self.instrument_list = self.rm.list_resources()
self.address = [elem for elem in self.instrument_list if (elem.find('TCPIP') != -1 and elem.find('192.168.1.112') != -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 = 'LAN'
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