plugger.py
changeset 244 85e92d9e34a8
parent 243 90db933fe956
child 246 3613c6ee9e0e
equal deleted inserted replaced
243:90db933fe956 244:85e92d9e34a8
  1356             IECdebug_data[0].pop(callableobj,None)
  1356             IECdebug_data[0].pop(callableobj,None)
  1357         self.IECdebug_lock.release()
  1357         self.IECdebug_lock.release()
  1358 
  1358 
  1359         self.ReArmDebugRegisterTimer()
  1359         self.ReArmDebugRegisterTimer()
  1360 
  1360 
  1361     def DebugCallerFunc(self, weakcallable, value, *args, **kwargs):
       
  1362         # do the call
       
  1363         weakcallable.SetValue(value, *args, **kwargs)
       
  1364         # will unlock debug thread
       
  1365         self.DebugThreadSlowDownLock.release()
       
  1366 
       
  1367     def DebugThreadProc(self):
  1361     def DebugThreadProc(self):
  1368         """
  1362         """
  1369         This thread waid PLC debug data, and dispatch them to subscribers
  1363         This thread waid PLC debug data, and dispatch them to subscribers
  1370         """
  1364         """
  1371         # This lock is used to avoid flooding wx event stack calling callafter
  1365         # This lock is used to avoid flooding wx event stack calling callafter
  1372         self.DebugThreadSlowDownLock = Semaphore(0)
  1366         self.DebugThreadSlowDownLock = Semaphore(0)
  1373         while self._connector is not None:
  1367         _break = False
       
  1368         while not _break and self._connector is not None:
  1374             debug_tick, debug_vars = self._connector.GetTraceVariables()
  1369             debug_tick, debug_vars = self._connector.GetTraceVariables()
  1375             #print debug_tick, debug_vars
  1370             #print debug_tick, debug_vars
  1376             self.IECdebug_lock.acquire()
  1371             self.IECdebug_lock.acquire()
  1377             if debug_vars is not None and \
  1372             if debug_vars is not None and \
  1378                len(debug_vars) == len(self.TracedIECPath):
  1373                len(debug_vars) == len(self.TracedIECPath):
  1381                     if data_tuple is not None:
  1376                     if data_tuple is not None:
  1382                         WeakCallableDict, data_log, status = data_tuple
  1377                         WeakCallableDict, data_log, status = data_tuple
  1383                         data_log.append((debug_tick, value))
  1378                         data_log.append((debug_tick, value))
  1384                         for weakcallable,(args,kwargs) in WeakCallableDict.iteritems():
  1379                         for weakcallable,(args,kwargs) in WeakCallableDict.iteritems():
  1385                             # delegate call to wx event loop
  1380                             # delegate call to wx event loop
  1386                             wx.CallAfter(self.DebugCallerFunc, weakcallable, value, *args, **kwargs)
  1381                             #print weakcallable, value, args, kwargs
       
  1382                             wx.CallAfter(weakcallable.SetValue, value, *args, **kwargs)
  1387                             # This will block thread if more than one call is waiting
  1383                             # This will block thread if more than one call is waiting
  1388                             self.DebugThreadSlowDownLock.acquire()
       
  1389             elif debug_vars is not None:
  1384             elif debug_vars is not None:
  1390                 wx.CallAfter(self.logger.write_warning, 
  1385                 wx.CallAfter(self.logger.write_warning, 
  1391                              "debug data not coherent %d != %d"%(len(debug_vars), len(self.TracedIECPath)))
  1386                              "debug data not coherent %d != %d"%(len(debug_vars), len(self.TracedIECPath)))
  1392             elif debug_tick == -1:
  1387             elif debug_tick == -1:
  1393                 #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
  1388                 #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
  1394                 pass
  1389                 pass
  1395             else:
  1390             else:
  1396                 wx.CallAfter(self.logger.write, "Debugger disabled\n")
  1391                 wx.CallAfter(self.logger.write, "Debugger disabled\n")
  1397                 break
  1392                 _break = True
  1398             self.IECdebug_lock.release()
  1393             self.IECdebug_lock.release()
       
  1394             wx.CallAfter(self.DebugThreadSlowDownLock.release)
       
  1395             self.DebugThreadSlowDownLock.acquire()
  1399 
  1396 
  1400     def _Debug(self):
  1397     def _Debug(self):
  1401         """
  1398         """
  1402         Start PLC (Debug Mode)
  1399         Start PLC (Debug Mode)
  1403         """
  1400         """
  1422 #        # debug code
  1419 #        # debug code
  1423 #        self.temporary_non_weak_callable_refs = []
  1420 #        self.temporary_non_weak_callable_refs = []
  1424 #        for IEC_Path, idx in self._IECPathToIdx.iteritems():
  1421 #        for IEC_Path, idx in self._IECPathToIdx.iteritems():
  1425 #            class tmpcls:
  1422 #            class tmpcls:
  1426 #                def __init__(_self):
  1423 #                def __init__(_self):
  1427 #                    self.buf = None
  1424 #                    _self.buf = None
  1428 #                def setbuf(_self,buf):
  1425 #                def setbuf(_self,buf):
  1429 #                    self.buf = buf
  1426 #                    _self.buf = buf
  1430 #                def SetValue(_self, value, idx, name):
  1427 #                def SetValue(_self, value, idx, name):
  1431 #                    self.logger.write("debug call: %s %d %s\n"%(repr(value), idx, name))
  1428 #                    self.logger.write("debug call: %s %d %s\n"%(repr(value), idx, name))
  1432 #                    #self.logger.write("debug call: %s %d %s %s\n"%(repr(value), idx, name, repr(self.buf)))
  1429 #                    #self.logger.write("debug call: %s %d %s %s\n"%(repr(value), idx, name, repr(self.buf)))
  1433 #            a = tmpcls()
  1430 #            a = tmpcls()
  1434 #            res = self.SubscribeDebugIECVariable(IEC_Path, a, idx, IEC_Path)
  1431 #            res = self.SubscribeDebugIECVariable(IEC_Path, a, idx, IEC_Path)