plugger.py
changeset 446 1edde533db19
parent 440 f122eb4248b6
child 447 af3399aca7b7
equal deleted inserted replaced
441:379c66468cf6 446:1edde533db19
   777         self.ProjectPath = None
   777         self.ProjectPath = None
   778         self._setBuildPath(None)
   778         self._setBuildPath(None)
   779         self.DebugThread = None
   779         self.DebugThread = None
   780         self.debug_break = False
   780         self.debug_break = False
   781         self.previous_plcstate = None
   781         self.previous_plcstate = None
   782         self.StatusPrint = {"Broken": self.logger.write_error,
       
   783                             None: lambda x: None}
       
   784         # copy PluginMethods so that it can be later customized
   782         # copy PluginMethods so that it can be later customized
   785         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
   783         self.PluginMethods = [dic.copy() for dic in self.PluginMethods]
   786         self.LoadSTLibrary()
   784         self.LoadSTLibrary()
   787 
   785 
   788     def __del__(self):
   786     def __del__(self):
  1527         # TODO : use explicit status instead of boolean
  1525         # TODO : use explicit status instead of boolean
  1528         if self._connector is not None:
  1526         if self._connector is not None:
  1529             status = self._connector.GetPLCstatus()
  1527             status = self._connector.GetPLCstatus()
  1530         else:
  1528         else:
  1531             status = "Disconnected"
  1529             status = "Disconnected"
  1532         for args in {
  1530         if(self.previous_plcstate != status):
  1533                  "Starting" :    [("_Run", True),
  1531             for args in {
  1534                                   ("_Debug", True),
  1532                      "Started" :     [("_Run", False),
  1535                                   ("_Stop", False)],
  1533                                       ("_Debug", False),
  1536                  "Started" :     [("_Run", False),
  1534                                       ("_Stop", True)],
  1537                                   ("_Debug", False),
  1535                      "Stopped" :     [("_Run", True),
  1538                                   ("_Stop", True)],
  1536                                       ("_Debug", True),
  1539                  "Stopped" :     [("_Run", True),
  1537                                       ("_Stop", False)],
  1540                                   ("_Debug", True),
  1538                      "Empty" :       [("_Run", False),
  1541                                   ("_Stop", False)],
  1539                                       ("_Debug", False),
  1542                  "Empty" :       [("_Run", False),
  1540                                       ("_Stop", False)],
  1543                                   ("_Debug", False),
  1541                      "Broken" :      [],
  1544                                   ("_Stop", False)],
  1542                      "Disconnected" :[("_Run", False),
  1545                  "Broken" :      [("_Run", True),
  1543                                       ("_Debug", False),
  1546                                   ("_Debug", True),
  1544                                       ("_Stop", False),
  1547                                   ("_Stop", False)],
  1545                                       ("_Transfer", False),
  1548                  "Disconnected" :[("_Run", False),
  1546                                       ("_Connect", True),
  1549                                   ("_Debug", False),
  1547                                       ("_Disconnect", False)],
  1550                                   ("_Stop", False),
  1548                    }.get(status,[]):
  1551                                   ("_Transfer", False),
  1549                 self.ShowMethod(*args)
  1552                                   ("_Connect", True),
  1550             self.previous_plcstate = status
  1553                                   ("_Disconnect", False)],
  1551             return True
  1554                }.get(status,[]):
  1552         return False
  1555             self.ShowMethod(*args)
  1553     
  1556         return status
  1554     def PullPLCStatusProc(self, event):
  1557     
       
  1558     def PullPLCStatusProc(self, event): 
       
  1559         if self._connector is None:
  1555         if self._connector is None:
  1560             self.StatusTimer.Stop()
  1556             self.StatusTimer.Stop()
  1561         current_status = self.UpdateMethodsFromPLCStatus()
  1557         if self.UpdateMethodsFromPLCStatus():
  1562         if current_status != self.previous_plcstate:
  1558             status = _(self.previous_plcstate)
  1563             self.previous_plcstate = current_status
  1559             {"Broken": self.logger.write_error,
  1564             if current_status is not None:
  1560              None: lambda x: None}.get(
  1565                 status = _(current_status)
  1561                 self.previous_plcstate, self.logger.write)(_("PLC is %s\n")%status)
  1566             else:
       
  1567                 status = ""
       
  1568             self.StatusPrint.get(current_status, self.logger.write)(_("PLC is %s\n")%status)
       
  1569             self.AppFrame.RefreshAll()
  1562             self.AppFrame.RefreshAll()
  1570         
  1563         
  1571     def _Run(self):
  1564     def _Run(self):
  1572         """
  1565         """
  1573         Start PLC
  1566         Start PLC
  1679         This thread waid PLC debug data, and dispatch them to subscribers
  1672         This thread waid PLC debug data, and dispatch them to subscribers
  1680         """
  1673         """
  1681         # This lock is used to avoid flooding wx event stack calling callafter
  1674         # This lock is used to avoid flooding wx event stack calling callafter
  1682         self.debug_break = False
  1675         self.debug_break = False
  1683         while (not self.debug_break) and (self._connector is not None):
  1676         while (not self.debug_break) and (self._connector is not None):
  1684             debug_tick, debug_vars = self._connector.GetTraceVariables()
  1677             plc_status, debug_tick, debug_vars = self._connector.GetTraceVariables()
  1685             #print debug_tick, debug_vars
  1678             #print debug_tick, debug_vars
  1686             self.IECdebug_lock.acquire()
  1679             self.IECdebug_lock.acquire()
  1687             if debug_vars is not None and \
  1680             if debug_vars is not None:
  1688                len(debug_vars) == len(self.TracedIECPath):
  1681                 if len(debug_vars) == len(self.TracedIECPath):
  1689                 for IECPath,value in zip(self.TracedIECPath, debug_vars):
  1682                     for IECPath,value in zip(self.TracedIECPath, debug_vars):
  1690                     if value is not None:
  1683                         if value is not None:
  1691                         self.CallWeakcallables(IECPath, "NewValue", debug_tick, value)
  1684                             self.CallWeakcallables(IECPath, "NewValue", debug_tick, value)
  1692                 self.CallWeakcallables("__tick__", "NewDataAvailable")
  1685                     self.CallWeakcallables("__tick__", "NewDataAvailable")
  1693             elif debug_vars is not None:
  1686                 else :
  1694                 wx.CallAfter(self.logger.write_warning, 
  1687                     wx.CallAfter(self.logger.write_warning, 
  1695                              _("Debug data not coherent %d != %d\n")%(len(debug_vars), len(self.TracedIECPath)))
  1688                                  _("Debug data do not match requested variable count %d != %d\n")%(len(debug_vars), len(self.TracedIECPath)))
  1696             elif debug_tick == -1:
       
  1697                 #wx.CallAfter(self.logger.write, "Debugger unavailable\n")
       
  1698                 pass
       
  1699             else:
  1689             else:
  1700                 if self._connector.PLCIsStarting():
  1690                 if plc_status == "Started":
       
  1691                     # Be patient, tollerate PLC to come up before debugging
  1701                     time.sleep(0.01)
  1692                     time.sleep(0.01)
  1702                 else:
  1693                 else:
  1703                     wx.CallAfter(self.logger.write, _("Debugger disabled\n"))
  1694                     wx.CallAfter(self.logger.write, _("Debugger disabled\n"))
  1704                     self.debug_break = True
  1695                     self.debug_break = True
  1705             self.IECdebug_lock.release()
  1696             self.IECdebug_lock.release()
  1802             self.ShowMethod("_Transfer", True)
  1793             self.ShowMethod("_Transfer", True)
  1803 
  1794 
  1804             self.CompareLocalAndRemotePLC()
  1795             self.CompareLocalAndRemotePLC()
  1805             
  1796             
  1806             # Init with actual PLC status and print it
  1797             # Init with actual PLC status and print it
  1807             self.previous_plcstate = self.UpdateMethodsFromPLCStatus()
  1798             self.UpdateMethodsFromPLCStatus()
  1808             if self.previous_plcstate is not None:
  1799             if self.previous_plcstate is not None:
  1809                 status = _(self.previous_plcstate)
  1800                 status = _(self.previous_plcstate)
  1810             else:
  1801             else:
  1811                 status = ""
  1802                 status = ""
  1812             self.logger.write(_("PLC is %s\n")%status)
  1803             self.logger.write(_("PLC is %s\n")%status)