add button to switch off all channels; add some fault proof
This commit is contained in:
parent
87182cebd2
commit
190627b913
55
IsegGUI.py
55
IsegGUI.py
|
@ -13,8 +13,12 @@ from influxdb_client import InfluxDBClient, Point, WritePrecision
|
||||||
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
||||||
|
|
||||||
#------ database
|
#------ database
|
||||||
|
try:
|
||||||
with open('ISEG_TOKEN.txt', 'r') as f:
|
with open('ISEG_TOKEN.txt', 'r') as f:
|
||||||
token = f.readline().replace('\n', '')
|
token = f.readline()
|
||||||
|
except:
|
||||||
|
print("Error: ISEG_TOKEN.txt file not found.")
|
||||||
|
token = None # Or assign a default value if needed
|
||||||
|
|
||||||
org = "FSUFoxLab"
|
org = "FSUFoxLab"
|
||||||
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
||||||
|
@ -111,7 +115,9 @@ 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:
|
||||||
|
self.txtIP.setEnabled(False)
|
||||||
|
self.chkDB.setEnabled(False)
|
||||||
|
|
||||||
lb1 = QLabel("Refresh period [sec] :", self)
|
lb1 = QLabel("Refresh period [sec] :", self)
|
||||||
lb1.setAlignment(Qt.AlignmentFlag.AlignRight)
|
lb1.setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
|
@ -124,6 +130,10 @@ class MyWindow(QMainWindow):
|
||||||
self.txtRefresh.returnPressed.connect(partial(self.UnSetTextColor, self.txtRefresh))
|
self.txtRefresh.returnPressed.connect(partial(self.UnSetTextColor, self.txtRefresh))
|
||||||
gLayout.addWidget(self.txtRefresh, 1, 1)
|
gLayout.addWidget(self.txtRefresh, 1, 1)
|
||||||
|
|
||||||
|
self.AllChkOff = QPushButton("Switch all channels off.")
|
||||||
|
gLayout.addWidget(self.AllChkOff, 2, 1)
|
||||||
|
self.AllChkOff.clicked.connect(partial(self.SetAllOnOff))
|
||||||
|
|
||||||
#=========== set tab
|
#=========== set tab
|
||||||
self.tabWidget = QTabWidget(self)
|
self.tabWidget = QTabWidget(self)
|
||||||
layout.addWidget(self.tabWidget)
|
layout.addWidget(self.tabWidget)
|
||||||
|
@ -138,16 +148,17 @@ class MyWindow(QMainWindow):
|
||||||
qlb = QLabel(lb, tab)
|
qlb = QLabel(lb, tab)
|
||||||
layout_tab.addWidget(qlb, 0, index)
|
layout_tab.addWidget(qlb, 0, index)
|
||||||
|
|
||||||
|
initRow = 1
|
||||||
for i, a in enumerate(modChList[k]) :
|
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:
|
||||||
layout_tab.addWidget(self.txtName[k][i], 1+i, j)
|
layout_tab.addWidget(self.txtName[k][i], initRow + i, j)
|
||||||
|
|
||||||
#------------ Ch
|
#------------ Ch
|
||||||
if j == 1:
|
if j == 1:
|
||||||
qlb = QLabel(str(a - 100*k), tab)
|
qlb = QLabel(str(a - 100*k), tab)
|
||||||
layout_tab.addWidget(qlb, 1+i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
layout_tab.addWidget(qlb, initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
#------------ On/Off
|
#------------ On/Off
|
||||||
if j == 2:
|
if j == 2:
|
||||||
|
@ -159,14 +170,14 @@ class MyWindow(QMainWindow):
|
||||||
self.chkON[k][i].setChecked(False)
|
self.chkON[k][i].setChecked(False)
|
||||||
self.chkON[k][i].setStyleSheet("background-color: red;")
|
self.chkON[k][i].setStyleSheet("background-color: red;")
|
||||||
|
|
||||||
layout_tab.addWidget(self.chkON[k][i], 1+i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
layout_tab.addWidget(self.chkON[k][i], initRow + i, j, alignment=Qt.AlignmentFlag.AlignCenter)
|
||||||
|
|
||||||
self.chkON[k][i].clicked.connect(partial(self.SetOnOff, k, i))
|
self.chkON[k][i].clicked.connect(partial(self.SetOnOff, k, i))
|
||||||
#------------ V set
|
#------------ V set
|
||||||
if j == 3:
|
if j == 3:
|
||||||
self.txtV[k][i].setText(str(hvList[sum(nChPerMod[:k]) + i]))
|
self.txtV[k][i].setText(str(hvList[sum(nChPerMod[:k]) + i]))
|
||||||
self.txtV[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
self.txtV[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
layout_tab.addWidget(self.txtV[k][i], 1+i, j)
|
layout_tab.addWidget(self.txtV[k][i], initRow + i, j)
|
||||||
|
|
||||||
self.txtV[k][i].returnPressed.connect(partial(self.SetHV, k, i) )
|
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].returnPressed.connect(partial(self.UnSetTextColor, self.txtV[k][i]))
|
||||||
|
@ -176,7 +187,7 @@ class MyWindow(QMainWindow):
|
||||||
if j == 4:
|
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]*1000))
|
||||||
self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
self.txtI[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
layout_tab.addWidget(self.txtI[k][i], 1+i, j)
|
layout_tab.addWidget(self.txtI[k][i], initRow + i, j)
|
||||||
|
|
||||||
self.txtI[k][i].returnPressed.connect(partial(self.SetI, k, i) )
|
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].returnPressed.connect(partial(self.UnSetTextColor, self.txtI[k][i]))
|
||||||
|
@ -186,7 +197,7 @@ class MyWindow(QMainWindow):
|
||||||
if j == 5:
|
if j == 5:
|
||||||
self.txtVOut[k][i].setText("{:.2f}".format(outVList[sum(nChPerMod[:k]) + i]))
|
self.txtVOut[k][i].setText("{:.2f}".format(outVList[sum(nChPerMod[:k]) + i]))
|
||||||
self.txtVOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
self.txtVOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
layout_tab.addWidget(self.txtVOut[k][i], 1+i, j)
|
layout_tab.addWidget(self.txtVOut[k][i], initRow + i, j)
|
||||||
self.txtVOut[k][i].setReadOnly(True)
|
self.txtVOut[k][i].setReadOnly(True)
|
||||||
self.txtVOut[k][i].setStyleSheet("background-color: lightgrey;")
|
self.txtVOut[k][i].setStyleSheet("background-color: lightgrey;")
|
||||||
|
|
||||||
|
@ -194,7 +205,7 @@ class MyWindow(QMainWindow):
|
||||||
if j == 6:
|
if j == 6:
|
||||||
self.txtIOut[k][i].setText("{:.2f}".format(outIList[sum(nChPerMod[:k]) + i]*1e6))
|
self.txtIOut[k][i].setText("{:.2f}".format(outIList[sum(nChPerMod[:k]) + i]*1e6))
|
||||||
self.txtIOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
self.txtIOut[k][i].setAlignment(Qt.AlignmentFlag.AlignRight)
|
||||||
layout_tab.addWidget(self.txtIOut[k][i], 1+i, j)
|
layout_tab.addWidget(self.txtIOut[k][i], initRow + i, j)
|
||||||
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;")
|
||||||
|
|
||||||
|
@ -293,6 +304,19 @@ class MyWindow(QMainWindow):
|
||||||
newValue = mpod.GetCurrent(mod*100+ch)
|
newValue = mpod.GetCurrent(mod*100+ch)
|
||||||
self.txtI[mod][ch].setText("{:.1f}".format(newValue))
|
self.txtI[mod][ch].setText("{:.1f}".format(newValue))
|
||||||
|
|
||||||
|
def SetAllOnOff(self):
|
||||||
|
for k in range(0, nMod):
|
||||||
|
for ch, a in enumerate(modChList[k]) :
|
||||||
|
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)
|
||||||
|
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):
|
def SetOnOff(self, mod, ch):
|
||||||
state = self.chkON[mod][ch].checkState()
|
state = self.chkON[mod][ch].checkState()
|
||||||
if state == Qt.CheckState.Checked:
|
if state == Qt.CheckState.Checked:
|
||||||
|
@ -305,7 +329,7 @@ class MyWindow(QMainWindow):
|
||||||
onOffList[sum(nChPerMod[:mod]) + ch] = 0
|
onOffList[sum(nChPerMod[:mod]) + ch] = 0
|
||||||
|
|
||||||
value = mpod.IsHVOn(mod*100 + ch)
|
value = mpod.IsHVOn(mod*100 + ch)
|
||||||
# print("mod : " + str(mod) + ", ch : " + str(ch) + " | " + str(state) + " | " + str(onOffList[sum(nChPerMod[:mod]) + 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[mod][ch].setChecked(False)
|
self.chkON[mod][ch].setChecked(False)
|
||||||
self.chkON[mod][ch].setStyleSheet("")
|
self.chkON[mod][ch].setStyleSheet("")
|
||||||
|
@ -328,12 +352,15 @@ class MyWindow(QMainWindow):
|
||||||
|
|
||||||
for k in range(0, nMod):
|
for k in range(0, nMod):
|
||||||
for i, a in enumerate(modChList[k]) :
|
for i, a in enumerate(modChList[k]) :
|
||||||
self.txtVOut[k][i].setText("{:.2f}".format(outVList[sum(nChPerMod[:k]) + i]))
|
|
||||||
self.txtIOut[k][i].setText("{:.2f}".format(outIList[sum(nChPerMod[:k]) + i] * 1e6))
|
vout = outVList[sum(nChPerMod[:k]) + i] # in Volt
|
||||||
|
iout = outIList[sum(nChPerMod[:k]) + i] # in Amp
|
||||||
|
self.txtVOut[k][i].setText("{:.2f}".format(vout))
|
||||||
|
self.txtIOut[k][i].setText("{:.2f}".format(iout * 1e6))
|
||||||
|
|
||||||
if 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[i])))
|
points.append(Point("Voltage").tag("Ch",int(chList[i] + 100 * k)).field("value",float(vout)))
|
||||||
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(outIList[i])))
|
points.append(Point("LeakageCurrent").tag("Ch",int(chList[i] + 100 * k)).field("value",float(iout)))
|
||||||
|
|
||||||
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
if self.chkDB.checkState() == Qt.CheckState.Checked:
|
||||||
write_api.write(bucket=bucket, org=org, record=points)
|
write_api.write(bucket=bucket, org=org, record=points)
|
||||||
|
|
|
@ -10,8 +10,12 @@ from influxdb_client import InfluxDBClient, Point, WritePrecision
|
||||||
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
from influxdb_client.client.write_api import SYNCHRONOUS, ASYNCHRONOUS
|
||||||
|
|
||||||
#------ database
|
#------ database
|
||||||
|
try:
|
||||||
with open('ISEG_TOKEN.txt', 'r') as f:
|
with open('ISEG_TOKEN.txt', 'r') as f:
|
||||||
token = f.readline()
|
token = f.readline()
|
||||||
|
except:
|
||||||
|
print("Error: ISEG_TOKEN.txt file not found.")
|
||||||
|
token = None # Or assign a default value if needed
|
||||||
|
|
||||||
org = "FSUFoxLab"
|
org = "FSUFoxLab"
|
||||||
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
ip = "https://fsunuc.physics.fsu.edu/influx/"
|
||||||
|
|
|
@ -15,9 +15,14 @@ class Mpod:
|
||||||
def __init__(self, ip):
|
def __init__(self, ip):
|
||||||
#check SNMP version
|
#check SNMP version
|
||||||
version = str(subprocess.check_output(['snmpwalk', '-V'], stderr=subprocess.STDOUT).decode("ascii"))
|
version = str(subprocess.check_output(['snmpwalk', '-V'], stderr=subprocess.STDOUT).decode("ascii"))
|
||||||
versionNum = float(version[17:-3])
|
match = re.search(r"NET-SNMP version: (\d+\.\d+\.\d+(?:\.\d+)?(?:\.\w+)?)", version)
|
||||||
|
if match:
|
||||||
|
versionNum = match.group(1)
|
||||||
|
print("Version:", version)
|
||||||
|
else:
|
||||||
|
print("Error: Could not extract version number." + version)
|
||||||
self.IP = ip
|
self.IP = ip
|
||||||
if versionNum < 5.8 :
|
if versionNum < "5.8" :
|
||||||
print(">>>>>> snmp version < 5.8, does not support high precision.")
|
print(">>>>>> snmp version < 5.8, does not support high precision.")
|
||||||
self.cmd0Str = "-v2c -m +WIENER-CRATE-MIB -c guru %s " % self.IP
|
self.cmd0Str = "-v2c -m +WIENER-CRATE-MIB -c guru %s " % self.IP
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user