half done. Don't know why cannot switch power on, and Pw has memeory, not the actual value
This commit is contained in:
parent
4649664b55
commit
760e2387d7
192
HVGUI.py
192
HVGUI.py
|
@ -2,8 +2,200 @@
|
||||||
|
|
||||||
import HVLibrary as hv
|
import HVLibrary as hv
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QCheckBox, QLineEdit, QLabel, QVBoxLayout, QWidget, QTabWidget, QGridLayout, QMessageBox, QFileDialog, QProgressBar
|
from PyQt6.QtWidgets import QApplication, QMainWindow, QPushButton, QCheckBox, QLineEdit, QLabel, QVBoxLayout, QWidget, QTabWidget, QGridLayout, QMessageBox, QFileDialog, QProgressBar
|
||||||
from PyQt6.QtCore import Qt, QThread, QTimer, QObject, pyqtSignal
|
from PyQt6.QtCore import Qt, QThread, QTimer, QObject, pyqtSignal
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
ColStrList = ["Name", "Ch", 'On/Off', "Set V [V]", "Set I [uA]", "Out V [V]", "Out I [uA]"]
|
||||||
|
|
||||||
|
nMod = 2
|
||||||
|
nChPerMod = [48, 48]
|
||||||
|
updateTime = 3 #sec
|
||||||
|
|
||||||
|
bd = []
|
||||||
|
for k in range(nMod):
|
||||||
|
bd.append(hv.Board(3 + k))
|
||||||
|
|
||||||
|
|
||||||
|
V0SetList = []
|
||||||
|
I0SetList = []
|
||||||
|
OnOffList = []
|
||||||
|
outVList = []
|
||||||
|
outIList = []
|
||||||
|
|
||||||
|
for k in range(nMod):
|
||||||
|
V0SetList.append(bd[k].GetPV('V0Set'))
|
||||||
|
I0SetList.append(bd[k].GetPV('I0Set'))
|
||||||
|
OnOffList.append(bd[k].GetPV('Pw'))
|
||||||
|
outVList.append(bd[k].GetPV('VMon'))
|
||||||
|
outIList.append(bd[k].GetPV('IMon'))
|
||||||
|
|
||||||
|
class MyWindow(QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.setWindowTitle("Iseg Controller")
|
||||||
|
self.setGeometry(100, 100, 500, 200)
|
||||||
|
|
||||||
|
widget = QWidget()
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
widget.setLayout(layout)
|
||||||
|
self.setCentralWidget(widget)
|
||||||
|
|
||||||
|
self.txtName = [[QLineEdit() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
self.txtV = [[QLineEdit() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
self.txtI = [[QLineEdit() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
self.txtVOut = [[QLineEdit() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
self.txtIOut = [[QLineEdit() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
self.chkON = [[QCheckBox() for _ in range(rows)] for rows in nChPerMod]
|
||||||
|
|
||||||
|
self.timer = QTimer(self)
|
||||||
|
self.timer.timeout.connect(self.updateTimer)
|
||||||
|
self.timer.start(updateTime*1000)
|
||||||
|
self.time = 0
|
||||||
|
|
||||||
|
#=========== set tab
|
||||||
|
self.tabWidget = QTabWidget(self)
|
||||||
|
layout.addWidget(self.tabWidget)
|
||||||
|
|
||||||
|
for k in range(0, nMod):
|
||||||
|
tab = QWidget(self)
|
||||||
|
layout_tab = QGridLayout()
|
||||||
|
layout_tab.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||||
|
tab.setLayout(layout_tab)
|
||||||
|
|
||||||
|
for index, lb in enumerate(ColStrList):
|
||||||
|
qlb = QLabel(lb, tab)
|
||||||
|
layout_tab.addWidget(qlb, 0, index)
|
||||||
|
|
||||||
|
for i in range(nChPerMod[k]) :
|
||||||
|
for j, lb in enumerate(ColStrList) :
|
||||||
|
#------------ name
|
||||||
|
if j == 0:
|
||||||
|
layout_tab.addWidget(self.txtName[k][i], 1+i, j)
|
||||||
|
|
||||||
|
#------------ Ch
|
||||||
|
if j == 1:
|
||||||
|
qlb = QLabel(str(i), tab)
|
||||||
|
layout_tab.addWidget(qlb, 1+i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
|
#------------ On/Off
|
||||||
|
if j == 2:
|
||||||
|
self.chkON[k][i].setChecked( OnOffList[k][i] == 1)
|
||||||
|
layout_tab.addWidget(self.chkON[k][i], 1+i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
|
self.chkON[k][i].clicked.connect(partial(self.SetOnOff, k, i))
|
||||||
|
|
||||||
|
# #------------ V set
|
||||||
|
if j == 3:
|
||||||
|
self.txtV[k][i].setText(str(V0SetList[k][i]))
|
||||||
|
self.txtV[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
layout_tab.addWidget(self.txtV[k][i], 1+i, j)
|
||||||
|
|
||||||
|
self.txtV[k][i].returnPressed.connect(partial(self.SetHV, k, i) )
|
||||||
|
self.txtV[k][i].returnPressed.connect(partial(self.UnSetTextColor, self.txtV[k][i]))
|
||||||
|
self.txtV[k][i].textChanged.connect(partial(self.TextChange, self.txtV[k][i]))
|
||||||
|
|
||||||
|
# #------------ I set
|
||||||
|
if j == 4:
|
||||||
|
self.txtI[k][i].setText(str(I0SetList[k][i]))
|
||||||
|
self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
layout_tab.addWidget(self.txtI[k][i], 1+i, j)
|
||||||
|
|
||||||
|
self.txtI[k][i].returnPressed.connect(partial(self.SetI, k, i) )
|
||||||
|
self.txtI[k][i].returnPressed.connect(partial(self.UnSetTextColor, self.txtI[k][i]))
|
||||||
|
self.txtI[k][i].textChanged.connect(partial(self.TextChange, self.txtI[k][i]))
|
||||||
|
|
||||||
|
# #------------ V out
|
||||||
|
if j == 5:
|
||||||
|
self.txtVOut[k][i].setText("{:.2f}".format(outVList[k][i]))
|
||||||
|
self.txtVOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
layout_tab.addWidget(self.txtVOut[k][i], 1+i, j)
|
||||||
|
self.txtVOut[k][i].setReadOnly(True)
|
||||||
|
self.txtVOut[k][i].setStyleSheet("background-color: lightgrey; color: black;")
|
||||||
|
|
||||||
|
# #------------ I out
|
||||||
|
if j == 6:
|
||||||
|
self.txtIOut[k][i].setText("{:.2f}".format(outIList[k][i]))
|
||||||
|
self.txtIOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
layout_tab.addWidget(self.txtIOut[k][i], 1+i, j)
|
||||||
|
self.txtIOut[k][i].setReadOnly(True)
|
||||||
|
self.txtIOut[k][i].setStyleSheet("background-color: lightgrey; color: black;")
|
||||||
|
|
||||||
|
self.tabWidget.addTab(tab, "Mod-" + str(k))
|
||||||
|
|
||||||
|
|
||||||
|
#=================================
|
||||||
|
def UnSetTextColor(self, qLineEdit : QLineEdit):
|
||||||
|
qLineEdit.setStyleSheet("")
|
||||||
|
|
||||||
|
def TextChange(self, qLineEdit : QLineEdit):
|
||||||
|
qLineEdit.setStyleSheet("color : darkgreen;")
|
||||||
|
|
||||||
|
#---------------------------------
|
||||||
|
def SetOnOff(self, mod, ch):
|
||||||
|
state = self.chkON[mod][ch].checkState()
|
||||||
|
if state == Qt.CheckState.Checked:
|
||||||
|
bd[mod].Channel[ch].SetPowerOnOff(1)
|
||||||
|
else:
|
||||||
|
bd[mod].Channel[ch].SetPowerOnOff(0)
|
||||||
|
|
||||||
|
value = bd[mod].Channel[ch].GetPowerOnOff()
|
||||||
|
OnOffList[mod][ch] = value
|
||||||
|
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(value))
|
||||||
|
self.chkON[mod][ch].setChecked(value == 1)
|
||||||
|
|
||||||
|
#---------------------------------
|
||||||
|
def SetHV(self, mod, ch):
|
||||||
|
value = float(self.txtV[mod][ch].text())
|
||||||
|
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(value))
|
||||||
|
bd[mod].Channel[ch].SetV0Set(value)
|
||||||
|
newValue = bd[mod].Channel[ch].GetV0Set()
|
||||||
|
V0SetList[mod][ch] = newValue
|
||||||
|
self.txtV[mod][ch].setText("{:.1f}".format(newValue))
|
||||||
|
|
||||||
|
#---------------------------------
|
||||||
|
def SetI(self, mod, ch):
|
||||||
|
value = float(self.txtI[mod][ch].text())
|
||||||
|
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(value))
|
||||||
|
bd[mod].Channel[ch].SetI0Set(value)
|
||||||
|
newValue = bd[mod].Channel[ch].GetI0Set()
|
||||||
|
I0SetList[mod][ch] = newValue
|
||||||
|
self.txtI[mod][ch].setText("{:.1f}".format(newValue))
|
||||||
|
|
||||||
|
#---------------------------------
|
||||||
|
def updateTimer(self):
|
||||||
|
self.time += 1
|
||||||
|
print(f'Time: {self.time}')
|
||||||
|
# outVList = mpod.GetAllOutputHV()
|
||||||
|
# outIList = mpod.GetAllLC()
|
||||||
|
# # print(outVList)
|
||||||
|
|
||||||
|
for k in range(2):
|
||||||
|
outVList.append(bd[k].GetPV('VMon'))
|
||||||
|
outIList.append(bd[k].GetPV('IMon'))
|
||||||
|
|
||||||
|
# if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||||
|
# points = []
|
||||||
|
|
||||||
|
for k in range(0, nMod):
|
||||||
|
for i in range(bd[k].numCh) :
|
||||||
|
self.txtVOut[k][i].setText("{:.2f}".format(outVList[k][i]))
|
||||||
|
self.txtIOut[k][i].setText("{:.2f}".format(outIList[k][i]))
|
||||||
|
|
||||||
|
# if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||||
|
# points.append(Point("Voltage").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outVList[i])))
|
||||||
|
# points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outIList[i])))
|
||||||
|
|
||||||
|
# if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||||
|
# write_api.write(bucket=bucket, org=org, record=points)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
window = MyWindow()
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec())
|
24
HVLibrary.py
24
HVLibrary.py
|
@ -29,9 +29,9 @@ def get_value(pv_name : str, show : bool = False):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def set_value(pv_name : str, value):
|
def set_value(pv_name : str, value) -> None:
|
||||||
pv = epics.PV(hostName + ":" + pv_name, connection_timeout=0.1)
|
pv = epics.PV(hostName + ":" + pv_name, connection_timeout=0.1)
|
||||||
return pv.put(value)
|
pv.put(value)
|
||||||
|
|
||||||
|
|
||||||
#======= general
|
#======= general
|
||||||
|
@ -88,7 +88,7 @@ class Channel:
|
||||||
def GetStatus(self) -> str:
|
def GetStatus(self) -> str:
|
||||||
return get_value(self.bdCh + "Status")
|
return get_value(self.bdCh + "Status")
|
||||||
|
|
||||||
def GetPowerOnOff(self) -> str:
|
def GetPowerOnOff(self) -> int:
|
||||||
return get_value(self.bdCh + "Pw")
|
return get_value(self.bdCh + "Pw")
|
||||||
|
|
||||||
def GetPowerOnOption(self) -> str:
|
def GetPowerOnOption(self) -> str:
|
||||||
|
@ -122,14 +122,14 @@ class Channel:
|
||||||
def SetMaxVoltage(self, volt: float):
|
def SetMaxVoltage(self, volt: float):
|
||||||
set_value(self.bdCh + "SVMax", volt)
|
set_value(self.bdCh + "SVMax", volt)
|
||||||
|
|
||||||
def GetPowerOnOff(self, onOff : bool): # off = 0, on = 1
|
def SetPowerOnOff(self, onOff): # off = 0, on = 1
|
||||||
return get_value(self.bdCh + "Pw", onOff)
|
set_value(self.bdCh + "Pw", onOff)
|
||||||
|
|
||||||
def GetPowerOnOption(self, disEn : bool): #disable = 0, enable = 1, if enable, restart will restore in same condition
|
def SetPowerOnOption(self, disEn : bool): #disable = 0, enable = 1, if enable, restart will restore in same condition
|
||||||
return get_value(self.bdCh + "POn", disEn)
|
set_value(self.bdCh + "POn", disEn)
|
||||||
|
|
||||||
def GetPowerDownOptionWhenTrip(self, killRamp) : # kill = 0, Ramp = 1
|
def SetPowerDownOptionWhenTrip(self, killRamp) : # kill = 0, Ramp = 1
|
||||||
return get_value(self.bdCh + "PDwn", killRamp)
|
set_value(self.bdCh + "PDwn", killRamp)
|
||||||
|
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
|
@ -158,3 +158,9 @@ class Board:
|
||||||
|
|
||||||
def GetTemp(self) -> float:
|
def GetTemp(self) -> float:
|
||||||
return get_value(self.id + ":" + 'Temp')
|
return get_value(self.id + ":" + 'Temp')
|
||||||
|
|
||||||
|
def GetPV(self, PV_Name : str):
|
||||||
|
pvList = []
|
||||||
|
for i in range(48):
|
||||||
|
pvList.append('solarisHV:' + self.id + ":" + f"{i:03d}" + ":" + PV_Name)
|
||||||
|
return epics.caget_many(pvList)
|
||||||
|
|
69
test.py
69
test.py
|
@ -2,17 +2,74 @@
|
||||||
|
|
||||||
import HVLibrary as hv
|
import HVLibrary as hv
|
||||||
|
|
||||||
#set_value('03:000:' + Ch_PV_List[1], 5)
|
# hv.get_value('03:000:' + hv.Ch_PV_List[1])
|
||||||
#hv.get_value('03:000:' + hv.Ch_PV_List[1])
|
# hv.get_value('03:000:' + hv.Ch_PV_List[0])
|
||||||
#hv.get_value('03:000:' + hv.Ch_PV_List[0])
|
|
||||||
|
|
||||||
# index = 14
|
# index = 14
|
||||||
# hv.get_value('03:000:' + hv.Ch_PV_List[index], True)
|
# hv.get_value('03:000:' + hv.Ch_PV_List[index], True)
|
||||||
# cf = hv.get_CtrlField('03:000:' + hv.Ch_PV_List[index])
|
# cf = hv.get_CtrlField('03:000:' + hv.Ch_PV_List[index])
|
||||||
# print(cf)
|
# print(cf)
|
||||||
|
|
||||||
bd = hv.Board(3)
|
# bd = []
|
||||||
|
|
||||||
print( bd.GetTemp())
|
# for k in range(2):
|
||||||
|
# bd.append(hv.Board(3 + k))
|
||||||
|
|
||||||
print( bd.Channel[0].GetName() )
|
# print( bd[0].GetTemp())
|
||||||
|
# print( bd[0].Channel[15].GetName() )
|
||||||
|
|
||||||
|
# bd[0].Channel[15].SetPowerOnOff(1)
|
||||||
|
|
||||||
|
# print(bd[0].Channel[15].GetPowerOnOff())
|
||||||
|
|
||||||
|
# print(bd[0].Channel[15].GetVMon())
|
||||||
|
|
||||||
|
# print(bd[0].Channel[15].GetPowerOnOff())
|
||||||
|
# for k in range(2):
|
||||||
|
# print("==========================")
|
||||||
|
# for i in range(bd[k].numCh):
|
||||||
|
# print("{:.2f}".format(bd[k].Channel[i].GetVMon()))
|
||||||
|
|
||||||
|
|
||||||
|
# hv.set_value('03:015:Pw', 1)
|
||||||
|
|
||||||
|
# haha = hv.get_value('03:015:Status')
|
||||||
|
# print(haha)
|
||||||
|
|
||||||
|
# haha = hv.get_value('03:015:Pw')
|
||||||
|
# print(haha)
|
||||||
|
|
||||||
|
# haha = hv.get_value('03:015:V0Set')
|
||||||
|
# print(haha)
|
||||||
|
|
||||||
|
# haha = hv.get_value('03:015:VMon')
|
||||||
|
# print(haha)
|
||||||
|
|
||||||
|
|
||||||
|
# haha = hv.get_value('03:BdStatus')
|
||||||
|
# print(haha)
|
||||||
|
|
||||||
|
# hv.epics.caput('solarisHV:03:015:Pw', 1)
|
||||||
|
|
||||||
|
# hv.epics.cainfo('solarisHV:03:015:Pw')
|
||||||
|
|
||||||
|
|
||||||
|
# m1 = hv.epics.caget('solarisHV:03:015:Pw', use_monitor= False)
|
||||||
|
# print(m1)
|
||||||
|
|
||||||
|
# m1 = hv.epics.caget('solarisHV:03:015:VMon')
|
||||||
|
# print(m1)
|
||||||
|
|
||||||
|
|
||||||
|
# m1 = hv.epics.caget('solarisHV:03:015:Pw')
|
||||||
|
# print(m1)
|
||||||
|
|
||||||
|
# hv.epics.camonitor('solarisHV:03:015:Pw')
|
||||||
|
|
||||||
|
pvList = []
|
||||||
|
for i in range(48):
|
||||||
|
pvList.append('solarisHV:03:' + f"{i:03d}" + ":VMon")
|
||||||
|
|
||||||
|
haha = hv.epics.caget_many(pvList)
|
||||||
|
|
||||||
|
print(haha)
|
Loading…
Reference in New Issue
Block a user