etherlab/etherlab.py
changeset 2063 c9a1c5bb51cd
parent 2062 c485269ec443
child 2064 810013fe8c1b
equal deleted inserted replaced
2062:c485269ec443 2063:c9a1c5bb51cd
    60 #--------------------------------------------------
    60 #--------------------------------------------------
    61 #                    Ethercat Node
    61 #                    Ethercat Node
    62 #--------------------------------------------------
    62 #--------------------------------------------------
    63 
    63 
    64 class _EthercatSlaveCTN:
    64 class _EthercatSlaveCTN:
    65 
    65     
       
    66     XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
       
    67     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
       
    68       <xsd:element name="SlaveParams">
       
    69         <xsd:complexType>
       
    70           <xsd:attribute name="DynamicPDOs" type="xsd:boolean" use="optional" default="true"/>
       
    71         </xsd:complexType>
       
    72       </xsd:element>
       
    73     </xsd:schema>
       
    74     """
       
    75     
    66     NODE_PROFILE = None
    76     NODE_PROFILE = None
    67     EditorType = NodeEditor
    77     EditorType = NodeEditor
    68     
    78     
    69     def GetIconPath(self):
    79     def GetIconPath(self):
    70         return os.path.join(CONFNODEFOLDER, "images", "Slave.png")
    80         return os.path.join(CONFNODEFOLDER, "images", "Slave.png")
    85                 return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
    95                 return self.MandatoryParams[1].getElementInfos(parts[0], parts[1])
    86             elif self.CTNParams and parts[0] == self.CTNParams[0]:
    96             elif self.CTNParams and parts[0] == self.CTNParams[0]:
    87                 return self.CTNParams[1].getElementInfos(parts[0], parts[1])
    97                 return self.CTNParams[1].getElementInfos(parts[0], parts[1])
    88         else:
    98         else:
    89             params = []
    99             params = []
    90             if wx.VERSION < (2, 8, 0) and self.MandatoryParams:
   100             if self.CTNParams:
    91                 params.append(self.MandatoryParams[1].getElementInfos(self.MandatoryParams[0]))
   101                 params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
       
   102             else:
       
   103                 params.append({
       
   104                     'use': 'required', 
       
   105                     'type': 'element', 
       
   106                     'name': 'SlaveParams', 
       
   107                     'value': None, 
       
   108                     'children': []
       
   109                 })
       
   110             
    92             slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
   111             slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
    93             params.append({
   112             params[0]['children'].insert(0,
    94                 'use': 'required', 
   113                    {'use': 'optional', 
    95                 'type': 'element', 
       
    96                 'name': 'SlaveParams', 
       
    97                 'value': None, 
       
    98                 'children': [{
       
    99                     'use': 'optional', 
       
   100                     'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), 
   114                     'type': self.CTNParent.GetSlaveTypesLibrary(self.NODE_PROFILE), 
   101                     'name': 'Type', 
   115                     'name': 'Type', 
   102                     'value': (slave_type["device_type"], slave_type)}, 
   116                     'value': (slave_type["device_type"], slave_type)}) 
       
   117             params[0]['children'].insert(1,
   103                    {'use': 'optional', 
   118                    {'use': 'optional', 
   104                     'type': 'unsignedLong', 
   119                     'type': 'unsignedLong', 
   105                     'name': 'Alias', 
   120                     'name': 'Alias', 
   106                     'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())}]
   121                     'value': self.CTNParent.GetSlaveAlias(self.GetSlavePos())})
   107             })
       
   108             if self.CTNParams:
       
   109                 params.append(self.CTNParams[1].getElementInfos(self.CTNParams[0]))
       
   110             return params
   122             return params
   111         
   123         
   112     def SetParamsAttribute(self, path, value):
   124     def SetParamsAttribute(self, path, value):
       
   125         if path == "SlaveParams.Type":
       
   126             self.CTNParent.SetSlaveType(position, value)
       
   127             slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
       
   128             value = (slave_type["device_type"], slave_type)
       
   129             return value, True
       
   130         elif path == "SlaveParams.Alias":
       
   131             self.CTNParent.SetSlaveAlias(position, value)
       
   132             return value, True
       
   133         
   113         position = self.BaseParams.getIEC_Channel()
   134         position = self.BaseParams.getIEC_Channel()
   114         value, changed = ConfigTreeNode.SetParamsAttribute(self, path, value)
   135         value, changed = ConfigTreeNode.SetParamsAttribute(self, path, value)
   115         # Filter IEC_Channel, Slave_Type and Alias that have specific behavior
   136         # Filter IEC_Channel, Slave_Type and Alias that have specific behavior
   116         if path == "BaseParams.IEC_Channel":
   137         if path == "BaseParams.IEC_Channel":
   117             self.CTNParent.SetSlavePosition(position, value)
   138             self.CTNParent.SetSlavePosition(position, value)
   118         elif path == "SlaveParams.Type":
   139         
   119             self.CTNParent.SetSlaveType(position, value)
       
   120             slave_type = self.CTNParent.GetSlaveType(self.GetSlavePos())
       
   121             value = (slave_type["device_type"], slave_type)
       
   122             changed = True
       
   123         elif path == "SlaveParams.Alias":
       
   124             self.CTNParent.SetSlaveAlias(position, value)
       
   125             changed = True
       
   126         return value, changed
   140         return value, changed
   127 
   141 
   128     def GetSlaveInfos(self):
   142     def GetSlaveInfos(self):
   129         return self.CTNParent.GetSlaveInfos(self.GetSlavePos())
   143         return self.CTNParent.GetSlaveInfos(self.GetSlavePos())
   130     
   144     
   168     class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
   182     class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
   169         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   183         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   170         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   184         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   171           <xsd:element name="CIA402SlaveParams">
   185           <xsd:element name="CIA402SlaveParams">
   172             <xsd:complexType>
   186             <xsd:complexType>
       
   187               <xsd:attribute name="DynamicPDOs" type="xsd:boolean" use="optional" default="true"/>
   173               %s
   188               %s
   174             </xsd:complexType>
   189             </xsd:complexType>
   175           </xsd:element>
   190           </xsd:element>
   176         </xsd:schema>
   191         </xsd:schema>
   177         """ % AxisXSD
   192         """ % AxisXSD
   178         
   193         
   179         NODE_PROFILE = 402
   194         NODE_PROFILE = 402
   180         EditorType = CIA402NodeEditor
   195         EditorType = CIA402NodeEditor
   181         
   196         
   182         ConfNodeMethods = [
   197         ConfNodeMethods = [
   183             {"bitmap" : "CIA402AxisRef",
   198             {"bitmap" : os.path.join(CONFNODEFOLDER, "images", "CIA402AxisRef.png"),
   184              "name" : _("Axis Ref"),
   199              "name" : _("Axis Ref"),
   185              "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"),
   200              "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"),
   186              "method" : "_getCIA402AxisRef"},
   201              "method" : "_getCIA402AxisRef",
       
   202              "push": True},
   187         ]
   203         ]
   188         
   204         
   189         def GetIconPath(self):
   205         def GetIconPath(self):
   190             return os.path.join(CONFNODEFOLDER, "images", "CIA402Slave.png")
   206             return os.path.join(CONFNODEFOLDER, "images", "CIA402Slave.png")
   191         
   207         
   192         def GetDeviceLocationTree(self, slave_pos, current_location, device_name):
   208         def SetParamsAttribute(self, path, value):
       
   209             if path == "CIA402SlaveParams.Type":
       
   210                 path = "SlaveParams.Type"
       
   211             elif path == "CIA402SlaveParams.Alias":
       
   212                 path = "SlaveParams.Alias"
       
   213             return _EthercatSlaveCTN.SetParamsAttribute(self, path, value)
       
   214         
       
   215         def GetVariableLocationTree(self):
   193             axis_name = self.CTNName()
   216             axis_name = self.CTNName()
   194             vars = [{"name": "%s Axis Ref" % (axis_name),
   217             current_location = self.GetCurrentLocation()
   195                      "type": LOCATION_VAR_INPUT,
   218             children = [{"name": "%s Axis Ref" % (axis_name),
   196                      "size": "W",
   219                          "type": LOCATION_VAR_INPUT,
   197                      "IEC_type": "AXIS_REF",
   220                          "size": "W",
   198                      "var_name": axis_name,
   221                          "IEC_type": "INT",
   199                      "location": "%IW%s.0" % (".".join(map(str, current_location))),
   222                          "var_name": axis_name,
   200                      "description": "",
   223                          "location": "%%IW%s.0" % (".".join(map(str, current_location))),
   201                      "children": []}]
   224                          "description": "",
   202             vars.extend(_EthercatSlaveCTN.GetDeviceLocationTree(self, slave_pos, current_location, device_name))
   225                          "children": []}]
   203             return vars
   226             children.extend(self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(), current_location, axis_name))
       
   227             return  {"name": axis_name,
       
   228                      "type": LOCATION_CONFNODE,
       
   229                      "location": self.GetFullIEC_Channel(),
       
   230                      "children": children,
       
   231             }
   204         
   232         
   205         def _getCIA402AxisRef(self):
   233         def _getCIA402AxisRef(self):
   206             data = wx.TextDataObject(str(("%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
   234             data = wx.TextDataObject(str(("%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
   207                                           "location", "AXIS_REF", self.CTNName(), "")))
   235                                           "location", "AXIS_REF", self.CTNName(), "")))
   208             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   236             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   332     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   360     <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   333       <xsd:element name="EtherlabNode">
   361       <xsd:element name="EtherlabNode">
   334         <xsd:complexType>
   362         <xsd:complexType>
   335           <xsd:attribute name="MasterNumber" type="xsd:integer" use="optional" default="0"/>
   363           <xsd:attribute name="MasterNumber" type="xsd:integer" use="optional" default="0"/>
   336           <xsd:attribute name="ConfigurePDOs" type="xsd:boolean" use="optional" default="true"/>
   364           <xsd:attribute name="ConfigurePDOs" type="xsd:boolean" use="optional" default="true"/>
   337           <xsd:attribute name="DynamicPDOs" type="xsd:boolean" use="optional" default="true"/>
       
   338         </xsd:complexType>
   365         </xsd:complexType>
   339       </xsd:element>
   366       </xsd:element>
   340     </xsd:schema>
   367     </xsd:schema>
   341     """
   368     """
   342     
   369