diff --git a/IsegHVController.py b/IsegHVController.py index f548403..c47232f 100755 --- a/IsegHVController.py +++ b/IsegHVController.py @@ -6,6 +6,7 @@ import datetime import csv import socket import sys +import time #assign a port, to prevent the script run mulitple time s = socket.socket() @@ -49,13 +50,22 @@ modChList = iseg.SplitChList(chList) nMod = len(modChList) nChannel = len(chList) -updateTime = 60 #sec +updateTime = 1 #sec fileName = '' layoutTab = [] +isAllOn = [] for k in range(0, nMod): layoutTab.append([]) + isAllOn.append(True) + baseI = 0 + for kk in range(0, k): + baseI += len(modChList[kk]) + for j in range(0, len(modChList[k])) : + i = baseI + j + if( onOffList[i] == False ): + isAllOn[k] = False for k in range(0, nMod): baseI = 0 @@ -76,7 +86,7 @@ for k in range(0, nMod): layoutTab[k].append([ sg.Text("", size = 8, justification = "center" ), sg.Text("All", size = 4, justification = "center" ), - sg.Checkbox('', default = 0, size = 3, enable_events = True, key=("c-ALL%d" % k)), + sg.Checkbox('', default = isAllOn[k], size = 3, enable_events = True, key=("c-ALL%d" % k)), sg.Input(default_text=("" ), size = 8, justification = "right", enable_events=True, key=("v-ALL%d" % k) ), sg.Input(default_text=("" ), size = 9, justification = "right", enable_events=True, key=("i-ALL%d" % k) ), ]) @@ -137,6 +147,8 @@ window = sg.Window('Iseg HV Control & Monitor', layout, finalize = True, keep_on for k in range(0, nMod): window[("i-ALL%d" % k)].bind("", "_EnterALL") + window[("i-ALL%d" % k)].bind("", "_EnterALL") + window[("v-ALL%d" % k)].bind("", "_EnterALL") window[("v-ALL%d" % k)].bind("", "_EnterALL") for i in range(0, nChannel): window[("v%d" % chList[i])].bind("", "_EnterCh") @@ -163,10 +175,18 @@ while True: for ch in modChList[mod]: mpod.SwitchOnHV(int(ch), int(window[event].get())) window[("c%d" % ch)].update(window[event].get()) + window.refresh() + #time.sleep(0.1) else : ID = event[1:] mpod.SwitchOnHV(int(ID), int(window[event].get())) - window[("c-ALL%d" % (ch%100 - 1))].update(False) + mod = int(int(ID)/100) + #--- check is all On + isAllOn[mod] = True + for ch in modChList[mod]: + if( window[("c%d" % ch)].get() == False ): + isAllOn[mod] = False + window[("c-ALL%d" % mod)].update(isAllOn[mod]); if event == '-Save-' : fileName = values["Save As"] @@ -213,45 +233,51 @@ while True: if event[0:1] == 'v' : mpod.SetHV(ch, float(window[ID].get())) window[ID].update("%.3f" % mpod.GetHV(ch)) - print(("v-ALL%d" % (ch%100 - 1))) - window[("v-ALL%d" % (ch%100 - 1))].update("") + print(("v-ALL%d" % int(ch/100))) + window[("v-ALL%d" % int(ch/100))].update("") if event[0:1] == 'i' : mpod.SetCurrent(ch, float(window[ID].get())/1000.) window[ID].update("%.3f" % (mpod.GetCurrent(ch)*1000)) - window[("i-ALL%d" % (ch%100 - 1))].update("") + print(("i-ALL%d" % int(ch/100))) + window[("i-ALL%d" % int(ch/100))].update("") jaja = event.find('_EnterALL') if jaja > 0 : ID = event[:jaja] mod = int(ID[5:]) + val = float(window[ID].get()); if event[0:1] == 'v' : for ch in modChList[mod]: - mpod.SetHV(ch, float(window[("v%d" % ch)].get())) + mpod.SetHV(ch, val) + window[ID].update("%.3f" % val) window[("v%d" % ch)].update("%.3f" % mpod.GetHV(ch)) + window.refresh() + #time.sleep(0.1) if event[0:1] == 'i' : for ch in modChList[mod]: - mpod.SetCurrent(ch, float(window[ID].get())/1000.) + mpod.SetCurrent(ch, val/1000.) + window[ID].update("%.3f" % val) window[("i%d" % ch)].update("%.3f" % (mpod.GetCurrent(ch)*1000)) + window.refresh() + #time.sleep(0.1) if event == "-DatabaseEnable-" : pushToDB = window["-DatabaseEnable-"].get() window["-DatabaseIP-"].update(disabled=pushToDB) if event == "_TIMEOUT_" : - #hvList = GetAllHV() # get all V - #iList = GetAllCurrent() # get all current outVList = mpod.GetAllOutputHV() outIList = mpod.GetAllLC() + #onOffList = mpod.GetAllOnOff() pushToDB = window["-DatabaseEnable-"].get() if pushToDB : tempFile = open("temp.dat", "w") for i in range(0, nChannel): - #window[("v%d" % chList[i])].update("%.3f" % hvList[i]) - #window[("i%d" % chList[i])].update("%.3f" % (iList[i]*1000)) window[("a%d" % chList[i])].update("%.3f" % outVList[i]) window[("b%d" % chList[i])].update("%.3f" % (outIList[i]*1e6)) + #==== To DataBase if pushToDB : tempFile.write("Voltage,Ch=%d value=%f\n" % (chList[i], outVList[i])) diff --git a/IsegLibrary.py b/IsegLibrary.py index 1473abc..43ddf46 100755 --- a/IsegLibrary.py +++ b/IsegLibrary.py @@ -171,7 +171,7 @@ class Mpod: return self.SendCmd(1, "outputVoltage.u" + str(ch) + " F " + str(val)) except: print("either ch is not int or val is not float") - + def SetCurrent(self, ch, val): if (self.isConnected == False ) : return 0 try : @@ -191,6 +191,16 @@ class Mpod: except : print("either ch or onOff is not int") + def SwitchALLOnHV(self, onOff): + if (self.isConnected == False ) : return 0 + try : + int(onOff) + self.SendCmd(1, "groupsSwitch" + " i " + str(10)) + return self.SendCmd(1, "groupsSwitch.u" + " i " + str(onOff)) + except : + print("onOff is not int or communication problem.") + + def SetHVRiseRate(self, ch, rate): if (self.isConnected == False ) : return 0 try : @@ -209,6 +219,7 @@ class Mpod: except: print("either ch is not int or rate is not float") + #===================== Auxliary function def SplitChList(chList): sep = list() @@ -229,6 +240,10 @@ def SplitChList(chList): #mpod = Mpod("128.186.111.101") +#print( mpod.SendCmd(2, "outputCurrent F 0.0001")) +#hvList = mpod.GetAllCurrent() +#print(hvList) + #print( mpod.GetOutputHV(0) ) #print( mpod.GetLI(0) ) #print( GetHVRiseRate(0) )