DEBUG: (IDE side) fixed wrong implementation of anti-rapid-fire leading to systematic delay in subscribing
authorEdouard Tisserant
Mon, 11 May 2020 11:10:38 +0200
changeset 2708 ea2aaeaaac4e
parent 2707 c26195654ae9
child 2709 a1b185e21295
DEBUG: (IDE side) fixed wrong implementation of anti-rapid-fire leading to systematic delay in subscribing
ProjectController.py
--- a/ProjectController.py	Tue Feb 11 13:56:48 2020 +0100
+++ b/ProjectController.py	Mon May 11 11:10:38 2020 +0200
@@ -254,7 +254,7 @@
         # Setup debug information
         self.IECdebug_datas = {}
 
-        self.DebugTimer = None
+        self.DebugUpdatePending = False
         self.ResetIECProgramsAndVariables()
 
         # In both new or load scenario, no need to save
@@ -276,8 +276,6 @@
         self.debug_status = PlcStatus.Stopped
 
     def __del__(self):
-        if self.DebugTimer:
-            self.DebugTimer.cancel()
         self.KillDebugThread()
 
     def LoadLibraries(self):
@@ -1538,7 +1536,6 @@
         return debug_status, ticks, buffers
 
     def RegisterDebugVarToConnector(self):
-        self.DebugTimer = None
         Idxs = []
         self.TracedIECPath = []
         self.TracedIECTypes = []
@@ -1577,25 +1574,15 @@
                 self._connector.SetTraceVariablesList([])
                 self.DebugToken = None
             self.debug_status, _debug_ticks, _buffers = self.SnapshotAndResetDebugValuesBuffers()
+        self.DebugUpdatePending = False
 
     def IsPLCStarted(self):
         return self.previous_plcstate == PlcStatus.Started
 
-    def ReArmDebugRegisterTimer(self):
-        if self.DebugTimer is not None:
-            self.DebugTimer.cancel()
-
-        # Prevent to call RegisterDebugVarToConnector when PLC is not started
-        # If an output location var is forced it's leads to segmentation fault in runtime
-        # Links between PLC located variables and real variables are not ready
-        if self.IsPLCStarted():
-            # Timer to prevent rapid-fire when registering many variables
-            # use wx.CallAfter use keep using same thread. TODO : use wx.Timer
-            # instead
-            self.DebugTimer = Timer(
-                0.5, wx.CallAfter, args=[self.RegisterDebugVarToConnector])
-            # Rearm anti-rapid-fire timer
-            self.DebugTimer.start()
+    def AppendDebugUpdate(self):
+        if not self.DebugUpdatePending :
+            wx.CallAfter(self.RegisterDebugVarToConnector)
+            self.DebugUpdatePending = True
 
     def GetDebugIECVariableType(self, IECPath):
         _Idx, IEC_Type = self._IECPathToIdx.get(IECPath, (None, None))
@@ -1625,7 +1612,7 @@
 
         IECdebug_data[0][callableobj] = buffer_list
 
-        self.ReArmDebugRegisterTimer()
+        self.AppendDebugUpdate()
 
         return IECdebug_data[1]
 
@@ -1641,12 +1628,12 @@
                     IECdebug_data[0].itervalues(),
                     False)
 
-        self.ReArmDebugRegisterTimer()
+        self.AppendDebugUpdate()
 
     def UnsubscribeAllDebugIECVariable(self):
         self.IECdebug_datas = {}
 
-        self.ReArmDebugRegisterTimer()
+        self.AppendDebugUpdate()
 
     def ForceDebugIECVariable(self, IECPath, fvalue):
         if IECPath not in self.IECdebug_datas:
@@ -1657,7 +1644,7 @@
         IECdebug_data[2] = "Forced"
         IECdebug_data[3] = fvalue
 
-        self.ReArmDebugRegisterTimer()
+        self.AppendDebugUpdate()
 
     def ReleaseDebugIECVariable(self, IECPath):
         if IECPath not in self.IECdebug_datas:
@@ -1668,7 +1655,7 @@
         IECdebug_data[2] = "Registered"
         IECdebug_data[3] = None
 
-        self.ReArmDebugRegisterTimer()
+        self.AppendDebugUpdate()
 
     def CallWeakcallables(self, IECPath, function_name, *cargs):
         data_tuple = self.IECdebug_datas.get(IECPath, None)