etherlab/etherlab.py
changeset 2102 90031b8db62d
parent 2101 da450992572e
child 2103 5a82d40c4b04
equal deleted inserted replaced
2101:da450992572e 2102:90031b8db62d
     8 from xmlclass import *
     8 from xmlclass import *
     9 from POULibrary import POULibrary
     9 from POULibrary import POULibrary
    10 from ConfigTreeNode import ConfigTreeNode
    10 from ConfigTreeNode import ConfigTreeNode
    11 from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    11 from PLCControler import UndoBuffer, LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    12 from ConfigEditor import NodeEditor, CIA402NodeEditor, MasterEditor, LibraryEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
    12 from ConfigEditor import NodeEditor, CIA402NodeEditor, MasterEditor, LibraryEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
       
    13 from dialogs import BrowseValuesLibraryDialog
       
    14 from IDEFrame import TITLE, FILEMENU, PROJECTTREE
    13 
    15 
    14 try:
    16 try:
    15     from MotionLibrary import Headers, AxisXSD
    17     from MotionLibrary import Headers, AxisXSD
    16     HAS_MCL = True
    18     HAS_MCL = True
    17 except:
    19 except:
   635         if config_is_saved and process_is_saved:
   637         if config_is_saved and process_is_saved:
   636             self.CreateBuffer(True)
   638             self.CreateBuffer(True)
   637         else:
   639         else:
   638             self.CreateBuffer(False)
   640             self.CreateBuffer(False)
   639             self.OnCTNSave()
   641             self.OnCTNSave()
   640 
   642     
       
   643     def GetContextualMenuItems(self):
       
   644         return [("Add Ethercat Slave", "Add Ethercat Slave to Master", self.OnAddEthercatSlave)]
       
   645     
       
   646     def OnAddEthercatSlave(self, event):
       
   647         app_frame = self.GetCTRoot().AppFrame
       
   648         dialog = BrowseValuesLibraryDialog(app_frame, 
       
   649             "Ethercat Slave Type", self.GetSlaveTypesLibrary())
       
   650         if dialog.ShowModal() == wx.ID_OK:
       
   651             type_infos = dialog.GetValueInfos()
       
   652             device, alignment = self.GetModuleInfos(type_infos)
       
   653             if device is not None:
       
   654                 if HAS_MCL and _EthercatCIA402SlaveCTN.NODE_PROFILE in device.GetProfileNumbers():
       
   655                     ConfNodeType = "EthercatCIA402Slave"
       
   656                 else:
       
   657                     ConfNodeType = "EthercatSlave"
       
   658                 new_child = self.CTNAddChild("%s_0" % ConfNodeType, ConfNodeType)
       
   659                 new_child.SetParamsAttribute("SlaveParams.Type", type_infos)
       
   660                 self.CTNRequestSave()
       
   661                 app_frame._Refresh(TITLE, FILEMENU, PROJECTTREE)
       
   662         dialog.Destroy()
       
   663     
   641     def ExtractHexDecValue(self, value):
   664     def ExtractHexDecValue(self, value):
   642         return ExtractHexDecValue(value)
   665         return ExtractHexDecValue(value)
   643 
   666 
   644     def GetSizeOfType(self, type):
   667     def GetSizeOfType(self, type):
   645         return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)
   668         return TYPECONVERSION.get(self.GetCTRoot().GetBaseType(type), None)