Add safety check to prevent exception when disconnecting while debugging
authorEdouard Tisserant
Thu, 19 Apr 2018 13:09:41 +0200
changeset 1996 4ae9c4447947
parent 1995 691d119ba20f
child 1997 d9e8fb47340f
Add safety check to prevent exception when disconnecting while debugging
ProjectController.py
--- a/ProjectController.py	Thu Apr 19 13:02:13 2018 +0200
+++ b/ProjectController.py	Thu Apr 19 13:09:41 2018 +0200
@@ -1418,25 +1418,26 @@
         self.UpdateMethodsFromPLCStatus()
 
     def SnapshotAndResetDebugValuesBuffers(self):
-        plc_status, Traces = self._connector.GetTraceVariables()
-        # print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()]
-        if plc_status == "Started":
-            if len(Traces) > 0:
-                for debug_tick, debug_buff in Traces:
-                    debug_vars = UnpackDebugBuffer(debug_buff, self.TracedIECTypes)
-                    if debug_vars is not None and len(debug_vars) == len(self.TracedIECPath):
-                        for IECPath, values_buffer, value in izip(
-                                self.TracedIECPath,
-                                self.DebugValuesBuffers,
-                                debug_vars):
-                            IECdebug_data = self.IECdebug_datas.get(IECPath, None)
-                            if IECdebug_data is not None and value is not None:
-                                forced = IECdebug_data[2:4] == ["Forced", value]
-                                if not IECdebug_data[4] and len(values_buffer) > 0:
-                                    values_buffer[-1] = (value, forced)
-                                else:
-                                    values_buffer.append((value, forced))
-                        self.DebugTicks.append(debug_tick)
+        if self._connector is not None:
+            plc_status, Traces = self._connector.GetTraceVariables()
+            # print [dict.keys() for IECPath, (dict, log, status, fvalue) in self.IECdebug_datas.items()]
+            if plc_status == "Started":
+                if len(Traces) > 0:
+                    for debug_tick, debug_buff in Traces:
+                        debug_vars = UnpackDebugBuffer(debug_buff, self.TracedIECTypes)
+                        if debug_vars is not None and len(debug_vars) == len(self.TracedIECPath):
+                            for IECPath, values_buffer, value in izip(
+                                    self.TracedIECPath,
+                                    self.DebugValuesBuffers,
+                                    debug_vars):
+                                IECdebug_data = self.IECdebug_datas.get(IECPath, None)
+                                if IECdebug_data is not None and value is not None:
+                                    forced = IECdebug_data[2:4] == ["Forced", value]
+                                    if not IECdebug_data[4] and len(values_buffer) > 0:
+                                        values_buffer[-1] = (value, forced)
+                                    else:
+                                        values_buffer.append((value, forced))
+                            self.DebugTicks.append(debug_tick)
 
 
         buffers, self.DebugValuesBuffers = (self.DebugValuesBuffers,