-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPS_DP832A.py
278 lines (222 loc) · 13.2 KB
/
PS_DP832A.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# Author: Malyshev Sergey 2022, Ekaterinburg
#
# References
# - http://www.batronix.com/pdf/Rigol/ProgrammingGuide/DP800_ProgrammingGuide_EN.pdf
#
# Instructions
# - Download and install National Instruments VISA software (https://www.ni.com/visa/ OR https://skachat.freedownloadmanager.org/Windows-PC/NI-VISA-Runtime/FREE-5.4.html)
# - Download and install PyVISA (eg. "pip install -U pyvisa" from CMD)
# - Download and install PySimpleGUI ("python -m pip install pysimplegui" from CMD)
import PySimpleGUI as sg
import pyvisa
import time
#--------------------------GLOBAL VARIABLES CONST---------------------------------
VERSION_MAJOR = 0
VERSION_MINOR = 3
VERSION_PATCH = 2
DELAY_AFTER_MEAS = 0.01
DEBUG = False # Will set True to run debug mode
NO_DEBUG_CONNECT_PSU = True # Will set False to run without connection
#--------------------------GENERAL CLASS------------------------------------------
class Canal_DP832(object): # Создали класс
measPower = 0 # Свойства класса(атрибуты)
measVolt = 0
measCurrent = 0
def __init__(self, number, voltage, current, ovp, ocp): # Конструктор
self.channelNumber = number
self.voltage = voltage
self.current = current
self.ovp = ovp
self.ocp = ocp
def run_channel(self, voltage, current, ocp): # Создали метод запуска канала
if NO_DEBUG_CONNECT_PSU:
print(psu.query("*IDN?"))
psu.write(f":INST CH{self.channelNumber}") # Select channel
psu.write(f":CURR {current}") # Set the current
psu.write(f":CURR:PROT {ocp}") # Set the overcurrent protection value
psu.write(":CURR:PROT:STAT ON") # Enable the overcurrent protection function
psu.write(f":VOLT {voltage}") # Set the voltage
psu.write(f":OUTP CH{self.channelNumber},ON") # Enable the output of channel
window['quote'].update(f'CH{self.channelNumber}: {voltage} V, {current} A, OCP {ocp} A', text_color = 'yellow')
def off_channel(self):
if NO_DEBUG_CONNECT_PSU:
psu.write(f":OUTP CH{self.channelNumber},OFF") # Disable the output of channel
print(f"channel {self.channelNumber} DP832A disable")
window['quote'].update(f'Output CH{self.channelNumber} disable', text_color = 'yellow')
#--------------------------GENERAL FUNCTIONS---------------------------------------
def off_all_channel():
ch1.off_channel();
ch2.off_channel();
ch3.off_channel();
window['quote'].update('Output all disable', text_color = 'yellow')
def measVolt(chan):
cmd1 = ':MEAS:VOLT? CH%s' %chan
V = psu.query(cmd1)
V = float(V)
time.sleep(DELAY_AFTER_MEAS)
return V
def measCurrent(chan):
cmd1 = ':MEAS:CURR? CH%s' %chan
C = psu.query(cmd1)
C = float(C)
time.sleep(DELAY_AFTER_MEAS)
return C
def measPower(chan):
cmd1 = ':MEAS:POWE? CH%s' %chan
P = psu.query(cmd1)
P = float(P)
time.sleep(DELAY_AFTER_MEAS)
return P
def mainMeas():
def debugOut():
print("Power: " + str(ch1.power) + " mW" + " Voltage: " + str(ch1.volt) + " V" + " Current: " + str(ch1.current) + " A")
print("Power: " + str(ch2.power) + " mW" + " Voltage: " + str(ch2.volt) + " V" + " Current: " + str(ch2.current) + " A")
print("Power: " + str(ch3.power) + " mW" + " Voltage: " + str(ch3.volt) + " V" + " Current: " + str(ch3.current) + " A")
ch1.measPower = measPower(1) # Создали атрибут объекта
ch1.measVolt = round(measVolt(1), 2)
ch1.measCurrent = round(measCurrent(1), 4)
ch2.measPower = measPower(2)
ch2.measVolt = round(measVolt(2), 2)
ch2.measCurrent = round(measCurrent(2), 4)
ch3.measPower = measPower(3)
ch3.measVolt = round(measVolt(3), 2)
ch3.measCurrent = round(measCurrent(3), 4)
if DEBUG:
debugOut()
def checkInputVoltage(value):
if value > 32:
raise Exception("Voltage")
return value
def checkInputOVP(value):
if value > 33:
raise Exception("Voltage")
return value
def checkInputVoltage2(value):
if value > 5.3:
raise Exception("Voltage")
return value
def checkInputOVP2(value):
if value > 5.5:
raise Exception("Voltage")
return value
def checkInputCurrent(value):
if value > 3.2:
raise Exception("Current")
return value
def checkInputOCP(value):
if value > 3.3:
raise Exception("Current")
return value
def screenUpdateValue():
window['-OUTPUT_VOLT_1-'].update(str(ch1.measVolt) + " V")
window['-OUTPUT_CURR_1-'].update(str(ch1.measCurrent) + " A")
window['-OUTPUT_VOLT_2-'].update(str(ch2.measVolt) + " V")
window['-OUTPUT_CURR_2-'].update(str(ch2.measCurrent) + " A")
window['-OUTPUT_VOLT_3-'].update(str(ch3.measVolt) + " V")
window['-OUTPUT_CURR_3-'].update(str(ch3.measCurrent) + " A")
sg.theme('Dark Amber') # Let's set our own color theme (sg.theme_previewer() # Просмотр всех доступных тем)
rm = pyvisa.ResourceManager()
if NO_DEBUG_CONNECT_PSU:
try:
psu = rm.open_resource('USB0::0x1AB1::0x0E11::DP8B241601290::INSTR')
except:
sg.popup('Error: Not connection DP832A')
# Экземпляры классов(объекты)
ch1 = Canal_DP832(1, 24, 0.2, 33, 3) # Установить номер канала и значения параметров по умолчанию
ch2 = Canal_DP832(2, 24, 0.3, 33, 3)
ch3 = Canal_DP832(3, 5, 0.3, 5.5, 0.5)
#-------Сreate the GUI-----------
layout = [ [sg.Frame('CH1: 32 V 3.2 A', [[sg.Button('Set CH1'), sg.Button('Reset CH1'), sg.Text(f'{ch1.measVolt}', size=(6, 1), font=('Helvetica', 16), key='-OUTPUT_VOLT_1-', text_color='yellow'), sg.Text(f'{ch1.measCurrent}', size=(7, 1), font=('Helvetica', 16), key='-OUTPUT_CURR_1-', text_color='yellow')],
[sg.Text('Voltage, V:', size=(8, 1)), sg.Text(f'{ch1.voltage}', size=(4, 1), font=('Helvetica 11'), key='voltage_out'), sg.InputText(key='-VOLTAGE-', size=(6, 1)), sg.Text('OVP:', size=(4, 1)), sg.Text(f'{ch1.ovp}', size=(2, 1), font=('Helvetica 11'), key='OVP_out'), sg.InputText(key='-OVP-', size=(6, 1))],
[sg.Text('Current, A:', size=(8, 1)), sg.Text(f'{ch1.current}', size=(4, 1), font=('Helvetica 11'), key='current_out'), sg.InputText(key='-CURRENT-', size=(6, 1)), sg.Text('OCP:', size=(4, 1)), sg.Text(f'{ch1.ocp}', size=(2, 1), font=('Helvetica 11'), key='OCP_out'), sg.InputText(key='-OCP-', size=(6, 1))]])],
[sg.Frame('CH2: 32 V 3.2 A', [[sg.Button('Set CH2'), sg.Button('Reset CH2'), sg.Text(f'{ch2.measVolt}', size=(6, 1), font=('Helvetica', 16), key='-OUTPUT_VOLT_2-', text_color = 'cyan'), sg.Text(f'{ch2.measCurrent}', size=(7, 1), font=('Helvetica', 16), key='-OUTPUT_CURR_2-', text_color = 'cyan')],
[sg.Text('Voltage, V:', size=(8, 1)), sg.Text(f'{ch2.voltage}', size=(4, 1), font=('Helvetica 11'), key='voltage_out2'), sg.InputText(key='-VOLTAGE2-', size=(6, 1)), sg.Text('OVP:', size=(4, 1)), sg.Text(f'{ch2.ovp}', size=(2, 1), font=('Helvetica 11'), key='OVP_out2'), sg.InputText(key='-OVP2-', size=(6, 1))],
[sg.Text('Current, A:', size=(8, 1)), sg.Text(f'{ch2.current}', size=(4, 1), font=('Helvetica 11'), key='current_out2'), sg.InputText(key='-CURRENT2-', size=(6, 1)), sg.Text('OCP:', size=(4, 1)), sg.Text(f'{ch2.ocp}', size=(2, 1), font=('Helvetica 11'), key='OCP_out2'), sg.InputText(key='-OCP2-', size=(6, 1))]])],
[sg.Frame('CH3: 5 V 3.2 A', [[sg.Button('Set CH3'), sg.Button('Reset CH3'), sg.Text(f'{ch3.measVolt}', size=(6, 1), font=('Helvetica', 16), key='-OUTPUT_VOLT_3-', text_color = 'magenta'), sg.Text(f'{ch3.measCurrent}', size=(7, 1), font=('Helvetica', 16), key='-OUTPUT_CURR_3-', text_color = 'magenta')],
[sg.Text('Voltage, V:', size=(8, 1)), sg.Text(f'{ch3.voltage} ', size=(4, 1), font=('Helvetica 11'), key='voltage_out3'), sg.InputText(key='-VOLTAGE3-', size=(6, 1)), sg.Text('OVP:', size=(4, 1)), sg.Text(f'{ch3.ovp}', size=(2, 1), font=('Helvetica 11'), key='OVP_out3'), sg.InputText(key='-OVP3-', size=(6, 1))],
[sg.Text('Current, A:', size=(8, 1)), sg.Text(f'{ch3.current}', size=(4, 1), font=('Helvetica 11'), key='current_out3'), sg.InputText(key='-CURRENT3-', size=(6, 1)), sg.Text('OCP:', size=(4, 1)), sg.Text(f'{ch3.ocp}', size=(2, 1), font=('Helvetica 11'), key='OCP_out3'), sg.InputText(key='-OCP3-', size=(6, 1))]])],
[sg.Frame('Fast preset', [[sg.Button('CH1'), sg.Button('CH2'), sg.Button('CH3'), sg.Button('OFF')]]), sg.Frame('System', [[sg.Button('Exit', size=(5, 1)), sg.Button('About', size=(5, 1))]])],
[sg.Text('This is GUI driving Rigol DP832A', key='quote', text_color='yellow')]
]
window = sg.Window('Run DP832A', layout)
while True:
event, values = window.read(timeout=200) # Read the event that happened and the values dictionary, timeout=200 - не блокирующий режим
if DEBUG:
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit': # If user closed window with X or if user clicked "Exit" button then exit
break
if event == 'About':
sg.popup('Run DP832A', f'Version {VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}', '2022, Ekaterinburg', sg.get_versions())
if event == 'Set CH1':
try:
if values['-VOLTAGE-'] > '0': # Проверка на ноль
ch1.voltage = float(values['-VOLTAGE-']) # Проверка на ввод цифры(а не буквы)
ch1.voltage = checkInputVoltage(ch1.voltage) # Проверка на верхний диапазон
window['voltage_out'].update(values['-VOLTAGE-'])
if values['-CURRENT-'] > '0':
ch1.current = checkInputCurrent(float(values['-CURRENT-']))
window['current_out'].update(values['-CURRENT-'])
if values['-OVP-'] > '0':
ch1.ovp = checkInputOVP(float(values['-OVP-']))
window['OVP_out'].update(values['-OVP-'])
if values['-OCP-'] > '0':
ch1.ocp = checkInputOCP(float(values['-OCP-']))
window['OCP_out'].update(values['-OCP-'])
ch1.run_channel(ch1.voltage, ch1.current, ch1.ocp)
except Exception as e:
window['quote'].update('Value input error CH1: '+ str(e), text_color ='red')
print("Value input CH1 error: "+ str(e))
if event == 'Reset CH1':
ch1.off_channel()
if event == 'Set CH2':
try:
if values['-VOLTAGE2-'] > '0':
ch2.voltage = checkInputVoltage(float(values['-VOLTAGE2-']))
window['voltage_out2'].update(values['-VOLTAGE2-'])
if values['-CURRENT2-'] > '0':
ch2.current = checkInputCurrent(float(values['-CURRENT2-']))
window['current_out2'].update(values['-CURRENT2-'])
if values['-OVP2-'] > '0':
ch2.ovp = checkInputOVP(float(values['-OVP2-']))
window['OVP_out2'].update(values['-OVP2-'])
if values['-OCP2-'] > '0':
ch2.ocp = checkInputOCP(float(values['-OCP2-']))
window['OCP_out2'].update(values['-OCP2-'])
ch2.run_channel(ch2.voltage, ch2.current, ch2.ocp)
except Exception as e:
window['quote'].update('Value input error CH2: '+ str(e), text_color ='red')
print("Value input CH2 error: "+ str(e))
if event == 'Reset CH2':
ch2.off_channel()
if event == 'Set CH3':
try:
if values['-VOLTAGE3-'] > '0':
ch3.voltage = checkInputVoltage2(float(values['-VOLTAGE3-']))
window['voltage_out3'].update(values['-VOLTAGE3-'])
if values['-CURRENT3-'] > '0':
ch3.current = checkInputCurrent(float(values['-CURRENT3-']))
window['current_out3'].update(values['-CURRENT3-'])
if values['-OVP3-'] > '0':
ch3.ovp = checkInputOVP2(float(values['-OVP3-']))
window['OVP_out3'].update(values['-OVP3-'])
if values['-OCP3-'] > '0':
ch3.ocp = checkInputOCP(float(values['-OCP3-']))
window['OCP_out3'].update(values['-OCP3-'])
ch3.run_channel(ch3.voltage, ch3.current, ch3.ocp)
except Exception as e:
window['quote'].update('Value input error CH3: '+ str(e), text_color ='red')
print("Value input CH2 error: "+ str(e))
if event == 'Reset CH3':
ch3.off_channel()
if event == 'CH1':
ch1.run_channel(24, 0.2, 3) # Fast preset
if event == 'CH2':
ch2.run_channel(24, 0.2, 3)
if event == 'CH3':
ch3.run_channel(5, 0.3, 0.5)
if event == 'OFF':
off_all_channel()
if NO_DEBUG_CONNECT_PSU:
mainMeas()
screenUpdateValue()
window.close()