plugger.py
changeset 286 a2a8a52b0d4f
parent 283 d0e6fc0701fb
child 288 7ee96191c476
equal deleted inserted replaced
285:e5782a52dcea 286:a2a8a52b0d4f
   698         # After __init__ root plugin is not valid
   698         # After __init__ root plugin is not valid
   699         self.ProjectPath = None
   699         self.ProjectPath = None
   700         self.BuildPath = None
   700         self.BuildPath = None
   701         self.PLCEditor = None
   701         self.PLCEditor = None
   702         self.PLCDebug = None
   702         self.PLCDebug = None
       
   703         self.DebugThread = None
       
   704         self.debug_break = False
   703         # copy PluginMethods so that it can be later customized
   705         # copy PluginMethods so that it can be later customized
   704         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
   706         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
   705 
   707 
   706     def PluginLibraryFilePath(self, PlugName=None):
   708     def PluginLibraryFilePath(self, PlugName=None):
   707         return os.path.join(os.path.join(os.path.split(__file__)[0], "pous.xml"))
   709         return os.path.join(os.path.join(os.path.split(__file__)[0], "pous.xml"))
  1307             shutil.rmtree(os.path.join(self._getBuildPath()))
  1309             shutil.rmtree(os.path.join(self._getBuildPath()))
  1308         else:
  1310         else:
  1309             self.logger.write_error("Build directory already clean\n")
  1311             self.logger.write_error("Build directory already clean\n")
  1310         self.ShowMethod("_showIECcode", False)
  1312         self.ShowMethod("_showIECcode", False)
  1311         self.EnableMethod("_Clean", False)
  1313         self.EnableMethod("_Clean", False)
       
  1314         # kill the builder
       
  1315         self._builder = None
  1312         self.CompareLocalAndRemotePLC()
  1316         self.CompareLocalAndRemotePLC()
  1313 
  1317 
  1314     ############# Real PLC object access #############
  1318     ############# Real PLC object access #############
  1315     def UpdateMethodsFromPLCStatus(self):
  1319     def UpdateMethodsFromPLCStatus(self):
  1316         # Get PLC state : Running or Stopped
  1320         # Get PLC state : Running or Stopped
  1432         """
  1436         """
  1433         This thread waid PLC debug data, and dispatch them to subscribers
  1437         This thread waid PLC debug data, and dispatch them to subscribers
  1434         """
  1438         """
  1435         # This lock is used to avoid flooding wx event stack calling callafter
  1439         # This lock is used to avoid flooding wx event stack calling callafter
  1436         self.DebugThreadSlowDownLock = Semaphore(0)
  1440         self.DebugThreadSlowDownLock = Semaphore(0)
  1437         _break = False
  1441         self.debug_break = False
  1438         while not _break and self._connector is not None:
  1442         while (not self.debug_break) and (self._connector is not None):
  1439             debug_tick, debug_vars = self._connector.GetTraceVariables()
  1443             debug_tick, debug_vars = self._connector.GetTraceVariables()
  1440             #print debug_tick, debug_vars
  1444             #print debug_tick, debug_vars
  1441             self.IECdebug_lock.acquire()
  1445             self.IECdebug_lock.acquire()
  1442             if debug_vars is not None and \
  1446             if debug_vars is not None and \
  1443                len(debug_vars) == len(self.TracedIECPath):
  1447                len(debug_vars) == len(self.TracedIECPath):
  1457             elif debug_tick == -1:
  1461             elif debug_tick == -1:
  1458                 #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
  1462                 #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
  1459                 pass
  1463                 pass
  1460             else:
  1464             else:
  1461                 wx.CallAfter(self.logger.write, "Debugger disabled\n")
  1465                 wx.CallAfter(self.logger.write, "Debugger disabled\n")
  1462                 _break = True
  1466                 self.debug_break = True
  1463             self.IECdebug_lock.release()
  1467             self.IECdebug_lock.release()
  1464             wx.CallAfter(self.DebugThreadSlowDownLock.release)
  1468             wx.CallAfter(self.DebugThreadSlowDownLock.release)
  1465             self.DebugThreadSlowDownLock.acquire()
  1469             self.DebugThreadSlowDownLock.acquire()
       
  1470 
       
  1471     def KillDebugThread(self):
       
  1472         self.debug_break = True
       
  1473         self.DebugThreadSlowDownLock.release()
       
  1474         self.DebugThread.join(timeout=1)
       
  1475         if self.DebugThread.isAlive():
       
  1476             self.logger.write_warning("Debug Thread couldn't be killed")
       
  1477         self.DebugThread = None
  1466 
  1478 
  1467     def _Debug(self):
  1479     def _Debug(self):
  1468         """
  1480         """
  1469         Start PLC (Debug Mode)
  1481         Start PLC (Debug Mode)
  1470         """
  1482         """
  1482             self.DebugThread = Thread(target=self.DebugThreadProc)
  1494             self.DebugThread = Thread(target=self.DebugThreadProc)
  1483             self.DebugThread.start()
  1495             self.DebugThread.start()
  1484         else:
  1496         else:
  1485             self.logger.write_error("Couldn't start PLC debug !\n")
  1497             self.logger.write_error("Couldn't start PLC debug !\n")
  1486         self.UpdateMethodsFromPLCStatus()
  1498         self.UpdateMethodsFromPLCStatus()
       
  1499 
  1487 
  1500 
  1488 #    def _Do_Test_Debug(self):
  1501 #    def _Do_Test_Debug(self):
  1489 #        # debug code
  1502 #        # debug code
  1490 #        self.temporary_non_weak_callable_refs = []
  1503 #        self.temporary_non_weak_callable_refs = []
  1491 #        for IEC_Path, idx in self._IECPathToIdx.iteritems():
  1504 #        for IEC_Path, idx in self._IECPathToIdx.iteritems():
  1504        
  1517        
  1505     def _Stop(self):
  1518     def _Stop(self):
  1506         """
  1519         """
  1507         Stop PLC
  1520         Stop PLC
  1508         """
  1521         """
       
  1522         if self.DebugThread is not None:
       
  1523             self.logger.write("Stopping debug\n")
       
  1524             self.KillDebugThread()
       
  1525         
  1509         if self._connector.StopPLC():
  1526         if self._connector.StopPLC():
  1510             self.logger.write("Stopping PLC\n")
  1527             self.logger.write("Stopping PLC\n")
  1511         else:
  1528         else:
  1512             self.logger.write_error("Couldn't stop PLC !\n")
  1529             self.logger.write_error("Couldn't stop PLC !\n")
  1513         self.UpdateMethodsFromPLCStatus()
  1530         self.UpdateMethodsFromPLCStatus()