Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
961941bbc9 | ||
|
c977498afc |
122
IsegGUI.py
122
IsegGUI.py
|
@ -20,12 +20,15 @@ except:
|
|||
print("Error: ISEG_TOKEN.txt file not found.")
|
||||
token = None # Or assign a default value if needed
|
||||
|
||||
org = "FSUFoxLab"
|
||||
databaseIP="https://fsunuc.physics.fsu.edu/influx/"
|
||||
write_client = influxdb_client.InfluxDBClient(url=databaseIP, token=token, org=org)
|
||||
bucket = "ISEG"
|
||||
# write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
||||
write_api = write_client.write_api(write_options=SYNCHRONOUS)
|
||||
useInfluxDBv1 = True
|
||||
databaseIP="192.168.1.193"
|
||||
org = ""
|
||||
bucket = ""
|
||||
|
||||
if useInfluxDBv1 == False :
|
||||
write_client = influxdb_client.InfluxDBClient(url=databaseIP, token=token, org=org)
|
||||
# write_api = write_client.write_api(write_options=ASYNCHRONOUS)
|
||||
write_api = write_client.write_api(write_options=SYNCHRONOUS)
|
||||
|
||||
nArg = len(sys.argv)
|
||||
|
||||
|
@ -43,7 +46,7 @@ pushToDB = False
|
|||
#============== assign a port, to prevent the script run mulitple time
|
||||
s = socket.socket()
|
||||
host = socket.gethostname()
|
||||
port = 4300 + int(IP[-3:])
|
||||
port = 4300 + int(IP[-2:])
|
||||
print("using port " + str(port))
|
||||
s.bind((host,port))
|
||||
|
||||
|
@ -62,20 +65,25 @@ onOffList = mpod.GetAllOnOff()
|
|||
|
||||
modChList = iseg.SplitChList(chList)
|
||||
|
||||
|
||||
nMod = len(modChList)
|
||||
modIndex = []
|
||||
nChPerMod = []
|
||||
for k in range(0, nMod):
|
||||
modIndex.append(int(modChList[k][0]/100))
|
||||
nChPerMod.append(len(modChList[k]))
|
||||
nChannel = len(chList)
|
||||
updateTime = 3 #sec
|
||||
|
||||
# print("######")
|
||||
# print(iList)
|
||||
# print(onOffList)
|
||||
|
||||
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 functools import partial
|
||||
|
||||
ColStrList = ["Name", "Ch", 'On/Off', "Set V [V]", "Set I [mA]", "Out V [V]", "Out I [uA]"]
|
||||
ColStrList = ["Name", "Ch", 'On/Off', "Set V [V]", "Set I [uA]", "Out V [V]", "Out I [uA]"]
|
||||
|
||||
class MyWindow(QMainWindow):
|
||||
def __init__(self):
|
||||
|
@ -117,7 +125,7 @@ class MyWindow(QMainWindow):
|
|||
|
||||
self.chkDB = QCheckBox("Enable", self)
|
||||
gLayout.addWidget(self.chkDB, 0, 2)
|
||||
if token == None:
|
||||
if token == None and useInfluxDBv1 == False:
|
||||
self.txtIP.setEnabled(False)
|
||||
self.chkDB.setEnabled(False)
|
||||
|
||||
|
@ -144,7 +152,7 @@ class MyWindow(QMainWindow):
|
|||
self.tabWidget = QTabWidget(self)
|
||||
layout.addWidget(self.tabWidget)
|
||||
|
||||
for k in range(0, nMod):
|
||||
for k in range(0, nMod): # k is running from 0, 1, 2, ....
|
||||
tab = QWidget(self)
|
||||
layout_tab = QGridLayout()
|
||||
layout_tab.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
|
@ -155,7 +163,7 @@ class MyWindow(QMainWindow):
|
|||
layout_tab.addWidget(qlb, 0, index)
|
||||
|
||||
initRow = 1
|
||||
for i, a in enumerate(modChList[k]) :
|
||||
for i, a in enumerate(modChList[k]) : # a is the channel ID
|
||||
for j, lb in enumerate(ColStrList) :
|
||||
#------------ name
|
||||
if j == 0:
|
||||
|
@ -163,7 +171,8 @@ class MyWindow(QMainWindow):
|
|||
|
||||
#------------ Ch
|
||||
if j == 1:
|
||||
qlb = QLabel(str(a - 100*k), tab)
|
||||
# print(f"{a}, {k}, {a-100*k}")
|
||||
qlb = QLabel(str(a), tab)
|
||||
layout_tab.addWidget(qlb, initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||
|
||||
#------------ On/Off
|
||||
|
@ -191,7 +200,7 @@ class MyWindow(QMainWindow):
|
|||
|
||||
#------------ I set
|
||||
if j == 4:
|
||||
self.txtI[k][i].setText("{:.2f}".format(iList[sum(nChPerMod[:k]) + i]*1000))
|
||||
self.txtI[k][i].setText("{:.2f}".format(iList[sum(nChPerMod[:k]) + i]*1e6))
|
||||
self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||
layout_tab.addWidget(self.txtI[k][i], initRow + i, j)
|
||||
|
||||
|
@ -215,7 +224,7 @@ class MyWindow(QMainWindow):
|
|||
self.txtIOut[k][i].setReadOnly(True)
|
||||
self.txtIOut[k][i].setStyleSheet("background-color: lightgrey;")
|
||||
|
||||
self.tabWidget.addTab(tab, "Mod-" + str(k))
|
||||
self.tabWidget.addTab(tab, "Mod-" + str(modIndex[k]))
|
||||
|
||||
#============= Save setting
|
||||
sLayout = QGridLayout()
|
||||
|
@ -299,19 +308,19 @@ class MyWindow(QMainWindow):
|
|||
self.timer.stop()
|
||||
self.timer.start(int(sec * 1000))
|
||||
|
||||
def SetHV(self, mod, ch):
|
||||
value = float(self.txtV[mod][ch].text())
|
||||
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(value))
|
||||
mpod.SetHV( mod*100 + ch, value)
|
||||
newValue = mpod.GetHV(mod*100+ch)
|
||||
self.txtV[mod][ch].setText("{:.1f}".format(newValue))
|
||||
def SetHV(self, k, ch):
|
||||
value = float(self.txtV[k][ch].text())
|
||||
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(value))
|
||||
mpod.SetHV( modIndex[k]*100 + ch, value)
|
||||
newValue = mpod.GetHV(modIndex[k]*100+ch)
|
||||
self.txtV[k][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))
|
||||
mpod.SetCurrent( mod*100 + ch, value/1000.)
|
||||
newValue = mpod.GetCurrent(mod*100+ch) * 1000.
|
||||
self.txtI[mod][ch].setText("{:.2f}".format(newValue))
|
||||
def SetI(self, k, ch):
|
||||
value = float(self.txtI[k][ch].text())
|
||||
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(value))
|
||||
mpod.SetCurrent( modIndex[k]*100 + ch, value/1e6)
|
||||
newValue = mpod.GetCurrent(modIndex[k]*100+ch) * 1e6
|
||||
self.txtI[k][ch].setText("{:.2f}".format(newValue))
|
||||
|
||||
def SwitchOnAllCh(self):
|
||||
for k in range(0, nMod):
|
||||
|
@ -332,44 +341,44 @@ class MyWindow(QMainWindow):
|
|||
state = self.chkON[k][ch].checkState()
|
||||
if state == Qt.CheckState.Checked:
|
||||
print("Switching off Mod-%d, ch-%d" % (k, ch))
|
||||
mpod.SwitchOnHV( int(k) * 100 + int(ch), 0)
|
||||
mpod.SwitchOnHV( int(modIndex[k]) * 100 + int(ch), 0)
|
||||
self.chkON[k][ch].setChecked(False)
|
||||
onOffList[sum(nChPerMod[:k]) + ch] = 0
|
||||
time.sleep(0.01) # wait 10 mili-sec
|
||||
|
||||
print("========== done")
|
||||
|
||||
def SetOnOff(self, mod, ch):
|
||||
state = self.chkON[mod][ch].checkState()
|
||||
def SetOnOff(self, k, ch):
|
||||
state = self.chkON[k][ch].checkState()
|
||||
if state == Qt.CheckState.Checked:
|
||||
if onOffList[sum(nChPerMod[:mod]) + ch] == 3 :
|
||||
mpod.SwitchOnHV(mod*100 + ch, 2)
|
||||
mpod.SwitchOnHV( mod*100 + ch, 1)
|
||||
onOffList[sum(nChPerMod[:mod]) + ch] = 1
|
||||
if onOffList[sum(nChPerMod[:k]) + ch] == 3 :
|
||||
mpod.SwitchOnHV(modIndex[k]*100 + ch, 2)
|
||||
mpod.SwitchOnHV( modIndex[k]*100 + ch, 1)
|
||||
onOffList[sum(nChPerMod[:k]) + ch] = 1
|
||||
else:
|
||||
mpod.SwitchOnHV( mod*100 + ch, 0)
|
||||
onOffList[sum(nChPerMod[:mod]) + ch] = 0
|
||||
mpod.SwitchOnHV( modIndex[k]*100 + ch, 0)
|
||||
onOffList[sum(nChPerMod[:k]) + ch] = 0
|
||||
|
||||
value = mpod.IsHVOn(mod*100 + ch)
|
||||
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:mod]) + ch]) + " | " + str(value))
|
||||
value = mpod.IsHVOn(modIndex[k]*100 + ch)
|
||||
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:k]) + ch]) + " | " + str(value))
|
||||
if value == 0 :
|
||||
self.chkON[mod][ch].setChecked(False)
|
||||
self.chkON[mod][ch].setStyleSheet("")
|
||||
self.chkON[k][ch].setChecked(False)
|
||||
self.chkON[k][ch].setStyleSheet("")
|
||||
if value == 1 :
|
||||
self.chkON[mod][ch].setChecked(True)
|
||||
self.chkON[mod][ch].setStyleSheet("")
|
||||
self.chkON[k][ch].setChecked(True)
|
||||
self.chkON[k][ch].setStyleSheet("")
|
||||
if value == 3 :
|
||||
self.chkON[mod][ch].setChecked(False)
|
||||
self.chkON[mod][ch].setStyleSheet("background-color: red;")
|
||||
self.chkON[k][ch].setChecked(False)
|
||||
self.chkON[k][ch].setStyleSheet("background-color: red;")
|
||||
|
||||
def updateTimer(self):
|
||||
# self.time += 1
|
||||
# print(f'Time: {self.time}')
|
||||
# print(f'Time: {time.time()}')
|
||||
outVList = mpod.GetAllOutputHV()
|
||||
outIList = mpod.GetAllLC()
|
||||
# print(outVList)
|
||||
|
||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||
if self.chkDB.checkState() == Qt.CheckState.Checked and useInfluxDBv1 == False:
|
||||
points = []
|
||||
|
||||
for k in range(0, nMod):
|
||||
|
@ -380,14 +389,31 @@ class MyWindow(QMainWindow):
|
|||
self.txtVOut[k][i].setText("{:.2f}".format(vout))
|
||||
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
|
||||
|
||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||
# print(f"{k}-{a},{vout:.2f}")
|
||||
|
||||
if useInfluxDBv1 == False and self.chkDB.checkState() == Qt.CheckState.Checked :
|
||||
points.append(Point("Voltage").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outVList[sum(nChPerMod[:k]) + i])))
|
||||
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outIList[sum(nChPerMod[:k]) + i])))
|
||||
|
||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||
|
||||
if useInfluxDBv1 == False and self.chkDB.checkState() == Qt.CheckState.Checked :
|
||||
write_api.write(bucket=bucket, org=org, record=points)
|
||||
|
||||
if useInfluxDBv1 == True and self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||
print("pushing data to influxDB")
|
||||
with open("output.txt", "w") as f:
|
||||
for i, ch in enumerate(chList):
|
||||
det = ch % 100
|
||||
module = ch // 100
|
||||
line = f"HV,Det={det},Module={module} value={outVList[i]:.3f}\n"
|
||||
f.write(line)
|
||||
line = f"LC,Det={det},Module={module} value={outIList[i]*1e6:.3f}\n"
|
||||
f.write(line)
|
||||
|
||||
DB_BashCommand_Mac='curl -sS -i -XPOST "http://%s:8086/write?db=testing" --data-binary @output.txt --speed-time 5 --speed-limit 1000' % databaseIP
|
||||
os.system(DB_BashCommand_Mac)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = MyWindow()
|
||||
|
|
Loading…
Reference in New Issue
Block a user