Compare commits

..

No commits in common. "HELIOS" and "master" have entirely different histories.

View File

@ -20,15 +20,12 @@ except:
print("Error: ISEG_TOKEN.txt file not found.")
token = None # Or assign a default value if needed
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)
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)
nArg = len(sys.argv)
@ -46,7 +43,7 @@ pushToDB = False
#============== assign a port, to prevent the script run mulitple time
s = socket.socket()
host = socket.gethostname()
port = 4300 + int(IP[-2:])
port = 4300 + int(IP[-3:])
print("using port " + str(port))
s.bind((host,port))
@ -65,25 +62,20 @@ 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 [uA]", "Out V [V]", "Out I [uA]"]
ColStrList = ["Name", "Ch", 'On/Off', "Set V [V]", "Set I [mA]", "Out V [V]", "Out I [uA]"]
class MyWindow(QMainWindow):
def __init__(self):
@ -125,7 +117,7 @@ class MyWindow(QMainWindow):
self.chkDB = QCheckBox("Enable", self)
gLayout.addWidget(self.chkDB, 0, 2)
if token == None and useInfluxDBv1 == False:
if token == None:
self.txtIP.setEnabled(False)
self.chkDB.setEnabled(False)
@ -152,7 +144,7 @@ class MyWindow(QMainWindow):
self.tabWidget = QTabWidget(self)
layout.addWidget(self.tabWidget)
for k in range(0, nMod): # k is running from 0, 1, 2, ....
for k in range(0, nMod):
tab = QWidget(self)
layout_tab = QGridLayout()
layout_tab.setAlignment(Qt.AlignmentFlag.AlignTop)
@ -163,7 +155,7 @@ class MyWindow(QMainWindow):
layout_tab.addWidget(qlb, 0, index)
initRow = 1
for i, a in enumerate(modChList[k]) : # a is the channel ID
for i, a in enumerate(modChList[k]) :
for j, lb in enumerate(ColStrList) :
#------------ name
if j == 0:
@ -171,8 +163,7 @@ class MyWindow(QMainWindow):
#------------ Ch
if j == 1:
# print(f"{a}, {k}, {a-100*k}")
qlb = QLabel(str(a), tab)
qlb = QLabel(str(a - 100*k), tab)
layout_tab.addWidget(qlb, initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter)
#------------ On/Off
@ -200,7 +191,7 @@ class MyWindow(QMainWindow):
#------------ I set
if j == 4:
self.txtI[k][i].setText("{:.2f}".format(iList[sum(nChPerMod[:k]) + i]*1e6))
self.txtI[k][i].setText("{:.2f}".format(iList[sum(nChPerMod[:k]) + i]*1000))
self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
layout_tab.addWidget(self.txtI[k][i], initRow + i, j)
@ -224,7 +215,7 @@ class MyWindow(QMainWindow):
self.txtIOut[k][i].setReadOnly(True)
self.txtIOut[k][i].setStyleSheet("background-color: lightgrey;")
self.tabWidget.addTab(tab, "Mod-" + str(modIndex[k]))
self.tabWidget.addTab(tab, "Mod-" + str(k))
#============= Save setting
sLayout = QGridLayout()
@ -308,19 +299,19 @@ class MyWindow(QMainWindow):
self.timer.stop()
self.timer.start(int(sec * 1000))
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 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 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 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 SwitchOnAllCh(self):
for k in range(0, nMod):
@ -341,44 +332,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(modIndex[k]) * 100 + int(ch), 0)
mpod.SwitchOnHV( int(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, k, ch):
state = self.chkON[k][ch].checkState()
def SetOnOff(self, mod, ch):
state = self.chkON[mod][ch].checkState()
if state == Qt.CheckState.Checked:
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
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
else:
mpod.SwitchOnHV( modIndex[k]*100 + ch, 0)
onOffList[sum(nChPerMod[:k]) + ch] = 0
mpod.SwitchOnHV( mod*100 + ch, 0)
onOffList[sum(nChPerMod[:mod]) + ch] = 0
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))
value = mpod.IsHVOn(mod*100 + ch)
print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:mod]) + ch]) + " | " + str(value))
if value == 0 :
self.chkON[k][ch].setChecked(False)
self.chkON[k][ch].setStyleSheet("")
self.chkON[mod][ch].setChecked(False)
self.chkON[mod][ch].setStyleSheet("")
if value == 1 :
self.chkON[k][ch].setChecked(True)
self.chkON[k][ch].setStyleSheet("")
self.chkON[mod][ch].setChecked(True)
self.chkON[mod][ch].setStyleSheet("")
if value == 3 :
self.chkON[k][ch].setChecked(False)
self.chkON[k][ch].setStyleSheet("background-color: red;")
self.chkON[mod][ch].setChecked(False)
self.chkON[mod][ch].setStyleSheet("background-color: red;")
def updateTimer(self):
# self.time += 1
# print(f'Time: {time.time()}')
# print(f'Time: {self.time}')
outVList = mpod.GetAllOutputHV()
outIList = mpod.GetAllLC()
# print(outVList)
if self.chkDB.checkState() == Qt.CheckState.Checked and useInfluxDBv1 == False:
if self.chkDB.checkState() == Qt.CheckState.Checked:
points = []
for k in range(0, nMod):
@ -389,30 +380,13 @@ class MyWindow(QMainWindow):
self.txtVOut[k][i].setText("{:.2f}".format(vout))
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
# print(f"{k}-{a},{vout:.2f}")
if useInfluxDBv1 == False and self.chkDB.checkState() == Qt.CheckState.Checked :
if 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 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)
if self.chkDB.checkState() == Qt.CheckState.Checked:
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)
write_api.write(bucket=bucket, org=org, record=points)
if __name__ == "__main__":
app = QApplication(sys.argv)