pyPLC/pyPlcWorker.py

40 lines
1.3 KiB
Python
Raw Normal View History

# Worker for the pyPLC
#
# Tested on Windows10 with python 3.9
#
#------------------------------------------------------------
import pyPlcHomeplug
class pyPlcWorker():
def __init__(self, callbackAddToTrace=None, callbackShowStatus=None):
print("initializing pyPlcWorker")
self.nMainFunctionCalls=0
self.strUserAction = ""
self.callbackAddToTrace = callbackAddToTrace
self.callbackShowStatus = callbackShowStatus
self.hp = pyPlcHomeplug.pyPlcHomeplug(self.callbackAddToTrace, self.callbackShowStatus)
def addToTrace(self, s):
self.callbackAddToTrace(s)
def showStatus(self, s, selection = ""):
self.callbackShowStatus(s, selection)
def mainfunction(self):
self.nMainFunctionCalls+=1
2022-10-14 21:36:03 +00:00
#self.showStatus("pyPlcWorker loop " + str(self.nMainFunctionCalls))
self.hp.mainfunction() # call the lower-level worker
def handleUserAction(self, strAction):
self.strUserAction = strAction
if (strAction == "P"):
self.hp.enterPevMode()
if (strAction == "E"):
self.hp.enterEvseMode()
if (strAction == "L"):
2022-10-24 21:19:45 +00:00
self.hp.enterListenMode()
# self.addToTrace("UserAction " + strAction)
2022-10-16 00:57:57 +00:00
self.hp.sendTestFrame(strAction)