# HG changeset patch # User Edouard Tisserant # Date 1578672001 -3600 # Node ID d631f8671c75def5e9e369fde4d8df88e68e8969 # Parent 9101a72a1da0e06ff0aba9336952963a6eec3b38 SVGHMI : add on Start, Stop and Watchdog command fields to configuration diff -r 9101a72a1da0 -r d631f8671c75 svghmi/svghmi.py --- a/svghmi/svghmi.py Fri Jan 10 13:15:07 2020 +0100 +++ b/svghmi/svghmi.py Fri Jan 10 17:00:01 2020 +0100 @@ -13,6 +13,7 @@ from pprint import pformat import hashlib import weakref +import shlex import wx import wx.dataview as dv @@ -375,8 +376,9 @@ - - + + + @@ -503,19 +505,37 @@ target_file.close() res += ((target_fname, open(target_path, "rb")),) + + svghmi_cmds = {} + for thing in ["Start", "Stop", "Watchdog"]: + given_command = self.GetParamsAttributes("SVGHMI.On"+thing)["value"] + if given_command: + svghmi_cmds[thing] = shlex.split(given_command) runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str) runtimefile = open(runtimefile_path, 'w') runtimefile.write(""" +# TODO : multi +svghmi_cmds = %(svghmi_cmds)s +def svghmi_cmd(cmd): + if cmd in svghmi_cmds: + Popen(svghmi_cmds[cmd]) + +def watchdog_trigger(): + svghmi_cmd("Watchdog") + def _runtime_svghmi1_%(location)s_start(): svghmi_root.putChild('%(view_name)s',File('%(xhtml)s', defaultType='application/xhtml+xml')) + svghmi_cmd("Start") def _runtime_svghmi1_%(location)s_stop(): svghmi_root.delEntity('%(view_name)s') + svghmi_cmd("Stop") """ % {"location": location_str, "xhtml": target_fname, - "view_name": view_name}) + "view_name": view_name, + "svghmi_cmds": repr(svghmi_cmds)}) runtimefile.close() diff -r 9101a72a1da0 -r d631f8671c75 svghmi/svghmi_server.py --- a/svghmi/svghmi_server.py Fri Jan 10 13:15:07 2020 +0100 +++ b/svghmi/svghmi_server.py Fri Jan 10 17:00:01 2020 +0100 @@ -9,6 +9,11 @@ import errno from threading import RLock, Timer +try: + from runtime.spawn_subprocess import Popen +except ImportError: + from subprocess import Popen + from twisted.web.server import Site from twisted.web.resource import Resource from twisted.internet import reactor diff -r 9101a72a1da0 -r d631f8671c75 tests/svghmi/plc.xml --- a/tests/svghmi/plc.xml Fri Jan 10 13:15:07 2020 +0100 +++ b/tests/svghmi/plc.xml Fri Jan 10 17:00:01 2020 +0100 @@ -1,7 +1,7 @@ - + diff -r 9101a72a1da0 -r d631f8671c75 tests/svghmi/svghmi_0@svghmi/confnode.xml --- a/tests/svghmi/svghmi_0@svghmi/confnode.xml Fri Jan 10 13:15:07 2020 +0100 +++ b/tests/svghmi/svghmi_0@svghmi/confnode.xml Fri Jan 10 17:00:01 2020 +0100 @@ -1,2 +1,2 @@ - +