completes MAXH2O-2. adds PLC Watchdog
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
from random import randint
|
||||||
|
from Channel import write_tag, read_tag
|
||||||
from device_base import deviceBase
|
from device_base import deviceBase
|
||||||
|
|
||||||
|
PLC_IP_ADDRESS = "192.168.1.10"
|
||||||
|
|
||||||
class start(threading.Thread, deviceBase):
|
class start(threading.Thread, deviceBase):
|
||||||
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
||||||
@@ -10,7 +13,7 @@ class start(threading.Thread, deviceBase):
|
|||||||
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
|
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
|
||||||
|
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.version = "5"
|
self.version = "6"
|
||||||
self.finished = threading.Event()
|
self.finished = threading.Event()
|
||||||
threading.Thread.start(self)
|
threading.Thread.start(self)
|
||||||
|
|
||||||
@@ -20,4 +23,28 @@ class start(threading.Thread, deviceBase):
|
|||||||
self.channels["status"]["last_value"] = ""
|
self.channels["status"]["last_value"] = ""
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
pass
|
watchdog = self.advvfdipp_watchdog()
|
||||||
|
self.sendtodbDev(1, 'watchdog', watchdog, 0)
|
||||||
|
# print("SENDING WATCHDOG: {}".format(watchdog))
|
||||||
|
watchdog_loops = 0
|
||||||
|
watchdog_check_after = 5000
|
||||||
|
while True:
|
||||||
|
watchdog_loops += 1
|
||||||
|
if (watchdog_loops >= watchdog_check_after):
|
||||||
|
test_watchdog = self.advvfdipp_watchdog()
|
||||||
|
if test_watchdog != watchdog:
|
||||||
|
self.sendtodbDev(1, 'watchdog', test_watchdog, 0)
|
||||||
|
# print("SENDING WATCHDOG: {}".format(test_watchdog))
|
||||||
|
watchdog = test_watchdog
|
||||||
|
watchdog_loops = 0
|
||||||
|
|
||||||
|
def advvfdipp_watchdog(self):
|
||||||
|
"""Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1."""
|
||||||
|
randval = randint(0, 32767)
|
||||||
|
write_tag(str(PLC_IP_ADDRESS), 'watchdog_INT', randval)
|
||||||
|
time.sleep(1)
|
||||||
|
watchdog_val = read_tag(str(PLC_IP_ADDRESS), 'watchdog_INT')
|
||||||
|
try:
|
||||||
|
return (randval - 1) == watchdog_val[0]
|
||||||
|
except (KeyError, TypeError):
|
||||||
|
return False
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
"driverFileName":"advvfdipp.py",
|
"driverFileName":"advvfdipp.py",
|
||||||
"deviceName":"advvfdipp",
|
"deviceName":"advvfdipp",
|
||||||
"driverId":"0100",
|
"driverId":"0100",
|
||||||
"releaseVersion":"5",
|
"releaseVersion":"6",
|
||||||
"files": {
|
"files": {
|
||||||
"file1":"advvfdipp.py",
|
"file1":"advvfdipp.py",
|
||||||
"file2":"modbusMap.p" }
|
"file2":"modbusMap.p",
|
||||||
|
"file3":"Channel.py" }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user