plugger.py
changeset 222 d0f7d36bf241
parent 217 f3eb35df4d87
child 227 48c13b84505c
equal deleted inserted replaced
221:451bb2c1d157 222:d0f7d36bf241
   598 
   598 
   599 iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+exe_ext)
   599 iec2c_path = os.path.join(base_folder, "matiec", "iec2c"+exe_ext)
   600 ieclib_path = os.path.join(base_folder, "matiec", "lib")
   600 ieclib_path = os.path.join(base_folder, "matiec", "lib")
   601 
   601 
   602 # import for project creation timestamping
   602 # import for project creation timestamping
   603 from threading import Timer
   603 from threading import Timer, Lock
   604 from time import localtime
   604 from time import localtime
   605 from datetime import datetime
   605 from datetime import datetime
   606 # import necessary stuff from PLCOpenEditor
   606 # import necessary stuff from PLCOpenEditor
   607 from PLCControler import PLCControler
   607 from PLCControler import PLCControler
   608 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
   608 from PLCOpenEditor import PLCOpenEditor, ProjectDialog
   661         self._builder = None
   661         self._builder = None
   662         self._connector = None
   662         self._connector = None
   663         
   663         
   664         # Setup debug information
   664         # Setup debug information
   665         self.IECdebug_callables = {}
   665         self.IECdebug_callables = {}
       
   666         self.IECdebug_callables_lock = Lock()
       
   667 
   666         # Timer to prevent rapid-fire when registering many variables
   668         # Timer to prevent rapid-fire when registering many variables
   667         self.DebugTimer=Timer(0.5,self.RegisterDebugVarToConnector)
   669         self.DebugTimer=Timer(0.5,self.RegisterDebugVarToConnector)
   668         self.ResetIECProgramsAndVariables()
   670         self.ResetIECProgramsAndVariables()
   669 
   671 
   670         
   672         
  1056         return debug_code
  1058         return debug_code
  1057 
  1059 
  1058     def RegisterDebugVarToConnector(self):
  1060     def RegisterDebugVarToConnector(self):
  1059         Idxs = []
  1061         Idxs = []
  1060         if self._connector is not None:
  1062         if self._connector is not None:
       
  1063             self.IECdebug_callables_lock.acquire()
  1061             for IECPath,WeakCallableDict in self.IECdebug_callables:
  1064             for IECPath,WeakCallableDict in self.IECdebug_callables:
  1062                 if len(WeakCallableDict) == 0:
  1065                 if len(WeakCallableDict) == 0:
  1063                     # Callable Dict is empty.
  1066                     # Callable Dict is empty.
  1064                     # This variable is not needed anymore!
  1067                     # This variable is not needed anymore!
  1065                     self.IECdebug_callables.pop(IECPath)
  1068                     self.IECdebug_callables.pop(IECPath)
  1068                     Idx = self._IECPathToIdx.get(IECPath,None)
  1071                     Idx = self._IECPathToIdx.get(IECPath,None)
  1069                     if Idx is not None:
  1072                     if Idx is not None:
  1070                         Idxs.append(Idx)
  1073                         Idxs.append(Idx)
  1071                     else:
  1074                     else:
  1072                         self.logger.write_warning("Debug : Unknown variable %s\n"%IECPath)
  1075                         self.logger.write_warning("Debug : Unknown variable %s\n"%IECPath)
       
  1076             self.IECdebug_callables_lock.release()
  1073             self._connector.TraceVariables(Idxs)
  1077             self._connector.TraceVariables(Idxs)
  1074         
  1078         
  1075     def SubscribeDebugIECVariable(self, IECPath, callable, *args, **kwargs):
  1079     def SubscribeDebugIECVariable(self, IECPath, callable, *args, **kwargs):
  1076         """
  1080         """
  1077         Dispatching use a dictionnary linking IEC variable paths
  1081         Dispatching use a dictionnary linking IEC variable paths
  1078         to a WeakKeyDictionary linking 
  1082         to a WeakKeyDictionary linking 
  1079         weakly referenced callables to optionnal args
  1083         weakly referenced callables to optionnal args
  1080         """
  1084         """
       
  1085         self.IECdebug_callables_lock.acquire()
  1081         # If no entry exist, create a new one with a fresh WeakKeyDictionary
  1086         # If no entry exist, create a new one with a fresh WeakKeyDictionary
  1082         self.IECdebug_callables.setdefault(
  1087         self.IECdebug_callables.setdefault(
  1083                    IECPath, 
  1088                    IECPath, 
  1084                    WeakKeyDictionary())[callable]=(args, kwargs)
  1089                    WeakKeyDictionary())[callable]=(args, kwargs)
       
  1090         self.IECdebug_callables_lock.release()
  1085         # Rearm anti-rapid-fire timer
  1091         # Rearm anti-rapid-fire timer
  1086         self.DebugTimer.cancel()
  1092         self.DebugTimer.cancel()
  1087         self.DebugTimer.start()
  1093         self.DebugTimer.start()
  1088         
  1094         
  1089     def Generate_plc_common_main(self):
  1095     def Generate_plc_common_main(self):