LPCBeremiz.py
changeset 725 31dade089db5
parent 721 ecf4d203c4d4
child 730 4480b7da6bea
equal deleted inserted replaced
724:e0630d262ac3 725:31dade089db5
    57 
    57 
    58 if __name__ == '__main__':
    58 if __name__ == '__main__':
    59     __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
    59     __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
    60 
    60 
    61 from Beremiz import *
    61 from Beremiz import *
    62 from ConfigTree import ConfigTreeRoot, ConfigTreeNode, opjimg, connectors
    62 from ProjectController import ProjectController
       
    63 from ConfigTreeNode import ConfigTreeNode
       
    64 import connectors
       
    65 from util import opjimg
    63 from plcopen.structures import LOCATIONDATATYPES
    66 from plcopen.structures import LOCATIONDATATYPES
    64 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\
    67 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\
    65                          LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    68                          LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    66 from PLCOpenEditor import IDEFrame, ProjectDialog
    69 from PLCOpenEditor import IDEFrame, ProjectDialog
    67 
    70 
   454                 slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
   457                 slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
   455                 slave.BaseParams.setEnabled(False)
   458                 slave.BaseParams.setEnabled(False)
   456     
   459     
   457 
   460 
   458 #-------------------------------------------------------------------------------
   461 #-------------------------------------------------------------------------------
   459 #                              LPCConfigTreeRoot Class
   462 #                              LPCProjectController Class
   460 #-------------------------------------------------------------------------------
   463 #-------------------------------------------------------------------------------
   461 
   464 
   462 def mycopytree(src, dst):
   465 def mycopytree(src, dst):
   463     """
   466     """
   464     Copy content of a directory to an other, omit hidden files
   467     Copy content of a directory to an other, omit hidden files
   477             elif os.path.isfile(srcpath):
   480             elif os.path.isfile(srcpath):
   478                 shutil.copy2(srcpath, dstpath)
   481                 shutil.copy2(srcpath, dstpath)
   479 
   482 
   480 [SIMULATION_MODE, TRANSFER_MODE] = range(2)
   483 [SIMULATION_MODE, TRANSFER_MODE] = range(2)
   481 
   484 
   482 class LPCConfigTreeRoot(ConfigTreeRoot):
   485 class LPCProjectController(ProjectController):
   483 
   486 
   484     ConfNodeMethods = [
   487     ConfNodeMethods = [
   485         {"bitmap" : opjimg("Debug"),
   488         {"bitmap" : opjimg("Debug"),
   486          "name" : _("Simulate"),
   489          "name" : _("Simulate"),
   487          "tooltip" : _("Simulate PLC"),
   490          "tooltip" : _("Simulate PLC"),
   508     ]
   511     ]
   509 
   512 
   510     def __init__(self, frame, logger, buildpath):
   513     def __init__(self, frame, logger, buildpath):
   511         self.OrigBuildPath = buildpath
   514         self.OrigBuildPath = buildpath
   512         
   515         
   513         ConfigTreeRoot.__init__(self, frame, logger)
   516         ProjectController.__init__(self, frame, logger)
   514         
   517         
   515         if havecanfestival:
   518         if havecanfestival:
   516             self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
   519             self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
   517         else:
   520         else:
   518             self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
   521             self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
   530     
   533     
   531     def ConfNodeLibraryFilePath(self):
   534     def ConfNodeLibraryFilePath(self):
   532         if self.OrigBuildPath is not None:
   535         if self.OrigBuildPath is not None:
   533             return os.path.join(self.OrigBuildPath, "pous.xml")
   536             return os.path.join(self.OrigBuildPath, "pous.xml")
   534         else:
   537         else:
   535             return ConfigTreeRoot.ConfNodeLibraryFilePath(self)
   538             return ProjectController.ConfNodeLibraryFilePath(self)
   536     
   539     
   537     def GetProjectName(self):
   540     def GetProjectName(self):
   538         return self.Project.getname()
   541         return self.Project.getname()
   539 
   542 
   540     def GetDefaultTargetName(self):
   543     def GetDefaultTargetName(self):
   541         if self.CurrentMode == SIMULATION_MODE:
   544         if self.CurrentMode == SIMULATION_MODE:
   542             return ConfigTreeRoot.GetDefaultTargetName(self)
   545             return ProjectController.GetDefaultTargetName(self)
   543         else:
   546         else:
   544             return "LPC"
   547             return "LPC"
   545 
   548 
   546     def GetTarget(self):
   549     def GetTarget(self):
   547         target = ConfigTreeRoot.GetTarget(self)
   550         target = ProjectController.GetTarget(self)
   548         if self.CurrentMode != SIMULATION_MODE:
   551         if self.CurrentMode != SIMULATION_MODE:
   549             target.getcontent()["value"].setBuildPath(self.BuildPath)
   552             target.getcontent()["value"].setBuildPath(self.BuildPath)
   550         return target
   553         return target
   551     
   554     
   552     def _getBuildPath(self):
   555     def _getBuildPath(self):
   553         if self.CurrentMode == SIMULATION_MODE:
   556         if self.CurrentMode == SIMULATION_MODE:
   554             if self.SimulationBuildPath is None:
   557             if self.SimulationBuildPath is None:
   555                 self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build")
   558                 self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build")
   556             return self.SimulationBuildPath
   559             return self.SimulationBuildPath
   557         else:
   560         else:
   558             return ConfigTreeRoot._getBuildPath(self)
   561             return ProjectController._getBuildPath(self)
   559 
   562 
   560     def _Build(self):
   563     def _Build(self):
   561         save = self.ProjectTestModified()
   564         save = self.ProjectTestModified()
   562         if save:
   565         if save:
   563             self.SaveProject()
   566             self.SaveProject()
   564             self.AppFrame._Refresh(TITLE, FILEMENU)
   567             self.AppFrame._Refresh(TITLE, FILEMENU)
   565         if self.BuildPath is not None:
   568         if self.BuildPath is not None:
   566             mycopytree(self.OrigBuildPath, self.BuildPath)
   569             mycopytree(self.OrigBuildPath, self.BuildPath)
   567         ConfigTreeRoot._Build(self)
   570         ProjectController._Build(self)
   568         if save:
   571         if save:
   569             wx.CallAfter(self.AppFrame.RefreshAll)
   572             wx.CallAfter(self.AppFrame.RefreshAll)
   570     
   573     
   571     def SetProjectName(self, name):
   574     def SetProjectName(self, name):
   572         return self.Project.setname(name)
   575         return self.Project.setname(name)
   968     def StopSimulation(self):
   971     def StopSimulation(self):
   969         self.CurrentMode = None
   972         self.CurrentMode = None
   970         self.ApplyOnlineMode()
   973         self.ApplyOnlineMode()
   971     
   974     
   972     def _Stop(self):
   975     def _Stop(self):
   973         ConfigTreeRoot._Stop(self)
   976         ProjectController._Stop(self)
   974         
   977         
   975         if self.CurrentMode == SIMULATION_MODE:
   978         if self.CurrentMode == SIMULATION_MODE:
   976             self.StopSimulation()
   979             self.StopSimulation()
   977 
   980 
   978     def CompareLocalAndRemotePLC(self):
   981     def CompareLocalAndRemotePLC(self):
   999 
  1002 
  1000     def _Transfer(self):
  1003     def _Transfer(self):
  1001         if self.CurrentMode is None and self.OnlineMode != "OFF":
  1004         if self.CurrentMode is None and self.OnlineMode != "OFF":
  1002             self.CurrentMode = TRANSFER_MODE
  1005             self.CurrentMode = TRANSFER_MODE
  1003             
  1006             
  1004             if ConfigTreeRoot._Build(self):
  1007             if ProjectController._Build(self):
  1005             
  1008             
  1006                 ID_ABORTTRANSFERTIMER = wx.NewId()
  1009                 ID_ABORTTRANSFERTIMER = wx.NewId()
  1007                 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
  1010                 self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
  1008                 self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)  
  1011                 self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)  
  1009                 
  1012                 
  1021     
  1024     
  1022     def BeginTransfer(self):
  1025     def BeginTransfer(self):
  1023         self.logger.write(_("Start PLC transfer\n"))
  1026         self.logger.write(_("Start PLC transfer\n"))
  1024         
  1027         
  1025         self.AbortTransferTimer.Stop()
  1028         self.AbortTransferTimer.Stop()
  1026         ConfigTreeRoot._Transfer(self)
  1029         ProjectController._Transfer(self)
  1027         self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
  1030         self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
  1028     
  1031     
  1029     def AbortTransfer(self, event):
  1032     def AbortTransfer(self, event):
  1030         self.logger.write_warning(_("Timeout waiting PLC to recover\n"))
  1033         self.logger.write_warning(_("Timeout waiting PLC to recover\n"))
  1031         
  1034         
  1741         lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
  1744         lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
  1742         lpcberemiz_cmd.cmdloop()
  1745         lpcberemiz_cmd.cmdloop()
  1743 
  1746 
  1744     Log = StdoutPseudoFile(port)
  1747     Log = StdoutPseudoFile(port)
  1745 
  1748 
  1746     CTR = LPCConfigTreeRoot(None, Log, buildpath)
  1749     CTR = LPCProjectController(None, Log, buildpath)
  1747     if projectOpen is not None and os.path.isdir(projectOpen):
  1750     if projectOpen is not None and os.path.isdir(projectOpen):
  1748         result = CTR.LoadProject(projectOpen)
  1751         result = CTR.LoadProject(projectOpen)
  1749         if result:
  1752         if result:
  1750             Log.write("Error: Invalid project directory", result)
  1753             Log.write("Error: Invalid project directory", result)
  1751     else:
  1754     else: