Fixed bug connector not resetted when connection is lost
authorLaurent Bessard
Fri, 10 May 2013 12:11:54 +0200
changeset 1116 300f98a8d4c6
parent 1115 a4e58715ae41
child 1117 1aef6a7db08d
Fixed bug connector not resetted when connection is lost
ProjectController.py
connectors/PYRO/__init__.py
--- a/ProjectController.py	Fri May 10 11:49:22 2013 +0200
+++ b/ProjectController.py	Fri May 10 12:11:54 2013 +0200
@@ -1116,7 +1116,7 @@
                 status, log_count = PLCstatus
                 self.UpdatePLCLog(log_count)
         if status is None:
-            self._SetConnector(None)
+            self._SetConnector(None, False)
             status = "Disconnected"
         if(self.previous_plcstate != status):
             for args in {
@@ -1380,7 +1380,7 @@
         
         wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
-    def _SetConnector(self, connector):
+    def _SetConnector(self, connector, update_status=True):
         self._connector = connector
         if self.AppFrame is not None:
             self.AppFrame.LogViewer.SetLogSource(connector)
@@ -1390,6 +1390,8 @@
         else:
             # Stop the status Timer
             self.StatusTimer.Stop()
+            if update_status:
+                wx.CallAfter(self.UpdateMethodsFromPLCStatus)
 
     def _Connect(self):
         # don't accept re-connetion if already connected
@@ -1493,7 +1495,6 @@
 
     def _Disconnect(self):
         self._SetConnector(None)
-        wx.CallAfter(self.UpdateMethodsFromPLCStatus)
         
     def _Transfer(self):
         # Get the last build PLC's 
--- a/connectors/PYRO/__init__.py	Fri May 10 11:49:22 2013 +0200
+++ b/connectors/PYRO/__init__.py	Fri May 10 12:11:54 2013 +0200
@@ -73,17 +73,17 @@
         def catcher_func(*args,**kwargs):
             try:
                 return func(*args,**kwargs)
+            except Pyro.errors.ConnectionClosedError, e:
+                confnodesroot.logger.write_error("Connection lost!\n")
+                confnodesroot._SetConnector(None)
             except Pyro.errors.ProtocolError, e:
                 confnodesroot.logger.write_error("Pyro exception: "+str(e)+"\n")
-            except Pyro.errors.ConnectionClosedError, e:
-                confnodesroot.logger.write_error("Connection lost!\n")
-                confnodesroot._connector = None
             except Exception,e:
                 #confnodesroot.logger.write_error(traceback.format_exc())
                 errmess = ''.join(Pyro.util.getPyroTraceback(e))
                 confnodesroot.logger.write_error(errmess+"\n")
                 print errmess
-                confnodesroot._connector = None
+                confnodesroot._SetConnector(None)
             return default
         return catcher_func