Fixed bugs with pulling plc status and log count
authorLaurent Bessard
Thu, 21 Mar 2013 17:29:53 +0100
changeset 35 cb9da964a178
parent 34 b2fb188c9bff
child 36 73360d0bacbc
child 37 6e36ecf3f622
Fixed bugs with pulling plc status and log count
LPCManager.py
LPCconnector/LPCAppObject.py
--- 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())
--- a/LPCconnector/LPCAppObject.py	Thu Mar 21 02:06:16 2013 +0100
+++ b/LPCconnector/LPCAppObject.py	Thu Mar 21 17:29:53 2013 +0100
@@ -124,7 +124,7 @@
 
     def GetLogMessage(self, level, msgid):
         strbuf = self.HandleSerialTransaction(GET_LOGMSGTransaction(level, msgid))
-        if len(strbuf) > 12:
+        if strbuf is not None and len(strbuf) > 12:
             cbuf = ctypes.cast(
                           ctypes.c_char_p(strbuf[:12]),
                           ctypes.POINTER(ctypes.c_uint32))