coil event processed immediately

This commit is contained in:
Wolfgang Hottgenroth 2021-08-23 17:55:10 +02:00
parent 882571425b
commit 5f3d50090a
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
2 changed files with 7 additions and 2 deletions

View File

@ -72,7 +72,10 @@ def modbusHandler(config, processImage):
logger.error("Exception in inner modbus handler loop: {}".format(e))
client.close()
finally:
sleep(modbusRefreshPeriod)
#sleep(modbusRefreshPeriod)
if (processImage.coilEvent.wait(timeout=modbusRefreshPeriod)):
processImage.coilEvent.clear()
except Exception as e:
logger.error("Exception in modbus handler: {}".format(e))

View File

@ -1,4 +1,4 @@
from threading import Condition
from threading import Condition, Event
from loguru import logger
def zippingFilter(a, b):
@ -9,6 +9,7 @@ class NotInitializedException(Exception): pass
class ProcessImage(Condition):
def __init__(self):
super().__init__()
self.coilEvent = Event()
self.initialized = False
def init(self, numCoils, numDiscreteInputs, numAnalogInputs):
@ -61,6 +62,7 @@ class ProcessImage(Condition):
if not self.initialized:
raise NotInitializedException
self.coils[coilNum] = value
self.coilEvent.set()
# def getChangedCoils(self):
# if not self.initialized: