PLCObject : reorganize code in StartPLC(), add a PreStartPLC() empty method, to be overloaded by runtime extensions. svghmi
authorEdouard Tisserant
Thu, 28 May 2020 11:38:09 +0200
branchsvghmi
changeset 2972 1f043fdaa7fb
parent 2971 f0a822ef9fa0
child 2973 fbe1c05c0311
child 2978 67c6783f221c
PLCObject : reorganize code in StartPLC(), add a PreStartPLC() empty method, to be overloaded by runtime extensions.
runtime/PLCObject.py
--- a/runtime/PLCObject.py	Tue May 26 09:58:20 2020 +0200
+++ b/runtime/PLCObject.py	Thu May 28 11:38:09 2020 +0200
@@ -451,17 +451,27 @@
         self.PythonThreadCond.notify()
         self.PythonThreadCondLock.release()
 
+    def _fail(msg):
+        self.LogMessage(0, msg)
+        self.PLCStatus = PlcStatus.Broken
+        self.StatusChange()
+
+    def PreStartPLC(self):
+        """ 
+        Here goes actions to be taken just before PLC starts, 
+        with all libraries and python object already created.
+        For example : restore saved proprietary parameters
+        """
+        pass
+
     @RunInMain
     def StartPLC(self):
 
-        def fail(msg):
-            self.LogMessage(0, msg)
-            self.PLCStatus = PlcStatus.Broken
-            self.StatusChange()
-
         if self.PLClibraryHandle is None:
             if not self.LoadPLC():
-                fail(_("Problem starting PLC : can't load PLC"))
+                self._fail(_("Problem starting PLC : can't load PLC"))
+
+        self.PreStartPLC()
 
         if self.CurrentPLCFilename is not None and self.PLCStatus == PlcStatus.Stopped:
             c_argv = ctypes.c_char_p * len(self.argv)
@@ -472,7 +482,7 @@
                 self.PythonThreadCommand("Activate")
                 self.LogMessage("PLC started")
             else:
-                fail(_("Problem starting PLC : error %d" % res))
+                self._fail(_("Problem starting PLC : error %d" % res))
 
     @RunInMain
     def StopPLC(self):