Fixes in debug + reconnect to running PLC
authorEdouard TISSERANT <edouard.tisserant@gmail.com>
Sun, 06 Dec 2009 22:52:51 +0100
changeset 465 67d32a91d70b
parent 464 46dd4358e8a8
child 466 11263fd24566
Fixes in debug + reconnect to running PLC
connectors/PYRO/__init__.py
plugger.py
runtime/PLCObject.py
--- a/connectors/PYRO/__init__.py	Sun Dec 06 21:43:34 2009 +0100
+++ b/connectors/PYRO/__init__.py	Sun Dec 06 22:52:51 2009 +0100
@@ -92,7 +92,8 @@
             object is recreated meanwhile, 
             so we must not keep ref to it here
             """
-            if pluginsroot._connector.GetPyroProxy().GetPLCstatus() == "Dirty":
+            current_status = pluginsroot._connector.GetPyroProxy().GetPLCstatus()
+            if current_status == "Dirty":
                 """
                 Some bad libs with static symbols may polute PLC
                 ask runtime to suicide and come back again
@@ -112,6 +113,8 @@
             """
             for safe use in from debug thread, must use the copy
             """
+            if self.RemotePLCObjectProxyCopy is None:
+                self.RemotePLCObjectProxyCopy = copy.copy(pluginsroot._connector.GetPyroProxy())
             return self.RemotePLCObjectProxyCopy.GetTraceVariables()
         GetTraceVariables = PyroCatcher(_PyroGetTraceVariables,("Broken",None,None))
 
--- a/plugger.py	Sun Dec 06 21:43:34 2009 +0100
+++ b/plugger.py	Sun Dec 06 22:52:51 2009 +0100
@@ -1602,6 +1602,9 @@
                 Idxs.sort()
                 self.TracedIECPath = zip(*Idxs)[2]
                 self._connector.SetTraceVariablesList(zip(*zip(*Idxs)[0:2]))
+            else:
+                self.TracedIECPath = []
+                self._connector.SetTraceVariablesList([])
             self.IECdebug_lock.release()
             
             #for IEC_path, IECdebug_data in self.IECdebug_datas.iteritems():
@@ -1727,6 +1730,13 @@
             self.logger.write_warning(_("Debug Thread couldn't be killed"))
         self.DebugThread = None
 
+    def _connect_debug(self): 
+        if self.AppFrame:
+            self.AppFrame.ResetGraphicViewers()
+        self.RegisterDebugVarToConnector()
+        self.DebugThread = Thread(target=self.DebugThreadProc)
+        self.DebugThread.start()
+    
     def _Run(self):
         """
         Start PLC
@@ -1734,11 +1744,7 @@
         if self.GetIECProgramsAndVariables():
             self._connector.StartPLC()
             self.logger.write(_("Starting PLC\n"))
-            if self.AppFrame:
-                self.AppFrame.ResetGraphicViewers()
-            self.RegisterDebugVarToConnector()
-            self.DebugThread = Thread(target=self.DebugThreadProc)
-            self.DebugThread.start()
+            self._connect_debug()
         else:
             self.logger.write_error(_("Couldn't start PLC !\n"))
         self.UpdateMethodsFromPLCStatus()
@@ -1830,6 +1836,13 @@
             
             # Start the status Timer
             self.StatusTimer.Start(milliseconds=500, oneShot=False)
+            
+            if self.previous_plcstate=="Started":
+                if self.DebugAvailable() and self.GetIECProgramsAndVariables():
+                    self.logger.write(_("Debug connect matching running PLC\n"))
+                    self._connect_debug()
+                else:
+                    self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n"))
 
     def CompareLocalAndRemotePLC(self):
         if self._connector is None:
@@ -1846,6 +1859,8 @@
                 self.logger.write(
                    _("Latest build matches target, no transfer needed.\n"))
                 self.EnableMethod("_Transfer", True)
+                # warns controller that program match
+                self.ProgramTransferred()
                 #self.EnableMethod("_Transfer", False)
         else:
             self.logger.write_warning(
--- a/runtime/PLCObject.py	Sun Dec 06 21:43:34 2009 +0100
+++ b/runtime/PLCObject.py	Sun Dec 06 22:52:51 2009 +0100
@@ -252,7 +252,7 @@
     
     def StartPLC(self):
         PLCprint("StartPLC")
-        if self.CurrentPLCFilename is not None:
+        if self.CurrentPLCFilename is not None and self.PLCStatus == "Stopped":
             self.PLCStatus = "Started"
             self.PythonThread = Thread(target=self.PythonThreadProc)
             self.PythonThread.start()
@@ -384,8 +384,8 @@
             tick = ctypes.c_uint32()
             size = ctypes.c_uint32()
             buffer = ctypes.c_void_p()
+            offset = 0
             if self._GetDebugData(ctypes.byref(tick),ctypes.byref(size),ctypes.byref(buffer)) == 0 :
-                offset = 0
                 for idx, iectype in self._Idxs:
                     cursor = ctypes.c_void_p(buffer.value + offset)
                     c_type,unpack_func = self.TypeTranslator.get(iectype, (None,None))
@@ -401,7 +401,7 @@
                         break
             self._FreeDebugData()
             self.PLClibraryLock.release()
-            if offset == size.value:
+            if offset and offset == size.value:
                 return self.PLCStatus, tick.value, res
             else:
                 PLCprint("Debug error - bad buffer unpack !")