LPCManager.py
changeset 35 cb9da964a178
parent 32 6942b30d13c4
child 37 6e36ecf3f622
--- a/LPCManager.py	Thu Mar 21 02:06:16 2013 +0100
+++ b/LPCManager.py	Thu Mar 21 17:29:53 2013 +0100
@@ -779,7 +779,7 @@
         if self.CurrentMode != SIMULATION_MODE:
             self.KillDebugThread()
             
-            self._connector = self.LPCConnector
+            self._SetConnector(self.LPCConnector)
             
             # Init with actual PLC status and print it
             self.UpdateMethodsFromPLCStatus()
@@ -917,18 +917,24 @@
     def UpdateMethodsFromPLCStatus(self):
         # Get PLC state : Running or Stopped
         # TODO : use explicit status instead of boolean
+        simulating = self.CurrentMode == SIMULATION_MODE
         if self.OnlineMode == "OFF":
+            if simulating:
+                status, log_count = self._connector.GetPLCstatus()
+                self.UpdatePLCLog(log_count)
             status = "Disconnected"
         elif self.OnlineMode == "BOOTLOADER":
             status = "Connected"
         else:
             if self._connector is not None:
                 status, log_count = self._connector.GetPLCstatus()
-                self.UpdatePLCLog(log_count)
+                if status == "Disconnected":
+                    self._SetConnector(None)
+                else:
+                    self.UpdatePLCLog(log_count)
             else:
                 status = "Disconnected"
         if self.previous_plcstate != status or self.previous_mode != self.CurrentMode:
-            simulating = self.CurrentMode == SIMULATION_MODE
             for args in {
                      "Started" :     [("_Simulate", False),
                                       ("_Run", False),
@@ -1057,7 +1063,7 @@
         
         uri = "LOCAL://"
         try:
-            self._connector = connectors.ConnectorFactory(uri, self)
+            self._SetConnector(connectors.ConnectorFactory(uri, self))
         except Exception, msg:
             self.logger.write_error(_("Exception while connecting %s!\n")%uri)
             self.logger.write_error(traceback.format_exc())