ask IP at the beginning of the program

This commit is contained in:
dirac 2022-08-08 12:24:23 -04:00
parent ffc09c7278
commit 4aa05ba873
2 changed files with 218 additions and 178 deletions

View File

@ -12,6 +12,8 @@ host = socket.gethostname()
port = 4305 port = 4305
s.bind((host,port)) s.bind((host,port))
IP = input('Mpod IP address to connect : ')
#===================== GUI #===================== GUI
import PySimpleGUI as sg import PySimpleGUI as sg
@ -19,12 +21,17 @@ import PySimpleGUI as sg
header = ["name", "HV [V]", "Current [mA]"] header = ["name", "HV [V]", "Current [mA]"]
chList = iseg.GetChList() mpod = iseg.Mpod(IP)
hvList = iseg.GetAllHV() # get all V
iList = iseg.GetAllCurrent() # get all current if mpod.isConnected == False:
outVList = iseg.GetAllOutputHV() exit()
outIList = iseg.GetAllLC()
onOffList = iseg.GetAllOnOff() chList = mpod.GetChList()
hvList = mpod.GetAllHV() # get all V
iList = mpod.GetAllCurrent() # get all current
outVList = mpod.GetAllOutputHV()
outIList = mpod.GetAllLC()
onOffList = mpod.GetAllOnOff()
modChList = iseg.SplitChList(chList) modChList = iseg.SplitChList(chList)
@ -39,7 +46,6 @@ for k in range(0, nMod):
layoutTab.append([]) layoutTab.append([])
for k in range(0, nMod): for k in range(0, nMod):
baseI = 0 baseI = 0
for kk in range(0, k): for kk in range(0, k):
baseI += len(modChList[kk]) baseI += len(modChList[kk])
@ -56,9 +62,7 @@ for k in range(0, nMod):
]) ])
for j in range(0, len(modChList[k])) : for j in range(0, len(modChList[k])) :
i = baseI + j i = baseI + j
layoutTab[k].append( layoutTab[k].append(
[ [
sg.Input(default_text='', size = 8, justification = "left", key=("n%d" % chList[i])), sg.Input(default_text='', size = 8, justification = "left", key=("n%d" % chList[i])),
@ -77,6 +81,10 @@ for k in range(0, nMod):
layoutTabGroup[0].append(sg.Tab("Mod-%0d" % k, layoutTab[k])) layoutTabGroup[0].append(sg.Tab("Mod-%0d" % k, layoutTab[k]))
layout = [ layout = [
[
sg.Text("IP :", size = 27, justification = "right"),
sg.Input(IP, size = 16, justification = "right", readonly = True),
],
[ [
sg.Text("refresh period [sec] :", size = 27, justification = "right"), sg.Text("refresh period [sec] :", size = 27, justification = "right"),
sg.Input(updateTime, size = 8, justification = "right", enable_events=True, key=("-Refresh-")) sg.Input(updateTime, size = 8, justification = "right", enable_events=True, key=("-Refresh-"))
@ -123,7 +131,7 @@ while True:
if event[0:1] == 'c' : if event[0:1] == 'c' :
ID = event[1:] ID = event[1:]
iseg.SwitchOnHV(int(ID), int(window[event].get())) mpod.SwitchOnHV(int(ID), int(window[event].get()))
if event == '-Save-' : if event == '-Save-' :
fileName = values["Save As"] fileName = values["Save As"]
@ -144,8 +152,8 @@ while True:
window[("n%d" % chList[i])].update(row[0]) window[("n%d" % chList[i])].update(row[0])
window[("v%d" % chList[i])].update(row[2]) window[("v%d" % chList[i])].update(row[2])
window[("i%d" % chList[i])].update(row[3]) window[("i%d" % chList[i])].update(row[3])
iseg.SetHV(chList[i], float(row[2])) mpod.SetHV(chList[i], float(row[2]))
iseg.SetCurrent(chList[i], float(row[3])/1000) mpod.SetCurrent(chList[i], float(row[3])/1000)
i += 1 i += 1
if event in ["-VRateCombo-", "-VRateCh-", "-VRate-"]: if event in ["-VRateCombo-", "-VRateCh-", "-VRate-"]:
@ -153,33 +161,33 @@ while True:
ch = window["-VRateCh-"].get() ch = window["-VRateCh-"].get()
val = window["-VRate-"].get() val = window["-VRate-"].get()
if item == comboList[0]: if item == comboList[0]:
window["-VRate-"].update("%.3f" % float(iseg.GetHVRiseRate(int(ch)))) window["-VRate-"].update("%.3f" % float(mpod.GetHVRiseRate(int(ch))))
if item == comboList[1]: if item == comboList[1]:
window["-VRate-"].update("%.3f" % float(iseg.GetHVFallRate(int(ch)))) window["-VRate-"].update("%.3f" % float(mpod.GetHVFallRate(int(ch))))
if item == comboList[2]: if item == comboList[2]:
iseg.SetHVRiseRate(ch, val) mpod.SetHVRiseRate(ch, val)
window["-VRate-"].update("%.3f" % float(iseg.GetHVRiseRate(int(ch)))) window["-VRate-"].update("%.3f" % float(mpod.GetHVRiseRate(int(ch))))
if item == comboList[3]: if item == comboList[3]:
iseg.SetHVFallRate(ch, val) mpod.SetHVFallRate(ch, val)
window["-VRate-"].update("%.3f" % float(iseg.GetHVFallRate(int(ch)))) window["-VRate-"].update("%.3f" % float(mpod.GetHVFallRate(int(ch))))
haha = event.find('_Enter') haha = event.find('_Enter')
if haha > 0 : if haha > 0 :
ID = event[:haha] ID = event[:haha]
ch = int(ID[1:]) ch = int(ID[1:])
if event[0:1] == 'v' : if event[0:1] == 'v' :
iseg.SetHV(ch, float(window[ID].get())) mpod.SetHV(ch, float(window[ID].get()))
window[ID].update("%.3f" % iseg.GetHV(ch)) window[ID].update("%.3f" % mpod.GetHV(ch))
if event[0:1] == 'i' : if event[0:1] == 'i' :
iseg.SetCurrent(ch, float(window[ID].get())/1000.) mpod.SetCurrent(ch, float(window[ID].get())/1000.)
window[ID].update("%.3f" % (iseg.GetCurrent(ch)*1000)) window[ID].update("%.3f" % (mpod.GetCurrent(ch)*1000))
if event == "_TIMEOUT_" : if event == "_TIMEOUT_" :
#hvList = GetAllHV() # get all V #hvList = GetAllHV() # get all V
#iList = GetAllCurrent() # get all current #iList = GetAllCurrent() # get all current
outVList = iseg.GetAllOutputHV() outVList = mpod.GetAllOutputHV()
outIList = iseg.GetAllLC() outIList = mpod.GetAllLC()
tempFile = open("temp.dat", "w") tempFile = open("temp.dat", "w")

View File

@ -3,162 +3,192 @@
import os import os
import subprocess import subprocess
#cmd0Str = "-v2c -m +WIENER-CRATE-MIB -c guru 128.186.111.101 " class Mpod:
cmd0Str = "-v2c -Op .12 -m +WIENER-CRATE-MIB -c guru 128.186.111.101 " def __init__(self, ip):
self.IP = ip
def SendCmd(option,cmd): #cmd0Str = "-v2c -m +WIENER-CRATE-MIB -c guru 128.186.111.101 "
if option == 0 : self.cmd0Str = "-v2c -Op .12 -m +WIENER-CRATE-MIB -c guru %s " % self.IP
cmdStr = "snmpget " + cmd0Str + cmd self.isConnected = False
elif option == 1: print( "testing communication via " + self.IP)
cmdStr = "snmpset " + cmd0Str + cmd cmdStr = "snmpwalk " + self.cmd0Str
elif option == 2: try :
cmdStr = "snmpwalk " + cmd0Str + cmd result = str(subprocess.check_output(cmdStr, shell=True))
else : print( result )
cmdStr = "echo option: 0 - get, 1 - set, 2 - walk" self.isConnected = True
#print(cmdStr) except :
result = str(subprocess.check_output(cmdStr, shell=True)) print("cannot establish communitation via " + self.IP)
return result.lstrip('b\'').rstrip('\'').rstrip('\n')
#======== Get settings
def GetHV(ch):
haha = SendCmd(0, "outputVoltage.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def GetCurrent(ch):
haha = SendCmd(0, "outputCurrent.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def GetOutputHV(ch):
haha = SendCmd(0, "outputMeasurementSenseVoltage.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def GetLI(ch):
haha = SendCmd(0, "outputMeasurementCurrent.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def IsHVOn(ch):
return SendCmd(0, "outputSwitch.u"+str(ch))
def GetHVRiseRate(ch):
haha = SendCmd(0, "outputVoltageRiseRate.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-5].strip())
def GetHVFallRate(ch):
haha = SendCmd(0, "outputVoltageFallRate.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-5].strip())
#======== Get All channel Setting using snmp walk
def GetChList():
haha = SendCmd(2, "outputName")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputName.'):
if len(k) > 0 :
aa = k.find("=")
k = k[0:aa].strip().lstrip('u')
kaka.append(int(k))
return kaka
def GetAllHV():
haha = SendCmd(2, "outputVoltage")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputVoltage'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllCurrent():
haha = SendCmd(2, "outputCurrent")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputCurrent'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllOutputHV():
haha = SendCmd(2, "outputMeasurementSenseVoltage")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputMeasurementSenseVoltage'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllLC():
haha = SendCmd(2, "outputMeasurementCurrent")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputMeasurementCurrent'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllOnOff():
haha = SendCmd(2, "outputSwitch")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputSwitch'):
if len(k) > 0 :
aa = k.find("INTEGER:")
k = k[aa+12:-2].strip('(').strip(')')
kaka.append(int(k))
return kaka
#======== Set Settings
def SetHV(ch, val):
try :
int(ch)
float(val)
return SendCmd(1, "outputVoltage.u" + str(ch) + " F " + str(val))
except:
print("either ch is not int or val is not float")
def SetCurrent(ch, val): def SendCmd(self, option,cmd):
try : if (self.isConnected == False ) : return 0
int(ch) if option == 0 :
float(val) cmdStr = "snmpget " + self.cmd0Str + cmd
return SendCmd(1, "outputCurrent.u" + str(ch) + " F " + str(val)) elif option == 1:
except: cmdStr = "snmpset " + self.cmd0Str + cmd
print("either ch is not int or val is not float") elif option == 2:
cmdStr = "snmpwalk " + self.cmd0Str + cmd
def SwitchOnHV(ch, onOff): else :
try : cmdStr = "echo option: 0 - get, 1 - set, 2 - walk"
int(ch) #print(cmdStr)
int(onOff) result = str(subprocess.check_output(cmdStr, shell=True))
SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(10)) return result.lstrip('b\'').rstrip('\'').rstrip('\n')
return SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(onOff))
except :
print("either ch or onOff is not int")
def SetHVRiseRate(ch, rate): #======== Get settings
try : def GetHV(self, ch):
int(ch) if (self.isConnected == False ) : return 0
int(rate) haha = self.SendCmd(0, "outputVoltage.u" + str(ch))
return SendCmd(1, "outputVoltageRiseRate.u" + str(ch) + " F " + str(rate)) aa = haha.find('Float:')
except: return float(haha[aa+6:-3].strip())
print("either ch is not int or rate is not float")
def GetCurrent(self, ch):
if (self.isConnected == False ) : return 0
haha = self.SendCmd(0, "outputCurrent.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def GetOutputHV(self,ch):
if (self.isConnected == False ) : return 0
haha = self.SendCmd(0, "outputMeasurementSenseVoltage.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def GetLI(self, ch):
if (self.isConnected == False ) : return 0
haha = self.SendCmd(0, "outputMeasurementCurrent.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-3].strip())
def IsHVOn(self, ch):
if (self.isConnected == False ) : return 0
return self.SendCmd(0, "outputSwitch.u"+str(ch))
def GetHVRiseRate(self, ch):
if (self.isConnected == False ) : return 0
haha = self.SendCmd(0, "outputVoltageRiseRate.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-5].strip())
def GetHVFallRate(self, ch):
if (self.isConnected == False ) : return 0
haha = self.SendCmd(0, "outputVoltageFallRate.u" + str(ch))
aa = haha.find('Float:')
return float(haha[aa+6:-5].strip())
def SetHVFallRate(ch, rate): #======== Get All channel Setting using snmp walk
try :
int(ch) def GetChList(self):
int(rate) if (self.isConnected == False ) : return [0]
return SendCmd(1, "outputVoltageFallRate.u" + str(ch) + " F " + str(rate)) haha = self.SendCmd(2, "outputName")
except: kaka = []
print("either ch is not int or rate is not float") for k in haha.split('WIENER-CRATE-MIB::outputName.'):
if len(k) > 0 :
aa = k.find("=")
k = k[0:aa].strip().lstrip('u')
kaka.append(int(k))
return kaka
def GetAllHV(self):
if (self.isConnected == False ) : return [0]
haha = self.SendCmd(2, "outputVoltage")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputVoltage'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllCurrent(self):
if (self.isConnected == False ) : return [0]
haha = self.SendCmd(2, "outputCurrent")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputCurrent'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllOutputHV(self):
if (self.isConnected == False ) : return [0]
haha = self.SendCmd(2, "outputMeasurementSenseVoltage")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputMeasurementSenseVoltage'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllLC(self):
if (self.isConnected == False ) : return [0]
haha = self.SendCmd(2, "outputMeasurementCurrent")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputMeasurementCurrent'):
if len(k) > 0 :
aa = k.find("Float:")
k = k[aa+6: -3].strip()
kaka.append(float(k))
return kaka
def GetAllOnOff(self):
if (self.isConnected == False ) : return [0]
haha = self.SendCmd(2, "outputSwitch")
kaka = []
for k in haha.split('WIENER-CRATE-MIB::outputSwitch'):
if len(k) > 0 :
aa = k.find("INTEGER:")
k = k[aa+12:-2].strip('(').strip(')')
kaka.append(int(k))
return kaka
#======== Set Settings
def SetHV(self, ch, val):
if (self.isConnected == False ) : return 0
try :
int(ch)
float(val)
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 :
int(ch)
float(val)
return self.SendCmd(1, "outputCurrent.u" + str(ch) + " F " + str(val))
except:
print("either ch is not int or val is not float")
def SwitchOnHV(self, ch, onOff):
if (self.isConnected == False ) : return 0
try :
int(ch)
int(onOff)
self.SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(10))
return self.SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(onOff))
except :
print("either ch or onOff is not int")
def SetHVRiseRate(self, ch, rate):
if (self.isConnected == False ) : return 0
try :
int(ch)
int(rate)
return self.SendCmd(1, "outputVoltageRiseRate.u" + str(ch) + " F " + str(rate))
except:
print("either ch is not int or rate is not float")
def SetHVFallRate(self, ch, rate):
if (self.isConnected == False ) : return 0
try :
int(ch)
int(rate)
return SendCmd(1, "outputVoltageFallRate.u" + str(ch) + " F " + str(rate))
except:
print("either ch is not int or rate is not float")
#===================== Auxliary function #===================== Auxliary function
def SplitChList(chList): def SplitChList(chList):
sep = list() sep = list()
for i in range(0, len(chList)): for i in range(0, len(chList)):
@ -176,8 +206,10 @@ def SplitChList(chList):
return newChList return newChList
#===================== SandBox #===================== SandBox
#print( GetOutputHV(0) ) #mpod = Mpod("128.186.111.101")
#print( GetLI(0) )
#print( mpod.GetOutputHV(0) )
#print( mpod.GetLI(0) )
#print( GetHVRiseRate(0) ) #print( GetHVRiseRate(0) )
#print( GetHVFallRate(0) ) #print( GetHVFallRate(0) )
# #
@ -188,6 +220,6 @@ def SplitChList(chList):
#hvList = GetAllOutputHV() #hvList = GetAllOutputHV()
#print(hvList) #print(hvList)
#chList = GetChList() #chList = mpod.GetChList()
#print( SplitChList(chList)) #print( SplitChList(chList))
#print( len(SplitChList(chList))) #print( len(SplitChList(chList)))