mirror of
https://github.com/uhi22/pyPLC.git
synced 2024-11-10 01:05:42 +00:00
feature: show inlet voltage in the GUI
This commit is contained in:
parent
8b9f840232
commit
3da03c011e
3 changed files with 32 additions and 3 deletions
|
@ -88,12 +88,14 @@ class hardwareInterface():
|
||||||
return self.simulatedSoc
|
return self.simulatedSoc
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, callbackAddToTrace=None):
|
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None):
|
||||||
self.callbackAddToTrace = callbackAddToTrace
|
self.callbackAddToTrace = callbackAddToTrace
|
||||||
|
self.callbackShowStatus = callbackShowStatus
|
||||||
self.loopcounter = 0
|
self.loopcounter = 0
|
||||||
self.outvalue = 0
|
self.outvalue = 0
|
||||||
self.simulatedSoc = 20.0 # percent
|
self.simulatedSoc = 20.0 # percent
|
||||||
self.inletVoltage = 0.0 # volts
|
self.inletVoltage = 0.0 # volts
|
||||||
|
self.rxbuffer = ""
|
||||||
self.findSerialPort()
|
self.findSerialPort()
|
||||||
|
|
||||||
def resetSimulation(self):
|
def resetSimulation(self):
|
||||||
|
@ -107,6 +109,22 @@ class hardwareInterface():
|
||||||
def close(self):
|
def close(self):
|
||||||
if (self.isInterfaceOk):
|
if (self.isInterfaceOk):
|
||||||
self.ser.close()
|
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):
|
def mainfunction(self):
|
||||||
if (self.simulatedSoc<100):
|
if (self.simulatedSoc<100):
|
||||||
|
@ -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
|
self.ser.write(bytes("do"+s+"\n", "utf-8")) # set outputs of dieter, see https://github.com/uhi22/dieter
|
||||||
s = self.ser.read(100)
|
s = self.ser.read(100)
|
||||||
if (len(s)>0):
|
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):
|
def myPrintfunction(s):
|
||||||
print("myprint " + s)
|
print("myprint " + s)
|
||||||
|
|
6
pyPlc.py
6
pyPlc.py
|
@ -36,6 +36,9 @@ def cbShowStatus(s, selection=""):
|
||||||
if (selection == "pevmac"):
|
if (selection == "pevmac"):
|
||||||
lblPevMac['text']="PEV MAC " + s
|
lblPevMac['text']="PEV MAC " + s
|
||||||
s=""
|
s=""
|
||||||
|
if (selection == "uInlet"):
|
||||||
|
lblUInlet['text']= "UInlet " + s + "V"
|
||||||
|
s=""
|
||||||
if (len(s)>0):
|
if (len(s)>0):
|
||||||
lblStatus['text']=s
|
lblStatus['text']=s
|
||||||
root.update()
|
root.update()
|
||||||
|
@ -69,6 +72,9 @@ lblStatus = tk.Label(root, text="(Status)")
|
||||||
lblStatus.pack()
|
lblStatus.pack()
|
||||||
lblPevMac = tk.Label(root, text="(pev mac)")
|
lblPevMac = tk.Label(root, text="(pev mac)")
|
||||||
lblPevMac.pack()
|
lblPevMac.pack()
|
||||||
|
lblUInlet = tk.Label(root, text="(U Inlet)")
|
||||||
|
lblUInlet.config(font=('Helvetica bold', 26))
|
||||||
|
lblUInlet.pack()
|
||||||
lblMode = tk.Label(root, text="(mode)")
|
lblMode = tk.Label(root, text="(mode)")
|
||||||
lblMode.pack()
|
lblMode.pack()
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ class pyPlcWorker():
|
||||||
self.oldAvlnStatus = 0
|
self.oldAvlnStatus = 0
|
||||||
self.isSimulationMode = isSimulationMode
|
self.isSimulationMode = isSimulationMode
|
||||||
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.workerAddToTrace, self.callbackShowStatus, self.mode, self.addressManager, self.callbackReadyForTcp, self.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")
|
self.hp.printToUdp("pyPlcWorker init")
|
||||||
# Find out the version number, using git.
|
# Find out the version number, using git.
|
||||||
# see https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
|
# see https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
|
||||||
|
|
Loading…
Reference in a new issue