LPCBeremiz.py
changeset 691 bb340874f09e
parent 684 d376a8b0b602
child 697 3e83853081d4
equal deleted inserted replaced
690:ef60d7e188e6 691:bb340874f09e
    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 plugger import PluginsRoot, PlugTemplate, opjimg, connectors
    62 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors
    63 from plugins.canfestival import RootClass as CanOpenRootClass
       
    64 from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager
       
    65 from plcopen.structures import LOCATIONDATATYPES
    63 from plcopen.structures import LOCATIONDATATYPES
    66 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
    64 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
    67                          LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    65                          LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    68 from PLCOpenEditor import IDEFrame, ProjectDialog
    66 from PLCOpenEditor import IDEFrame, ProjectDialog
       
    67 
       
    68 havecanfestival = False
       
    69 try:
       
    70     from plugins.canfestival import RootClass as CanOpenRootClass
       
    71     from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager
       
    72     havecanfestival = True
       
    73 except:
       
    74     havecanfestival = False
       
    75     
    69 
    76 
    70 #-------------------------------------------------------------------------------
    77 #-------------------------------------------------------------------------------
    71 #                          CANFESTIVAL PLUGIN HACK
    78 #                          CANFESTIVAL PLUGIN HACK
    72 #-------------------------------------------------------------------------------
    79 #-------------------------------------------------------------------------------
    73 # from plugins.canfestival import canfestival
    80 # from plugins.canfestival import canfestival
   361 
   368 
   362 #-------------------------------------------------------------------------------
   369 #-------------------------------------------------------------------------------
   363 #                          LPC CanFestival Plugin Class
   370 #                          LPC CanFestival Plugin Class
   364 #-------------------------------------------------------------------------------
   371 #-------------------------------------------------------------------------------
   365 
   372 
   366 DEFAULT_SETTINGS = {
   373 if havecanfestival:
   367     "CAN_Baudrate": "125K",
   374 
   368     "Slave_NodeId": 2,
   375     DEFAULT_SETTINGS = {
   369     "Master_NodeId": 1,
   376         "CAN_Baudrate": "125K",
   370 }
   377         "Slave_NodeId": 2,
   371 
   378         "Master_NodeId": 1,
   372 class LPCCanOpenSlave(_SlavePlug):
   379     }
   373     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   380     
   374     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   381     class LPCCanOpenSlave(_SlavePlug):
   375       <xsd:element name="CanFestivalSlaveNode">
   382         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   376         <xsd:complexType>
   383         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   377           <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
   384           <xsd:element name="CanFestivalSlaveNode">
   378           <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/>
   385             <xsd:complexType>
   379           <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/>
   386               <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
   380           <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50">
   387               <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/>
   381             <xsd:simpleType>
   388               <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/>
   382                 <xsd:restriction base="xsd:integer">
   389               <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50">
   383                     <xsd:minInclusive value="1"/>
   390                 <xsd:simpleType>
   384                     <xsd:maxInclusive value="99"/>
   391                     <xsd:restriction base="xsd:integer">
   385                 </xsd:restriction>
   392                         <xsd:minInclusive value="1"/>
   386             </xsd:simpleType>
   393                         <xsd:maxInclusive value="99"/>
   387           </xsd:attribute>
   394                     </xsd:restriction>
   388         </xsd:complexType>
   395                 </xsd:simpleType>
   389       </xsd:element>
   396               </xsd:attribute>
   390     </xsd:schema>
   397             </xsd:complexType>
   391     """ % DEFAULT_SETTINGS
   398           </xsd:element>
   392     
   399         </xsd:schema>
   393     def __init__(self):
   400         """ % DEFAULT_SETTINGS
   394         # TODO change netname when name change
   401         
   395         NodeManager.__init__(self)
   402         def __init__(self):
   396         odfilepath = self.GetSlaveODPath()
   403             # TODO change netname when name change
   397         if(os.path.isfile(odfilepath)):
   404             NodeManager.__init__(self)
   398             self.OpenFileInCurrent(odfilepath)
   405             odfilepath = self.GetSlaveODPath()
   399         else:
   406             if(os.path.isfile(odfilepath)):
   400             self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
   407                 self.OpenFileInCurrent(odfilepath)
   401                                0x00,         # NodeID - will be changed at build time
   408             else:
   402                                "slave",      # Type
   409                 self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
   403                                "",           # description 
   410                                    0x00,         # NodeID - will be changed at build time
   404                                "None",       # profile
   411                                    "slave",      # Type
   405                                "", # prfile filepath
   412                                    "",           # description 
   406                                "heartbeat",  # NMT
   413                                    "None",       # profile
   407                                [])           # options
   414                                    "", # prfile filepath
   408             self.OnPlugSave()
   415                                    "heartbeat",  # NMT
   409     
   416                                    [])           # options
   410     def GetCanDevice(self):
   417                 self.OnPlugSave()
   411         return str(self.BaseParams.getIEC_Channel())
   418         
   412     
   419         def GetCanDevice(self):
   413 class LPCCanOpenMaster(_NodeListPlug):
   420             return str(self.BaseParams.getIEC_Channel())
   414     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   421         
   415     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   422     class LPCCanOpenMaster(_NodeListPlug):
   416       <xsd:element name="CanFestivalNode">
   423         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   417         <xsd:complexType>
   424         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   418           <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
   425           <xsd:element name="CanFestivalNode">
   419           <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/>
   426             <xsd:complexType>
   420           <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
   427               <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
   421         </xsd:complexType>
   428               <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/>
   422       </xsd:element>
   429               <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
   423     </xsd:schema>
   430             </xsd:complexType>
   424     """ % DEFAULT_SETTINGS
   431           </xsd:element>
   425 
   432         </xsd:schema>
   426     def GetCanDevice(self):
   433         """ % DEFAULT_SETTINGS
   427         return str(self.BaseParams.getIEC_Channel())
   434     
   428 
   435         def GetCanDevice(self):
   429 class LPCCanOpen(CanOpenRootClass):
   436             return str(self.BaseParams.getIEC_Channel())
   430     XSD = None
   437     
   431     PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"),
   438     class LPCCanOpen(CanOpenRootClass):
   432                        ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")]
   439         XSD = None
   433     
   440         PlugChildsTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"),
   434     def GetCanDriver(self):
   441                            ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")]
   435         return ""
   442         
   436     
   443         def GetCanDriver(self):
   437     def LoadChilds(self):
   444             return ""
   438         PlugTemplate.LoadChilds(self)
   445         
   439         
   446         def LoadChilds(self):
   440         if self.GetChildByName("Master") is None:
   447             PlugTemplate.LoadChilds(self)
   441             master = self.PlugAddChild("Master", "CanOpenNode", 0)
   448             
   442             master.BaseParams.setEnabled(False)
   449             if self.GetChildByName("Master") is None:
   443         
   450                 master = self.PlugAddChild("Master", "CanOpenNode", 0)
   444         if self.GetChildByName("Slave") is None:
   451                 master.BaseParams.setEnabled(False)
   445             slave = self.PlugAddChild("Slave", "CanOpenSlave", 1)
   452             
   446             slave.BaseParams.setEnabled(False)
   453             if self.GetChildByName("Slave") is None:
       
   454                 slave = self.PlugAddChild("Slave", "CanOpenSlave", 1)
       
   455                 slave.BaseParams.setEnabled(False)
   447     
   456     
   448 
   457 
   449 #-------------------------------------------------------------------------------
   458 #-------------------------------------------------------------------------------
   450 #                              LPCPluginsRoot Class
   459 #                              LPCPluginsRoot Class
   451 #-------------------------------------------------------------------------------
   460 #-------------------------------------------------------------------------------
   501     def __init__(self, frame, logger, buildpath):
   510     def __init__(self, frame, logger, buildpath):
   502         self.OrigBuildPath = buildpath
   511         self.OrigBuildPath = buildpath
   503         
   512         
   504         PluginsRoot.__init__(self, frame, logger)
   513         PluginsRoot.__init__(self, frame, logger)
   505         
   514         
   506         self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
   515         if havecanfestival:
       
   516             self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
       
   517         else:
       
   518             self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
   507         self.PlugType = "LPC"
   519         self.PlugType = "LPC"
   508         
   520         
   509         self.OnlineMode = "OFF"
   521         self.OnlineMode = "OFF"
   510         self.LPCConnector = None
   522         self.LPCConnector = None
   511         
   523         
   680             if result:
   692             if result:
   681                 return result
   693                 return result
   682             #Load and init all the childs
   694             #Load and init all the childs
   683             self.LoadChilds()
   695             self.LoadChilds()
   684         
   696         
   685         if self.GetChildByName("CanOpen") is None:
   697         if havecanfestival and self.GetChildByName("CanOpen") is None:
   686             canopen = self.PlugAddChild("CanOpen", "CanOpen", 0)
   698             canopen = self.PlugAddChild("CanOpen", "CanOpen", 0)
   687             canopen.BaseParams.setEnabled(False)
   699             canopen.BaseParams.setEnabled(False)
   688             canopen.LoadChilds()
   700             canopen.LoadChilds()
   689         
   701         
   690         if self.PlugTestModified():
   702         if self.PlugTestModified():
   898             self.ProgramTransferred()
   910             self.ProgramTransferred()
   899 
   911 
   900     def ResetBuildMD5(self):
   912     def ResetBuildMD5(self):
   901         builder=self.GetBuilder()
   913         builder=self.GetBuilder()
   902         if builder is not None:
   914         if builder is not None:
   903             builder.ResetBinaryCodeMD5()
   915             builder.ResetBinaryCodeMD5(self.OnlineMode)
   904         
   916         
   905     def GetLastBuildMD5(self):
   917     def GetLastBuildMD5(self):
   906         builder=self.GetBuilder()
   918         builder=self.GetBuilder()
   907         if builder is not None:
   919         if builder is not None:
   908             return builder.GetBinaryCodeMD5(self.OnlineMode)
   920             return builder.GetBinaryCodeMD5(self.OnlineMode)
   925                 else:
   937                 else:
   926                     self.logger.write(_("Resetting PLC\n"))
   938                     self.logger.write(_("Resetting PLC\n"))
   927                     #self.StatusTimer.Stop()
   939                     #self.StatusTimer.Stop()
   928                     self.LPCConnector.ResetPLC()
   940                     self.LPCConnector.ResetPLC()
   929                     self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
   941                     self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
       
   942             
       
   943             else:
       
   944                 self.CurrentMode = None
   930     
   945     
   931     def BeginTransfer(self):
   946     def BeginTransfer(self):
   932         self.logger.write(_("Start PLC transfer\n"))
   947         self.logger.write(_("Start PLC transfer\n"))
   933         
   948         
   934         self.AbortTransferTimer.Stop()
   949         self.AbortTransferTimer.Stop()
  1365             new_properties["projectName"] = projectname
  1380             new_properties["projectName"] = projectname
  1366             new_properties["productName"] = productname
  1381             new_properties["productName"] = productname
  1367             new_properties["productVersion"] = productversion
  1382             new_properties["productVersion"] = productversion
  1368             new_properties["companyName"] = companyname
  1383             new_properties["companyName"] = companyname
  1369             if new_properties != properties:
  1384             if new_properties != properties:
  1370                 self.PluginRoot.SetProjectProperties(properties=new_properties)
  1385                 self.PluginRoot.SetProjectProperties(properties=new_properties, buffer=False)
  1371                 self.RestartTimer()
  1386                 self.RestartTimer()
  1372         
  1387         
  1373         def SetOnlineMode(self, mode, path=None):
  1388         def SetOnlineMode(self, mode, path=None):
  1374             self.PluginRoot.SetOnlineMode(mode, path)
  1389             self.PluginRoot.SetOnlineMode(mode, path)
  1375             self.RestartTimer()
  1390             self.RestartTimer()