--- a/svghmi/svghmi.py Tue Jan 21 13:55:03 2020 +0100
+++ b/svghmi/svghmi.py Thu Jan 23 11:22:09 2020 +0100
@@ -374,6 +374,8 @@
<xsd:attribute name="OnStart" type="xsd:string" use="optional"/>
<xsd:attribute name="OnStop" type="xsd:string" use="optional"/>
<xsd:attribute name="OnWatchdog" type="xsd:string" use="optional"/>
+ <xsd:attribute name="WatchdogInitial" type="xsd:integer" use="optional"/> + <xsd:attribute name="WatchdogInterval" type="xsd:integer" use="optional"/> @@ -511,22 +513,42 @@
runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
runtimefile = open(runtimefile_path, 'w')
+# TODO : multiple watchdog (one for each svghmi instance) +def svghmi_watchdog_trigger(): def _runtime_svghmi1_{location}_start():
- svghmi_root.putChild('{view_name}', NoCacheFile('{xhtml}', defaultType='application/xhtml+xml'))
+ defaultType='application/xhtml+xml')) + svghmi_watchdog = Watchdog( + svghmi_watchdog_trigger) def _runtime_svghmi1_{location}_stop():
+ if svghmi_watchdog is not None: + svghmi_watchdog.cancel() svghmi_root.delEntity('{view_name}')
""".format(location=location_str,
- svghmi_cmds=svghmi_cmds))
+ svghmi_cmds=svghmi_cmds, + watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"], + watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"], --- a/svghmi/svghmi_server.py Tue Jan 21 13:55:03 2020 +0100
+++ b/svghmi/svghmi_server.py Thu Jan 23 11:22:09 2020 +0100
@@ -78,17 +78,20 @@
- def __init__(self, initial_timeout, callback):
+ def __init__(self, initial_timeout, interval, callback): self._callback = callback
self.initial_timeout = initial_timeout
+ self.interval = interval
- self.timer = Timer(self.initial_timeout, self.trigger)
+ def _start(self, rearm=False): + duration = self.interval if rearm else self.initial_timeout + self.timer = Timer(duration, self.trigger) if self.timer is not None:
@@ -102,7 +105,7 @@
+ self._start(rearm=True) @@ -162,7 +165,7 @@
# Called by PLCObject at start
def _runtime_svghmi0_start():
- global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_watchdog
+ global svghmi_listener, svghmi_root, svghmi_send_thread svghmi_root.putChild("ws", WebSocketResource(HMIWebSocketServerFactory()))
@@ -173,15 +176,10 @@
svghmi_send_thread = Thread(target=SendThreadProc, name="SVGHMI Send")
svghmi_send_thread.start()
- svghmi_watchdog = Watchdog(5, watchdog_trigger)
# Called by PLCObject at stop
def _runtime_svghmi0_stop():
- global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_session, svghmi_watchdog
- if svghmi_watchdog is not None:
- svghmi_watchdog.cancel()
+ global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_session if svghmi_session is not None:
--- a/tests/svghmi/plc.xml Tue Jan 21 13:55:03 2020 +0100
+++ b/tests/svghmi/plc.xml Thu Jan 23 11:22:09 2020 +0100
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns:ns1="http://www.plcopen.org/xml/tc6_0201" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="Unknown" productName="Unnamed" productVersion="1" creationDateTime="2019-08-06T14:23:42"/>
- <contentHeader name="Unnamed" modificationDateTime="2020-01-15T09:34:34">
+ <contentHeader name="Unnamed" modificationDateTime="2020-01-23T11:01:29"> --- a/tests/svghmi/svghmi_0@svghmi/confnode.xml Tue Jan 21 13:55:03 2020 +0100
+++ b/tests/svghmi/svghmi_0@svghmi/confnode.xml Thu Jan 23 11:22:09 2020 +0100
@@ -1,2 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
-<SVGHMI xmlns:xsd="http://www.w3.org/2001/XMLSchema" OnWatchdog="echo Watchdog for {name} !" OnStart="xdg-open http://127.0.0.1:{port}/{name}" OnStop="echo Closing {name}"/>
+<SVGHMI xmlns:xsd="http://www.w3.org/2001/XMLSchema" OnWatchdog="echo Watchdog for {name} !" OnStart="xdg-open http://127.0.0.1:{port}/{name}" OnStop="echo Closing {name}" WatchdogInitial="10" WatchdogInterval="5"/>