-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
258 lines (213 loc) · 11.8 KB
/
main.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
""" Main body """
# pyinstaller --noconfirm
# --hidden-import six
# --hidden-import packaging
# --hidden-import packaging.version
# --hidden-import packaging.specifiers
# --hidden-import packaging.requirements
# -i "icon.ICO"
# -F
# -w
# main.py
import sys
import time
import visa
from PyQt5 import QtCore, QtWidgets
from interface import UI_Window
RM = visa.ResourceManager("C:/Windows/System32/visa64.dll") # "C:/Windows/System32/visa32.dll"
KEYSIGHT = RM.open_resource('TCPIP0::10.11.0.200::inst0::INSTR')
class Thread(QtCore.QThread):
""" Class Threading """
channel_one_v = QtCore.pyqtSignal(str)
channel_two_v = QtCore.pyqtSignal(str)
channel_three_v = QtCore.pyqtSignal(str)
channel_one_i = QtCore.pyqtSignal(str)
channel_two_i = QtCore.pyqtSignal(str)
channel_three_i = QtCore.pyqtSignal(str)
channel_one_w = QtCore.pyqtSignal(str)
channel_two_w = QtCore.pyqtSignal(str)
channel_three_w = QtCore.pyqtSignal(str)
def __init__(self, parent=None):
""" Initialization """
QtCore.QThread.__init__(self, parent=parent)
self.isRunning = True
def run(self):
""" Run Thread """
while self.isRunning:
time.sleep(5)
convert_one_power = round(float(KEYSIGHT.ask("MEASure:POWer? (@1)")), 3)
convert_two_power = round(float(KEYSIGHT.ask("MEASure:POWer? (@2)")), 3)
convert_three_power = round(float(KEYSIGHT.ask("MEASure:POWer? (@3)")), 3)
convert_one_voltage = round(float(KEYSIGHT.ask("MEASure:VOLTage? (@1)")), 3)
convert_two_voltage = round(float(KEYSIGHT.ask("MEASure:VOLTage? (@2)")), 3)
convert_three_voltage = round(float(KEYSIGHT.ask("MEASure:VOLTage? (@3)")), 3)
convert_one_current = round(float(KEYSIGHT.ask("MEASure:CURRent? (@1)")), 3)
convert_two_current = round(float(KEYSIGHT.ask("MEASure:CURRent? (@1)")), 3)
convert_three_current = round(float(KEYSIGHT.ask("MEASure:CURRent? (@1)")), 3)
self.channel_one_v.emit(str(convert_one_voltage))
self.channel_two_v.emit(str(convert_two_voltage))
self.channel_three_v.emit(str(convert_three_voltage))
self.channel_one_i.emit(str(convert_one_current))
self.channel_two_i.emit(str(convert_two_current))
self.channel_three_i.emit(str(convert_three_current))
self.channel_one_w.emit(str(convert_one_power))
self.channel_two_w.emit(str(convert_two_power))
self.channel_three_w.emit(str(convert_three_power))
def stop(self):
""" Stop Thread """
self.isRunning = False
self.quit()
self.wait()
class Window(QtWidgets.QMainWindow):
""" Main Window """
def __init__(self, parent=None):
""" Initialization """
QtWidgets.QWidget.__init__(self, parent)
self.ui = UI_Window()
self.ui.UI_Setup(self)
self.ui.pushButton_start.clicked.connect(self.start_connection)
self.ui.pushButton_stop.clicked.connect(self.stop_connection)
self.ui.pushButton_emergency.clicked.connect(self.emergency_stop)
self.ui.pushButton_allon.clicked.connect(self.turn_all_channels_on)
self.ui.pushButton_Ch1.clicked.connect(self.turn_on_channel_one)
self.ui.pushButton_Ch2.clicked.connect(self.turn_on_channel_two)
self.ui.pushButton_Ch3.clicked.connect(self.turn_on_channel_three)
self.ui.lineEdit_V_Ch1.returnPressed.connect(self.set_voltage_to_channel_one)
self.ui.lineEdit_V_Ch2.returnPressed.connect(self.set_voltage_to_channel_two)
self.ui.lineEdit_V_Ch3.returnPressed.connect(self.set_voltage_to_channel_three)
self.ui.lineEdit_I_Ch1.returnPressed.connect(self.set_current_to_channel_one)
self.ui.lineEdit_I_Ch2.returnPressed.connect(self.set_current_to_channel_two)
self.ui.lineEdit_I_Ch3.returnPressed.connect(self.set_current_to_channel_three)
self.th = Thread(self)
self.th.channel_one_v.connect(self.ui.lcdNumber_V_Ch1.display)
self.th.channel_two_v.connect(self.ui.lcdNumber_V_Ch2.display)
self.th.channel_three_v.connect(self.ui.lcdNumber_V_Ch3.display)
self.th.channel_one_i.connect(self.ui.lcdNumber_I_Ch1.display)
self.th.channel_two_i.connect(self.ui.lcdNumber_I_Ch2.display)
self.th.channel_three_i.connect(self.ui.lcdNumber_I_Ch3.display)
self.th.channel_one_w.connect(self.ui.lcdNumber_W_Ch1.display)
self.th.channel_two_w.connect(self.ui.lcdNumber_W_Ch2.display)
self.th.channel_three_w.connect(self.ui.lcdNumber_W_Ch3.display)
self.th.start()
def start_connection(self):
""" Соединение """
try:
if KEYSIGHT.resource_name.startswith('ASRL') or KEYSIGHT.resource_name.endswith('SOCKET'):
KEYSIGHT.read_termination = '\n'
self.ui.textEdit.append('IP-адрес: %s\nИмя: %s\nПорт: %d' % (KEYSIGHT.get_visa_attribute(visa.constants.VI_ATTR_TCPIP_ADDR),
KEYSIGHT.get_visa_attribute(visa.constants.VI_ATTR_TCPIP_HOSTNAME),
KEYSIGHT.get_visa_attribute(visa.constants.VI_ATTR_TCPIP_PORT)))
KEYSIGHT.write('*IDN?')
IDN = KEYSIGHT.read()
self.ui.textEdit.append('Идентификатор прибора: %s' % IDN.rstrip(' '))
except visa.Error as ex:
self.ui.textEdit.append('Ошибка: %s' % ex)
def stop_connection(self):
""" Закрыть соединение (не работает) """
try:
KEYSIGHT.close()
RM.close()
self.ui.textEdit.append('Соединение завершено')
except visa.Error as ex:
self.ui.textEdit.append('Ошибка: %s' % ex)
def turn_all_channels_on(self):
""" Включить все каналы """
KEYSIGHT.write("OUTPut:STATe ON, (@1)")
time.sleep(0.1)
KEYSIGHT.write("OUTPut:STATe ON, (@2)")
time.sleep(0.1)
KEYSIGHT.write("OUTPut:STATe ON, (@3)")
time.sleep(0.1)
self.ui.textEdit.append('ВНИМАНИЕ! Все каналы работают')
def emergency_stop(self):
""" Аварийное отключение всех каналов """
KEYSIGHT.write("OUTPut:STATe OFF, (@1)")
time.sleep(0.1)
KEYSIGHT.write("OUTPut:STATe OFF, (@2)")
time.sleep(0.1)
KEYSIGHT.write("OUTPut:STATe OFF, (@3)")
time.sleep(0.1)
self.ui.textEdit.append('ВНИМАНИЕ! Выполнено аварийное отключение')
def set_current_to_channel_one(self):
""" Установка тока """
current_variable = self.ui.lineEdit_I_Ch1.text()
if self.ui.lineEdit_I_Ch1.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("CURRent " + current_variable + ", (@1)")
self.ui.textEdit.append('Ограничение по току на перовом канале: ' + current_variable + ' A')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def set_current_to_channel_two(self):
""" Установка тока """
current_variable = self.ui.lineEdit_I_Ch2.text()
if self.ui.lineEdit_I_Ch2.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("CURRent " + current_variable + ", (@2)")
self.ui.textEdit.append('Ограничение по току на втором канале: ' + current_variable + ' A')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def set_current_to_channel_three(self):
""" Установка тока """
current_variable = self.ui.lineEdit_I_Ch3.text()
if self.ui.lineEdit_I_Ch3.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("CURRent " + current_variable + ", (@3)")
self.ui.textEdit.append('Ограничение по току на третьем канале: ' + current_variable + ' A')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def set_voltage_to_channel_one(self):
""" Установка напряжения """
voltage_variable = self.ui.lineEdit_V_Ch1.text()
if self.ui.lineEdit_V_Ch1.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("VOLTage " + voltage_variable + ", (@1)")
self.ui.textEdit.append('Напряжение на перовом канале: ' + voltage_variable + ' В')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def set_voltage_to_channel_two(self):
""" Установка напряжения """
voltage_variable = self.ui.lineEdit_V_Ch2.text()
if self.ui.lineEdit_V_Ch2.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("VOLTage " + voltage_variable + ", (@2)")
self.ui.textEdit.append('Напряжение на втором канале: ' + voltage_variable + ' В')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def set_voltage_to_channel_three(self):
""" Установка напряжения """
voltage_variable = self.ui.lineEdit_V_Ch3.text()
if self.ui.lineEdit_V_Ch3.text().replace('.', '', 1).isdigit():
KEYSIGHT.write("VOLTage " + voltage_variable + ", (@3)")
self.ui.textEdit.append('Напряжение на третьем канале: ' + voltage_variable + ' В')
else:
self.ui.textEdit.append("Ошибка: неверный формат ввода данных")
def turn_on_channel_one(self):
""" Включить канал """
if self.ui.pushButton_Ch1.isChecked():
KEYSIGHT.write("OUTPut:STATe ON, (@1)")
self.ui.textEdit.append('Первый канал работает')
self.ui.pushButton_Ch1.setText('Выключить')
else:
KEYSIGHT.write("OUTPut:STATe OFF, (@1)")
self.ui.textEdit.append('Первый канал отключен')
self.ui.pushButton_Ch1.setText('Включить')
def turn_on_channel_two(self):
""" Включить канал """
if self.ui.pushButton_Ch2.isChecked():
KEYSIGHT.write("OUTPut:STATe ON, (@2)")
self.ui.textEdit.append('Второй канал работает')
self.ui.pushButton_Ch2.setText('Выключить')
else:
KEYSIGHT.write("OUTPut:STATe OFF, (@2)")
self.ui.textEdit.append('Второй канал отключен')
self.ui.pushButton_Ch2.setText('Включить')
def turn_on_channel_three(self):
""" Включить канал """
if self.ui.pushButton_Ch3.isChecked():
KEYSIGHT.write("OUTPut:STATe ON, (@3)")
self.ui.textEdit.append('Третий канал работает')
self.ui.pushButton_Ch3.setText('Выключить')
else:
KEYSIGHT.write("OUTPut:STATe OFF, (@3)")
self.ui.textEdit.append('Третий канал отключен')
self.ui.pushButton_Ch3.setText('Включить')
if __name__ == "__main__":
APP = QtWidgets.QApplication(sys.argv)
MY_APP = Window()
MY_APP.show()
sys.exit(APP.exec_())