Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
--- a/bacnet/bacnet.py Fri Jul 10 11:15:41 2020 +0200
+++ b/bacnet/bacnet.py Mon Jul 13 13:56:42 2020 +0200
@@ -790,6 +790,6 @@
runtimefile.close()
return ([(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True,
- ("runtime_bacnet_websettings_%s.py" % location_str, open(runtimefile_path, "rb")),
+ ("runtime_%s_bacnet_websettings.py" % location_str, open(runtimefile_path, "rb")),
)
#return [(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True, ('extrafile1.txt', extra_file_handle)
--- a/bacnet/web_settings.py Fri Jul 10 11:15:41 2020 +0200
+++ b/bacnet/web_settings.py Mon Jul 13 13:56:42 2020 +0200
@@ -295,7 +295,7 @@
# location_str is replaced by extension's value in CTNGenerateC call
-def _runtime_bacnet_websettings_%(location_str)s_init():
+def _runtime_%(location_str)s_bacnet_websettings_init():
"""
# Callback function, called (by PLCObject.py) when a new PLC program
# (i.e. XXX.so file) is transfered to the PLC runtime
@@ -383,7 +383,7 @@
# location_str is replaced by extension's value in CTNGenerateC call
-def _runtime_bacnet_websettings_%(location_str)s_cleanup():
+def _runtime_%(location_str)s_bacnet_websettings_cleanup():
"""
# Callback function, called (by PLCObject.py) when a PLC program is unloaded from memory
"""
--- a/etherlab/EthercatMaster.py Fri Jul 10 11:15:41 2020 +0200
+++ b/etherlab/EthercatMaster.py Mon Jul 13 13:56:42 2020 +0200
@@ -97,6 +97,8 @@
return ((["etherlab_ext"], [(Gen_etherlabfile_path, IECCFLAGS)], True), "",
("runtime_etherlab.py", open(GetLocalPath("runtime_etherlab.py"))))
+ # TODO : rename to match runtime_{location}_extname.py format
+
# --------------------------------------------------
# Ethercat MASTER
# --------------------------------------------------
--- a/etherlab/runtime_etherlab.py Fri Jul 10 11:15:41 2020 +0200
+++ b/etherlab/runtime_etherlab.py Mon Jul 13 13:56:42 2020 +0200
@@ -114,6 +114,7 @@
time.sleep(0.5)
+# TODO : rename to match _runtime_{location}_extname_init() format
def _runtime_etherlab_init():
global KMSGPollThread, StopKMSGThread
StopKMSGThread = False
@@ -121,6 +122,7 @@
KMSGPollThread.start()
+# TODO : rename to match _runtime_{location}_extname_cleanup() format
def _runtime_etherlab_cleanup():
global KMSGPollThread, StopKMSGThread, SDOThread
try:
--- a/modbus/modbus.py Fri Jul 10 11:15:41 2020 +0200
+++ b/modbus/modbus.py Mon Jul 13 13:56:42 2020 +0200
@@ -1006,5 +1006,5 @@
runtimefile.close()
return ([(Gen_MB_c_path, ' -I"' + ModbusPath + '"')], LDFLAGS, True,
- ("runtime_modbus_websettings_%s.py" % location_str, open(runtimefile_path, "rb")),
+ ("runtime_%s_modbus_websettings.py" % location_str, open(runtimefile_path, "rb")),
)
--- a/modbus/web_settings.py Fri Jul 10 11:15:41 2020 +0200
+++ b/modbus/web_settings.py Mon Jul 13 13:56:42 2020 +0200
@@ -526,7 +526,7 @@
-def _runtime_modbus_websettings_%(location_str)s_init():
+def _runtime_%(location_str)s_modbus_websettings_init():
"""
Callback function, called (by PLCObject.py) when a new PLC program
(i.e. XXX.so file) is transfered to the PLC runtime
@@ -609,7 +609,7 @@
-def _runtime_modbus_websettings_%(location_str)s_cleanup():
+def _runtime_%(location_str)s_modbus_websettings_cleanup():
"""
Callback function, called (by PLCObject.py) when a PLC program is unloaded from memory
"""
--- a/svghmi/svghmi.py Fri Jul 10 11:15:41 2020 +0200
+++ b/svghmi/svghmi.py Mon Jul 13 13:56:42 2020 +0200
@@ -334,13 +334,16 @@
svghmiservercode = svghmiserverfile.read()
svghmiserverfile.close()
- runtimefile_path = os.path.join(buildpath, "runtime_svghmi.py")
+ runtimefile_path = os.path.join(buildpath, "runtime_00_svghmi.py")
runtimefile = open(runtimefile_path, 'w')
runtimefile.write(svghmiservercode)
runtimefile.close()
return ((["svghmi"], [(gen_svghmi_c_path, IECCFLAGS)], True), "",
- ("runtime_svghmi0.py", open(runtimefile_path, "rb")))
+ ("runtime_00_svghmi.py", open(runtimefile_path, "rb")))
+ # ^
+ # note the double zero after "runtime_",
+ # to ensure placement before other CTN generated code in execution order
class HMITreeSelector(wx.TreeCtrl):
@@ -566,7 +569,7 @@
repr(shlex.split(given_command.format(port="8008", name=view_name))) +
")") if given_command else "pass # no command given"
- runtimefile_path = os.path.join(buildpath, "runtime_svghmi1_%s.py" % location_str)
+ runtimefile_path = os.path.join(buildpath, "runtime_%s_svghmi_.py" % location_str)
runtimefile = open(runtimefile_path, 'w')
runtimefile.write("""
# TODO : multiple watchdog (one for each svghmi instance)
@@ -575,7 +578,7 @@
svghmi_watchdog = None
-def _runtime_svghmi1_{location}_start():
+def _runtime_{location}_svghmi_start():
global svghmi_watchdog
svghmi_root.putChild(
'{view_name}',
@@ -589,7 +592,7 @@
{watchdog_interval},
svghmi_watchdog_trigger)
-def _runtime_svghmi1_{location}_stop():
+def _runtime_{location}_svghmi_stop():
global svghmi_watchdog
if svghmi_watchdog is not None:
svghmi_watchdog.cancel()
@@ -608,7 +611,7 @@
runtimefile.close()
- res += (("runtime_svghmi1_%s.py" % location_str, open(runtimefile_path, "rb")),)
+ res += (("runtime_%s_svghmi.py" % location_str, open(runtimefile_path, "rb")),)
return res
--- a/svghmi/svghmi_server.py Fri Jul 10 11:15:41 2020 +0200
+++ b/svghmi/svghmi_server.py Mon Jul 13 13:56:42 2020 +0200
@@ -167,7 +167,7 @@
# Called by PLCObject at start
-def _runtime_svghmi0_start():
+def _runtime_00_svghmi_start():
global svghmi_listener, svghmi_root, svghmi_send_thread
svghmi_root = Resource()
@@ -181,7 +181,7 @@
# Called by PLCObject at stop
-def _runtime_svghmi0_stop():
+def _runtime_00_svghmi_stop():
global svghmi_listener, svghmi_root, svghmi_send_thread, svghmi_session
if svghmi_session is not None: