ask IP at the beginning of the program
This commit is contained in:
parent
ffc09c7278
commit
4aa05ba873
|
@ -12,6 +12,8 @@ host = socket.gethostname()
|
|||
port = 4305
|
||||
s.bind((host,port))
|
||||
|
||||
IP = input('Mpod IP address to connect : ')
|
||||
|
||||
#===================== GUI
|
||||
import PySimpleGUI as sg
|
||||
|
||||
|
@ -19,12 +21,17 @@ import PySimpleGUI as sg
|
|||
|
||||
header = ["name", "HV [V]", "Current [mA]"]
|
||||
|
||||
chList = iseg.GetChList()
|
||||
hvList = iseg.GetAllHV() # get all V
|
||||
iList = iseg.GetAllCurrent() # get all current
|
||||
outVList = iseg.GetAllOutputHV()
|
||||
outIList = iseg.GetAllLC()
|
||||
onOffList = iseg.GetAllOnOff()
|
||||
mpod = iseg.Mpod(IP)
|
||||
|
||||
if mpod.isConnected == False:
|
||||
exit()
|
||||
|
||||
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)
|
||||
|
||||
|
@ -39,7 +46,6 @@ for k in range(0, nMod):
|
|||
layoutTab.append([])
|
||||
|
||||
for k in range(0, nMod):
|
||||
|
||||
baseI = 0
|
||||
for kk in range(0, k):
|
||||
baseI += len(modChList[kk])
|
||||
|
@ -56,9 +62,7 @@ for k in range(0, nMod):
|
|||
])
|
||||
|
||||
for j in range(0, len(modChList[k])) :
|
||||
|
||||
i = baseI + j
|
||||
|
||||
layoutTab[k].append(
|
||||
[
|
||||
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]))
|
||||
|
||||
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.Input(updateTime, size = 8, justification = "right", enable_events=True, key=("-Refresh-"))
|
||||
|
@ -123,7 +131,7 @@ while True:
|
|||
|
||||
if event[0:1] == 'c' :
|
||||
ID = event[1:]
|
||||
iseg.SwitchOnHV(int(ID), int(window[event].get()))
|
||||
mpod.SwitchOnHV(int(ID), int(window[event].get()))
|
||||
|
||||
if event == '-Save-' :
|
||||
fileName = values["Save As"]
|
||||
|
@ -144,8 +152,8 @@ while True:
|
|||
window[("n%d" % chList[i])].update(row[0])
|
||||
window[("v%d" % chList[i])].update(row[2])
|
||||
window[("i%d" % chList[i])].update(row[3])
|
||||
iseg.SetHV(chList[i], float(row[2]))
|
||||
iseg.SetCurrent(chList[i], float(row[3])/1000)
|
||||
mpod.SetHV(chList[i], float(row[2]))
|
||||
mpod.SetCurrent(chList[i], float(row[3])/1000)
|
||||
i += 1
|
||||
|
||||
if event in ["-VRateCombo-", "-VRateCh-", "-VRate-"]:
|
||||
|
@ -153,33 +161,33 @@ while True:
|
|||
ch = window["-VRateCh-"].get()
|
||||
val = window["-VRate-"].get()
|
||||
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]:
|
||||
window["-VRate-"].update("%.3f" % float(iseg.GetHVFallRate(int(ch))))
|
||||
window["-VRate-"].update("%.3f" % float(mpod.GetHVFallRate(int(ch))))
|
||||
if item == comboList[2]:
|
||||
iseg.SetHVRiseRate(ch, val)
|
||||
window["-VRate-"].update("%.3f" % float(iseg.GetHVRiseRate(int(ch))))
|
||||
mpod.SetHVRiseRate(ch, val)
|
||||
window["-VRate-"].update("%.3f" % float(mpod.GetHVRiseRate(int(ch))))
|
||||
if item == comboList[3]:
|
||||
iseg.SetHVFallRate(ch, val)
|
||||
window["-VRate-"].update("%.3f" % float(iseg.GetHVFallRate(int(ch))))
|
||||
mpod.SetHVFallRate(ch, val)
|
||||
window["-VRate-"].update("%.3f" % float(mpod.GetHVFallRate(int(ch))))
|
||||
|
||||
haha = event.find('_Enter')
|
||||
if haha > 0 :
|
||||
ID = event[:haha]
|
||||
ch = int(ID[1:])
|
||||
if event[0:1] == 'v' :
|
||||
iseg.SetHV(ch, float(window[ID].get()))
|
||||
window[ID].update("%.3f" % iseg.GetHV(ch))
|
||||
mpod.SetHV(ch, float(window[ID].get()))
|
||||
window[ID].update("%.3f" % mpod.GetHV(ch))
|
||||
if event[0:1] == 'i' :
|
||||
iseg.SetCurrent(ch, float(window[ID].get())/1000.)
|
||||
window[ID].update("%.3f" % (iseg.GetCurrent(ch)*1000))
|
||||
mpod.SetCurrent(ch, float(window[ID].get())/1000.)
|
||||
window[ID].update("%.3f" % (mpod.GetCurrent(ch)*1000))
|
||||
|
||||
|
||||
if event == "_TIMEOUT_" :
|
||||
#hvList = GetAllHV() # get all V
|
||||
#iList = GetAllCurrent() # get all current
|
||||
outVList = iseg.GetAllOutputHV()
|
||||
outIList = iseg.GetAllLC()
|
||||
outVList = mpod.GetAllOutputHV()
|
||||
outIList = mpod.GetAllLC()
|
||||
|
||||
tempFile = open("temp.dat", "w")
|
||||
|
||||
|
|
122
IsegLibrary.py
122
IsegLibrary.py
|
@ -3,16 +3,29 @@
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
class Mpod:
|
||||
def __init__(self, ip):
|
||||
self.IP = ip
|
||||
#cmd0Str = "-v2c -m +WIENER-CRATE-MIB -c guru 128.186.111.101 "
|
||||
cmd0Str = "-v2c -Op .12 -m +WIENER-CRATE-MIB -c guru 128.186.111.101 "
|
||||
self.cmd0Str = "-v2c -Op .12 -m +WIENER-CRATE-MIB -c guru %s " % self.IP
|
||||
self.isConnected = False
|
||||
print( "testing communication via " + self.IP)
|
||||
cmdStr = "snmpwalk " + self.cmd0Str
|
||||
try :
|
||||
result = str(subprocess.check_output(cmdStr, shell=True))
|
||||
print( result )
|
||||
self.isConnected = True
|
||||
except :
|
||||
print("cannot establish communitation via " + self.IP)
|
||||
|
||||
def SendCmd(option,cmd):
|
||||
def SendCmd(self, option,cmd):
|
||||
if (self.isConnected == False ) : return 0
|
||||
if option == 0 :
|
||||
cmdStr = "snmpget " + cmd0Str + cmd
|
||||
cmdStr = "snmpget " + self.cmd0Str + cmd
|
||||
elif option == 1:
|
||||
cmdStr = "snmpset " + cmd0Str + cmd
|
||||
cmdStr = "snmpset " + self.cmd0Str + cmd
|
||||
elif option == 2:
|
||||
cmdStr = "snmpwalk " + cmd0Str + cmd
|
||||
cmdStr = "snmpwalk " + self.cmd0Str + cmd
|
||||
else :
|
||||
cmdStr = "echo option: 0 - get, 1 - set, 2 - walk"
|
||||
#print(cmdStr)
|
||||
|
@ -20,43 +33,51 @@ def SendCmd(option,cmd):
|
|||
return result.lstrip('b\'').rstrip('\'').rstrip('\n')
|
||||
|
||||
#======== Get settings
|
||||
def GetHV(ch):
|
||||
haha = SendCmd(0, "outputVoltage.u" + str(ch))
|
||||
def GetHV(self, ch):
|
||||
if (self.isConnected == False ) : return 0
|
||||
haha = self.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))
|
||||
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(ch):
|
||||
haha = SendCmd(0, "outputMeasurementSenseVoltage.u" + str(ch))
|
||||
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(ch):
|
||||
haha = SendCmd(0, "outputMeasurementCurrent.u" + str(ch))
|
||||
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(ch):
|
||||
return SendCmd(0, "outputSwitch.u"+str(ch))
|
||||
def IsHVOn(self, ch):
|
||||
if (self.isConnected == False ) : return 0
|
||||
return self.SendCmd(0, "outputSwitch.u"+str(ch))
|
||||
|
||||
def GetHVRiseRate(ch):
|
||||
haha = SendCmd(0, "outputVoltageRiseRate.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(ch):
|
||||
haha = SendCmd(0, "outputVoltageFallRate.u" + str(ch))
|
||||
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())
|
||||
|
||||
#======== Get All channel Setting using snmp walk
|
||||
|
||||
def GetChList():
|
||||
haha = SendCmd(2, "outputName")
|
||||
def GetChList(self):
|
||||
if (self.isConnected == False ) : return [0]
|
||||
haha = self.SendCmd(2, "outputName")
|
||||
kaka = []
|
||||
for k in haha.split('WIENER-CRATE-MIB::outputName.'):
|
||||
if len(k) > 0 :
|
||||
|
@ -65,8 +86,9 @@ def GetChList():
|
|||
kaka.append(int(k))
|
||||
return kaka
|
||||
|
||||
def GetAllHV():
|
||||
haha = SendCmd(2, "outputVoltage")
|
||||
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 :
|
||||
|
@ -75,8 +97,9 @@ def GetAllHV():
|
|||
kaka.append(float(k))
|
||||
return kaka
|
||||
|
||||
def GetAllCurrent():
|
||||
haha = SendCmd(2, "outputCurrent")
|
||||
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 :
|
||||
|
@ -85,8 +108,9 @@ def GetAllCurrent():
|
|||
kaka.append(float(k))
|
||||
return kaka
|
||||
|
||||
def GetAllOutputHV():
|
||||
haha = SendCmd(2, "outputMeasurementSenseVoltage")
|
||||
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 :
|
||||
|
@ -95,8 +119,9 @@ def GetAllOutputHV():
|
|||
kaka.append(float(k))
|
||||
return kaka
|
||||
|
||||
def GetAllLC():
|
||||
haha = SendCmd(2, "outputMeasurementCurrent")
|
||||
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 :
|
||||
|
@ -105,8 +130,9 @@ def GetAllLC():
|
|||
kaka.append(float(k))
|
||||
return kaka
|
||||
|
||||
def GetAllOnOff():
|
||||
haha = SendCmd(2, "outputSwitch")
|
||||
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 :
|
||||
|
@ -116,40 +142,45 @@ def GetAllOnOff():
|
|||
return kaka
|
||||
|
||||
#======== Set Settings
|
||||
def SetHV(ch, val):
|
||||
def SetHV(self, ch, val):
|
||||
if (self.isConnected == False ) : return 0
|
||||
try :
|
||||
int(ch)
|
||||
float(val)
|
||||
return SendCmd(1, "outputVoltage.u" + str(ch) + " F " + str(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(ch, val):
|
||||
def SetCurrent(self, ch, val):
|
||||
if (self.isConnected == False ) : return 0
|
||||
try :
|
||||
int(ch)
|
||||
float(val)
|
||||
return SendCmd(1, "outputCurrent.u" + str(ch) + " F " + str(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(ch, onOff):
|
||||
def SwitchOnHV(self, ch, onOff):
|
||||
if (self.isConnected == False ) : return 0
|
||||
try :
|
||||
int(ch)
|
||||
int(onOff)
|
||||
SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(10))
|
||||
return SendCmd(1, "outputSwitch.u" + str(ch) + " i " + str(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(ch, rate):
|
||||
def SetHVRiseRate(self, ch, rate):
|
||||
if (self.isConnected == False ) : return 0
|
||||
try :
|
||||
int(ch)
|
||||
int(rate)
|
||||
return SendCmd(1, "outputVoltageRiseRate.u" + str(ch) + " F " + str(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(ch, rate):
|
||||
def SetHVFallRate(self, ch, rate):
|
||||
if (self.isConnected == False ) : return 0
|
||||
try :
|
||||
int(ch)
|
||||
int(rate)
|
||||
|
@ -158,7 +189,6 @@ def SetHVFallRate(ch, rate):
|
|||
print("either ch is not int or rate is not float")
|
||||
|
||||
#===================== Auxliary function
|
||||
|
||||
def SplitChList(chList):
|
||||
sep = list()
|
||||
for i in range(0, len(chList)):
|
||||
|
@ -176,8 +206,10 @@ def SplitChList(chList):
|
|||
return newChList
|
||||
#===================== SandBox
|
||||
|
||||
#print( GetOutputHV(0) )
|
||||
#print( GetLI(0) )
|
||||
#mpod = Mpod("128.186.111.101")
|
||||
|
||||
#print( mpod.GetOutputHV(0) )
|
||||
#print( mpod.GetLI(0) )
|
||||
#print( GetHVRiseRate(0) )
|
||||
#print( GetHVFallRate(0) )
|
||||
#
|
||||
|
@ -188,6 +220,6 @@ def SplitChList(chList):
|
|||
#hvList = GetAllOutputHV()
|
||||
#print(hvList)
|
||||
|
||||
#chList = GetChList()
|
||||
#chList = mpod.GetChList()
|
||||
#print( SplitChList(chList))
|
||||
#print( len(SplitChList(chList)))
|
||||
|
|
Loading…
Reference in New Issue
Block a user