svghmi/svghmi.py
branchsvghmi
changeset 2831 6c9cfdbe94dc
parent 2830 15d7bd79d9e8
child 2834 6ac6a9dff594
--- 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"/>
         </xsd:complexType>
       </xsd:element>
     </xsd:schema>
@@ -511,22 +513,42 @@
         runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
         runtimefile = open(runtimefile_path, 'w')
         runtimefile.write("""
-# TODO : multi
-def watchdog_trigger():
+# TODO : multiple watchdog (one for each svghmi instance)
+def svghmi_watchdog_trigger():
     {svghmi_cmds[Watchdog]}
 
+svghmi_watchdog = None
+
 def _runtime_svghmi1_{location}_start():
-    svghmi_root.putChild('{view_name}', NoCacheFile('{xhtml}', defaultType='application/xhtml+xml'))
+    global svghmi_watchdog
+    svghmi_root.putChild(
+        '{view_name}',
+        NoCacheFile('{xhtml}',
+        defaultType='application/xhtml+xml'))
+
     {svghmi_cmds[Start]}
 
+    svghmi_watchdog = Watchdog(
+        {watchdog_initial}, 
+        {watchdog_interval}, 
+        svghmi_watchdog_trigger)
+
 def _runtime_svghmi1_{location}_stop():
+    global svghmi_watchdog
+    if svghmi_watchdog is not None:
+        svghmi_watchdog.cancel()
+        svghmi_watchdog = None
+
     svghmi_root.delEntity('{view_name}')
     {svghmi_cmds[Stop]}
 
         """.format(location=location_str,
                    xhtml=target_fname,
                    view_name=view_name,
-                   svghmi_cmds=svghmi_cmds))
+                   svghmi_cmds=svghmi_cmds,
+                   watchdog_initial = self.GetParamsAttributes("SVGHMI.WatchdogInitial")["value"],
+                   watchdog_interval = self.GetParamsAttributes("SVGHMI.WatchdogInterval")["value"],
+                   ))
 
         runtimefile.close()