feature: show inlet voltage in the GUI

This commit is contained in:
uhi22 2022-12-19 14:48:23 +01:00
parent 8b9f840232
commit 3da03c011e
3 changed files with 32 additions and 3 deletions

View file

@ -88,12 +88,14 @@ class hardwareInterface():
return self.simulatedSoc
def __init__(self, callbackAddToTrace=None):
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None):
self.callbackAddToTrace = callbackAddToTrace
self.callbackShowStatus = callbackShowStatus
self.loopcounter = 0
self.outvalue = 0
self.simulatedSoc = 20.0 # percent
self.inletVoltage = 0.0 # volts
self.rxbuffer = ""
self.findSerialPort()
def resetSimulation(self):
@ -108,6 +110,22 @@ class hardwareInterface():
if (self.isInterfaceOk):
self.ser.close()
def evaluateReceivedData(self, s):
self.rxbuffer += s
x=self.rxbuffer.find("A0=")
if (x>=0):
s = self.rxbuffer[x+3:x+7]
if (len(s)==4):
try:
self.uInlet_V = int(s) / 1024.0 * 1.08 * (6250) / (4.7+4.7)
self.callbackShowStatus(format(self.uInlet_V,".1f"), "uInlet")
except:
# keep last known value, if nothing new valid was received.
pass
#self.addToTrace("RX data ok " + s)
self.rxbuffer = self.rxbuffer[x+3:] # consume the receive buffer entry
def mainfunction(self):
if (self.simulatedSoc<100):
if ((self.outvalue & 2)!=0):
@ -122,7 +140,12 @@ class hardwareInterface():
self.ser.write(bytes("do"+s+"\n", "utf-8")) # set outputs of dieter, see https://github.com/uhi22/dieter
s = self.ser.read(100)
if (len(s)>0):
self.addToTrace(str(len(s)) + " bytes received: " + str(s, 'utf-8').strip())
try:
s = str(s, 'utf-8').strip()
except:
s = "" # for the case we received corrupted data (not convertable as utf-8)
self.addToTrace(str(len(s)) + " bytes received: " + s)
self.evaluateReceivedData(s)
def myPrintfunction(s):
print("myprint " + s)

View file

@ -36,6 +36,9 @@ def cbShowStatus(s, selection=""):
if (selection == "pevmac"):
lblPevMac['text']="PEV MAC " + s
s=""
if (selection == "uInlet"):
lblUInlet['text']= "UInlet " + s + "V"
s=""
if (len(s)>0):
lblStatus['text']=s
root.update()
@ -69,6 +72,9 @@ lblStatus = tk.Label(root, text="(Status)")
lblStatus.pack()
lblPevMac = tk.Label(root, text="(pev mac)")
lblPevMac.pack()
lblUInlet = tk.Label(root, text="(U Inlet)")
lblUInlet.config(font=('Helvetica bold', 26))
lblUInlet.pack()
lblMode = tk.Label(root, text="(mode)")
lblMode.pack()

View file

@ -29,7 +29,7 @@ class pyPlcWorker():
self.oldAvlnStatus = 0
self.isSimulationMode = isSimulationMode
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.workerAddToTrace, self.callbackShowStatus, self.mode, self.addressManager, self.callbackReadyForTcp, self.isSimulationMode)
self.hardwareInterface = hardwareInterface.hardwareInterface(self.workerAddToTrace)
self.hardwareInterface = hardwareInterface.hardwareInterface(self.workerAddToTrace, self.callbackShowStatus)
self.hp.printToUdp("pyPlcWorker init")
# Find out the version number, using git.
# see https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script