Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
authorEdouard Tisserant
Fri, 05 Jan 2018 15:39:02 +0100
changeset 1887 1b9907ef770b
parent 1886 e4a656e73aec
child 1888 5b3e17d0957c
Moved code from to Beremiz_service.py Server class Start method to Loop method to allow customisation by hot patching. Also renamed Stop method as _stop and use Restart instead of Stop from everywhere else to make it clear that _stop actually does restart...
Beremiz_service.py
--- a/Beremiz_service.py	Thu Jan 04 16:00:35 2018 +0100
+++ b/Beremiz_service.py	Fri Jan 05 15:39:02 2018 +0100
@@ -319,20 +319,20 @@
                                _("IP is not valid!"))])
                 if dlg.ShowModal() == wx.ID_OK:
                     self.pyroserver.ip_addr = dlg.GetValue()
-                    self.pyroserver.Stop()
+                    self.pyroserver.Restart()
 
             def OnTaskBarChangePort(self, evt):
                 dlg = ParamsEntryDialog(None, _("Enter a port number "), defaultValue=str(self.pyroserver.port))
                 dlg.SetTests([(UnicodeType.isdigit, _("Port number must be an integer!")), (lambda port: 0 <= int(port) <= 65535, _("Port number must be 0 <= port <= 65535!"))])
                 if dlg.ShowModal() == wx.ID_OK:
                     self.pyroserver.port = int(dlg.GetValue())
-                    self.pyroserver.Stop()
+                    self.pyroserver.Restart()
 
             def OnTaskBarChangeWorkingDir(self, evt):
                 dlg = wx.DirDialog(None, _("Choose a working directory "), self.pyroserver.workdir, wx.DD_NEW_DIR_BUTTON)
                 if dlg.ShowModal() == wx.ID_OK:
                     self.pyroserver.workdir = dlg.GetPath()
-                    self.pyroserver.Stop()
+                    self.pyroserver.Restart()
 
             def OnTaskBarChangeName(self, evt):
                 servicename = self.pyroserver.servicename
@@ -412,24 +412,26 @@
 
     def Loop(self):
         while self.continueloop:
+            pyro.initServer()
+            self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port)
             self.Start()
+            self.daemon.requestLoop()
+            self.daemon.sock.close()
 
     def Restart(self):
-        self.Stop()
+        self._stop()
 
     def Quit(self):
         self.continueloop = False
         if self.plcobj is not None:
             self.plcobj.StopPLC()
             self.plcobj.UnLoadPLC()
-        self.Stop()
+        self._stop()
 
     def Start(self):
-        pyro.initServer()
-        self.daemon = pyro.Daemon(host=self.ip_addr, port=self.port)
         self.plcobj = PLCObject(self.workdir, self.daemon, self.argv,
-                                self.statuschange, self.evaluator,
-                                self.pyruntimevars)
+                                    self.statuschange, self.evaluator,
+                                    self.pyruntimevars)
         uri = self.daemon.connect(self.plcobj, "PLCObject")
 
         print(_("Pyro port :"), self.port)
@@ -458,10 +460,8 @@
 
         sys.stdout.flush()
 
-        self.daemon.requestLoop()
-        self.daemon.sock.close()
-
-    def Stop(self):
+
+    def _stop(self):
         if self.plcobj is not None:
             self.plcobj.StopPLC()
         if self.servicepublisher is not None: