plugger.py
changeset 474 6dc5505d79ce
parent 468 d750151bd6ae
child 475 44fea837f813
equal deleted inserted replaced
473:fc0b3c064208 474:6dc5505d79ce
  1584         self.TracedIECPath = []
  1584         self.TracedIECPath = []
  1585         if self._connector is not None:
  1585         if self._connector is not None:
  1586             self.IECdebug_lock.acquire()
  1586             self.IECdebug_lock.acquire()
  1587             IECPathsToPop = []
  1587             IECPathsToPop = []
  1588             for IECPath,data_tuple in self.IECdebug_datas.iteritems():
  1588             for IECPath,data_tuple in self.IECdebug_datas.iteritems():
  1589                 WeakCallableDict, data_log, status = data_tuple
  1589                 WeakCallableDict, data_log, status, fvalue = data_tuple
  1590                 if len(WeakCallableDict) == 0:
  1590                 if len(WeakCallableDict) == 0:
  1591                     # Callable Dict is empty.
  1591                     # Callable Dict is empty.
  1592                     # This variable is not needed anymore!
  1592                     # This variable is not needed anymore!
  1593                     #print "Unused : " + IECPath
  1593                     #print "Unused : " + IECPath
  1594                     IECPathsToPop.append(IECPath)
  1594                     IECPathsToPop.append(IECPath)
  1595                 elif IECPath != "__tick__":
  1595                 elif IECPath != "__tick__":
  1596                     # Convert 
  1596                     # Convert 
  1597                     Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None))
  1597                     Idx, IEC_Type = self._IECPathToIdx.get(IECPath,(None,None))
  1598                     if Idx is not None:
  1598                     if Idx is not None:
  1599                         Idxs.append((Idx, IEC_Type, IECPath))
  1599                         Idxs.append((Idx, IEC_Type, IECPath, fvalue))
  1600                     else:
  1600                     else:
  1601                         self.logger.write_warning(_("Debug : Unknown variable %s\n")%IECPath)
  1601                         self.logger.write_warning(_("Debug : Unknown variable %s\n")%IECPath)
  1602             for IECPathToPop in IECPathsToPop:
  1602             for IECPathToPop in IECPathsToPop:
  1603                 self.IECdebug_datas.pop(IECPathToPop)
  1603                 self.IECdebug_datas.pop(IECPathToPop)
  1604 
  1604 
  1605             if Idxs:
  1605             if Idxs:
  1606                 Idxs.sort()
  1606                 Idxs.sort()
  1607                 self.TracedIECPath = zip(*Idxs)[2]
  1607                 self.TracedIECPath = zip(*Idxs)[2]
  1608                 self._connector.SetTraceVariablesList(zip(*zip(*Idxs)[0:2]))
  1608                 self._connector.SetTraceVariablesList(zip(*zip(*Idxs)[0:3]))
  1609             else:
  1609             else:
  1610                 self.TracedIECPath = []
  1610                 self.TracedIECPath = []
  1611                 self._connector.SetTraceVariablesList([])
  1611                 self._connector.SetTraceVariablesList([])
  1612             self.IECdebug_lock.release()
  1612             self.IECdebug_lock.release()
  1613             
  1613             
  1642         IECdebug_data = self.IECdebug_datas.get(IECPath, None)
  1642         IECdebug_data = self.IECdebug_datas.get(IECPath, None)
  1643         if IECdebug_data is None:
  1643         if IECdebug_data is None:
  1644             IECdebug_data  = [
  1644             IECdebug_data  = [
  1645                     WeakKeyDictionary(), # Callables
  1645                     WeakKeyDictionary(), # Callables
  1646                     [],                  # Data storage [(tick, data),...]
  1646                     [],                  # Data storage [(tick, data),...]
  1647                     "Registered"]        # Variable status
  1647                     "Registered",        # Variable status
       
  1648                     None]                # Forced value
  1648             self.IECdebug_datas[IECPath] = IECdebug_data
  1649             self.IECdebug_datas[IECPath] = IECdebug_data
  1649         
  1650         
  1650         IECdebug_data[0][callableobj]=(args, kwargs)
  1651         IECdebug_data[0][callableobj]=(args, kwargs)
  1651 
  1652 
  1652         self.IECdebug_lock.release()
  1653         self.IECdebug_lock.release()
  1670         IECdebug_data = {}
  1671         IECdebug_data = {}
  1671         self.IECdebug_lock.release()
  1672         self.IECdebug_lock.release()
  1672 
  1673 
  1673         self.ReArmDebugRegisterTimer()
  1674         self.ReArmDebugRegisterTimer()
  1674 
  1675 
  1675     def ForceDebugIECVariable(self, IECPath, value):
  1676     def ForceDebugIECVariable(self, IECPath, fvalue):
  1676         pass
  1677         if not self.IECdebug_datas.has_key(IECPath):
       
  1678             return
       
  1679         
       
  1680         self.IECdebug_lock.acquire()
       
  1681         
       
  1682         # If no entry exist, create a new one with a fresh WeakKeyDictionary
       
  1683         IECdebug_data = self.IECdebug_datas.get(IECPath, None)
       
  1684         IECdebug_data[2] = "Forced"
       
  1685         IECdebug_data[3] = fvalue
       
  1686         
       
  1687         self.IECdebug_lock.release()
       
  1688         
       
  1689         self.ReArmDebugRegisterTimer()
  1677     
  1690     
  1678     def ReleaseDebugIECVariable(self, IECPath):
  1691     def ReleaseDebugIECVariable(self, IECPath):
  1679         pass
  1692         if not self.IECdebug_datas.has_key(IECPath):
  1680 
  1693             return
       
  1694         
       
  1695         self.IECdebug_lock.acquire()
       
  1696         
       
  1697         # If no entry exist, create a new one with a fresh WeakKeyDictionary
       
  1698         IECdebug_data = self.IECdebug_datas.get(IECPath, None)
       
  1699         IECdebug_data[2] = "Registered"
       
  1700         IECdebug_data[3] = None
       
  1701         
       
  1702         self.IECdebug_lock.release()
       
  1703         
       
  1704         self.ReArmDebugRegisterTimer()
       
  1705     
  1681     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1706     def CallWeakcallables(self, IECPath, function_name, *cargs):
  1682         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1707         data_tuple = self.IECdebug_datas.get(IECPath, None)
  1683         if data_tuple is not None:
  1708         if data_tuple is not None:
  1684             WeakCallableDict, data_log, status = data_tuple
  1709             WeakCallableDict, data_log, status, fvalue = data_tuple
  1685             #data_log.append((debug_tick, value))
  1710             #data_log.append((debug_tick, value))
  1686             for weakcallable,(args,kwargs) in WeakCallableDict.iteritems():
  1711             for weakcallable,(args,kwargs) in WeakCallableDict.iteritems():
  1687                 #print weakcallable, value, args, kwargs
  1712                 #print weakcallable, value, args, kwargs
  1688                 function = getattr(weakcallable, function_name, None)
  1713                 function = getattr(weakcallable, function_name, None)
  1689                 if function is not None:
  1714                 if function is not None:
  1690                     function(*(cargs + args), **kwargs)
  1715                     if status == "Forced":
       
  1716                         function(*(cargs + [True] + args), **kwargs)
       
  1717                     else:
       
  1718                         function(*(cargs + args), **kwargs)
  1691                 # This will block thread if more than one call is waiting
  1719                 # This will block thread if more than one call is waiting
  1692 
  1720 
  1693     def DebugThreadProc(self):
  1721     def DebugThreadProc(self):
  1694         """
  1722         """
  1695         This thread waid PLC debug data, and dispatch them to subscribers
  1723         This thread waid PLC debug data, and dispatch them to subscribers