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.") print("Error: ISEG_TOKEN.txt file not found.")
token = None # Or assign a default value if needed token = None # Or assign a default value if needed
useInfluxDBv1 = True org = "FSUFoxLab"
databaseIP="192.168.1.193" databaseIP="https://fsunuc.physics.fsu.edu/influx/"
org = "" write_client = influxdb_client.InfluxDBClient(url=databaseIP, token=token, org=org)
bucket = "" bucket = "ISEG"
# write_api = write_client.write_api(write_options=ASYNCHRONOUS)
if useInfluxDBv1 == False : write_api = write_client.write_api(write_options=SYNCHRONOUS)
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) nArg = len(sys.argv)
@ -46,7 +43,7 @@ pushToDB = False
#============== assign a port, to prevent the script run mulitple time #============== assign a port, to prevent the script run mulitple time
s = socket.socket() s = socket.socket()
host = socket.gethostname() host = socket.gethostname()
port = 4300 + int(IP[-2:]) port = 4300 + int(IP[-3:])
print("using port " + str(port)) print("using port " + str(port))
s.bind((host,port)) s.bind((host,port))
@ -65,25 +62,20 @@ onOffList = mpod.GetAllOnOff()
modChList = iseg.SplitChList(chList) modChList = iseg.SplitChList(chList)
nMod = len(modChList) nMod = len(modChList)
modIndex = []
nChPerMod = [] nChPerMod = []
for k in range(0, nMod): for k in range(0, nMod):
modIndex.append(int(modChList[k][0]/100))
nChPerMod.append(len(modChList[k])) nChPerMod.append(len(modChList[k]))
nChannel = len(chList) nChannel = len(chList)
updateTime = 3 #sec updateTime = 3 #sec
# print("######")
# print(iList)
# print(onOffList) # print(onOffList)
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]"] ColStrList = ["Name", "Ch", 'On/Off', "Set V [V]", "Set I [mA]", "Out V [V]", "Out I [uA]"]
class MyWindow(QMainWindow): class MyWindow(QMainWindow):
def __init__(self): def __init__(self):
@ -125,7 +117,7 @@ class MyWindow(QMainWindow):
self.chkDB = QCheckBox("Enable", self) self.chkDB = QCheckBox("Enable", self)
gLayout.addWidget(self.chkDB, 0, 2) gLayout.addWidget(self.chkDB, 0, 2)
if token == None and useInfluxDBv1 == False: if token == None:
self.txtIP.setEnabled(False) self.txtIP.setEnabled(False)
self.chkDB.setEnabled(False) self.chkDB.setEnabled(False)
@ -152,7 +144,7 @@ class MyWindow(QMainWindow):
self.tabWidget = QTabWidget(self) self.tabWidget = QTabWidget(self)
layout.addWidget(self.tabWidget) 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) tab = QWidget(self)
layout_tab = QGridLayout() layout_tab = QGridLayout()
layout_tab.setAlignment(Qt.AlignmentFlag.AlignTop) layout_tab.setAlignment(Qt.AlignmentFlag.AlignTop)
@ -163,7 +155,7 @@ class MyWindow(QMainWindow):
layout_tab.addWidget(qlb, 0, index) layout_tab.addWidget(qlb, 0, index)
initRow = 1 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) : for j, lb in enumerate(ColStrList) :
#------------ name #------------ name
if j == 0: if j == 0:
@ -171,8 +163,7 @@ class MyWindow(QMainWindow):
#------------ Ch #------------ Ch
if j == 1: if j == 1:
# print(f"{a}, {k}, {a-100*k}") qlb = QLabel(str(a - 100*k), tab)
qlb = QLabel(str(a), tab)
layout_tab.addWidget(qlb, initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter) layout_tab.addWidget(qlb, initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter)
#------------ On/Off #------------ On/Off
@ -200,7 +191,7 @@ class MyWindow(QMainWindow):
#------------ I set #------------ I set
if j == 4: 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) self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
layout_tab.addWidget(self.txtI[k][i], initRow + i, j) 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].setReadOnly(True)
self.txtIOut[k][i].setStyleSheet("background-color: lightgrey;") 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 #============= Save setting
sLayout = QGridLayout() sLayout = QGridLayout()
@ -308,19 +299,19 @@ class MyWindow(QMainWindow):
self.timer.stop() self.timer.stop()
self.timer.start(int(sec * 1000)) self.timer.start(int(sec * 1000))
def SetHV(self, k, ch): def SetHV(self, mod, ch):
value = float(self.txtV[k][ch].text()) value = float(self.txtV[mod][ch].text())
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(value)) print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(value))
mpod.SetHV( modIndex[k]*100 + ch, value) mpod.SetHV( mod*100 + ch, value)
newValue = mpod.GetHV(modIndex[k]*100+ch) newValue = mpod.GetHV(mod*100+ch)
self.txtV[k][ch].setText("{:.1f}".format(newValue)) self.txtV[mod][ch].setText("{:.1f}".format(newValue))
def SetI(self, k, ch): def SetI(self, mod, ch):
value = float(self.txtI[k][ch].text()) value = float(self.txtI[mod][ch].text())
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(value)) print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(value))
mpod.SetCurrent( modIndex[k]*100 + ch, value/1e6) mpod.SetCurrent( mod*100 + ch, value/1000.)
newValue = mpod.GetCurrent(modIndex[k]*100+ch) * 1e6 newValue = mpod.GetCurrent(mod*100+ch) * 1000.
self.txtI[k][ch].setText("{:.2f}".format(newValue)) self.txtI[mod][ch].setText("{:.2f}".format(newValue))
def SwitchOnAllCh(self): def SwitchOnAllCh(self):
for k in range(0, nMod): for k in range(0, nMod):
@ -341,44 +332,44 @@ class MyWindow(QMainWindow):
state = self.chkON[k][ch].checkState() state = self.chkON[k][ch].checkState()
if state == Qt.CheckState.Checked: if state == Qt.CheckState.Checked:
print("Switching off Mod-%d, ch-%d" % (k, ch)) 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) self.chkON[k][ch].setChecked(False)
onOffList[sum(nChPerMod[:k]) + ch] = 0 onOffList[sum(nChPerMod[:k]) + ch] = 0
time.sleep(0.01) # wait 10 mili-sec time.sleep(0.01) # wait 10 mili-sec
print("========== done") print("========== done")
def SetOnOff(self, k, ch): def SetOnOff(self, mod, ch):
state = self.chkON[k][ch].checkState() state = self.chkON[mod][ch].checkState()
if state == Qt.CheckState.Checked: if state == Qt.CheckState.Checked:
if onOffList[sum(nChPerMod[:k]) + ch] == 3 : if onOffList[sum(nChPerMod[:mod]) + ch] == 3 :
mpod.SwitchOnHV(modIndex[k]*100 + ch, 2) mpod.SwitchOnHV(mod*100 + ch, 2)
mpod.SwitchOnHV( modIndex[k]*100 + ch, 1) mpod.SwitchOnHV( mod*100 + ch, 1)
onOffList[sum(nChPerMod[:k]) + ch] = 1 onOffList[sum(nChPerMod[:mod]) + ch] = 1
else: else:
mpod.SwitchOnHV( modIndex[k]*100 + ch, 0) mpod.SwitchOnHV( mod*100 + ch, 0)
onOffList[sum(nChPerMod[:k]) + ch] = 0 onOffList[sum(nChPerMod[:mod]) + ch] = 0
value = mpod.IsHVOn(modIndex[k]*100 + ch) value = mpod.IsHVOn(mod*100 + ch)
print("mod : " + str(modIndex[k]) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:k]) + ch]) + " | " + str(value)) print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:mod]) + ch]) + " | " + str(value))
if value == 0 : if value == 0 :
self.chkON[k][ch].setChecked(False) self.chkON[mod][ch].setChecked(False)
self.chkON[k][ch].setStyleSheet("") self.chkON[mod][ch].setStyleSheet("")
if value == 1 : if value == 1 :
self.chkON[k][ch].setChecked(True) self.chkON[mod][ch].setChecked(True)
self.chkON[k][ch].setStyleSheet("") self.chkON[mod][ch].setStyleSheet("")
if value == 3 : if value == 3 :
self.chkON[k][ch].setChecked(False) self.chkON[mod][ch].setChecked(False)
self.chkON[k][ch].setStyleSheet("background-color: red;") self.chkON[mod][ch].setStyleSheet("background-color: red;")
def updateTimer(self): def updateTimer(self):
# self.time += 1 # self.time += 1
# print(f'Time: {time.time()}') # print(f'Time: {self.time}')
outVList = mpod.GetAllOutputHV() outVList = mpod.GetAllOutputHV()
outIList = mpod.GetAllLC() outIList = mpod.GetAllLC()
# print(outVList) # print(outVList)
if self.chkDB.checkState() == Qt.CheckState.Checked and useInfluxDBv1 == False: if self.chkDB.checkState() == Qt.CheckState.Checked:
points = [] points = []
for k in range(0, nMod): for k in range(0, nMod):
@ -389,30 +380,13 @@ class MyWindow(QMainWindow):
self.txtVOut[k][i].setText("{:.2f}".format(vout)) self.txtVOut[k][i].setText("{:.2f}".format(vout))
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6)) self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
# print(f"{k}-{a},{vout:.2f}") if self.chkDB.checkState() == Qt.CheckState.Checked:
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("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]))) 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 : if 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 write_api.write(bucket=bucket, org=org, record=points)
os.system(DB_BashCommand_Mac)
if __name__ == "__main__": if __name__ == "__main__":
app = QApplication(sys.argv) app = QApplication(sys.argv)