# HG changeset patch # User Laurent Bessard # Date 1339352177 -7200 # Node ID c485269ec44328943c00db4efef4b2a7d508e461 # Parent c7a2c9362d6352f3bfb97c2c82b15cf3463708eb Adding support for getting CIA402 slave AXIS_REF located variables and disabling dynamic PDO mapping algorithm for drives than doesn't support this functionality diff -r c7a2c9362d63 -r c485269ec443 etherlab/etherlab.py --- a/etherlab/etherlab.py Wed May 23 16:30:41 2012 +0200 +++ b/etherlab/etherlab.py Sun Jun 10 20:16:17 2012 +0200 @@ -159,7 +159,7 @@ NODE_VARIABLES = [ ("ControlWord", 0x6040, 0x00, "UINT", "Q"), ("TargetPosition", 0x607a, 0x00, "DINT", "Q"), -# ("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"), + ("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"), ("StatusWord", 0x6041, 0x00, "UINT", "I"), ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"), ("ActualPosition", 0x6064, 0x00, "DINT", "I"), @@ -179,9 +179,36 @@ NODE_PROFILE = 402 EditorType = CIA402NodeEditor + ConfNodeMethods = [ + {"bitmap" : "CIA402AxisRef", + "name" : _("Axis Ref"), + "tooltip" : _("Initiate Drag'n drop of Axis ref located variable"), + "method" : "_getCIA402AxisRef"}, + ] + def GetIconPath(self): return os.path.join(CONFNODEFOLDER, "images", "CIA402Slave.png") + def GetDeviceLocationTree(self, slave_pos, current_location, device_name): + axis_name = self.CTNName() + vars = [{"name": "%s Axis Ref" % (axis_name), + "type": LOCATION_VAR_INPUT, + "size": "W", + "IEC_type": "AXIS_REF", + "var_name": axis_name, + "location": "%IW%s.0" % (".".join(map(str, current_location))), + "description": "", + "children": []}] + vars.extend(_EthercatSlaveCTN.GetDeviceLocationTree(self, slave_pos, current_location, device_name)) + return vars + + def _getCIA402AxisRef(self): + data = wx.TextDataObject(str(("%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), + "location", "AXIS_REF", self.CTNName(), ""))) + dragSource = wx.DropSource(self.GetCTRoot().AppFrame) + dragSource.SetData(data) + dragSource.DoDragDrop() + def CTNGenerate_C(self, buildpath, locations): """ Generate C code @@ -307,6 +334,7 @@ + @@ -497,11 +525,10 @@ def GetDeviceLocationTree(self, slave_pos, current_location, device_name): slave = self.GetSlave(slave_pos) + vars = [] if slave is not None: type_infos = slave.getType() - vars = [] - device = self.GetModuleInfos(type_infos) if device is not None: sync_managers = [] @@ -965,85 +992,86 @@ "entries_number": len(entries_infos), "fixed": pdo.getFixed() == True}) - dynamic_pdos = {} - dynamic_pdos_number = 0 - for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), - ("Outputs", 0x1a00, 0x1C00)]: - for sync_manager in sync_managers: - if sync_manager["name"] == category: - category_infos = dynamic_pdos.setdefault(category, {}) - category_infos["sync_manager"] = sync_manager - category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] - if not pdo["fixed"] and pdo["type"] == category] - category_infos["current_index"] = min_index - category_infos["max_index"] = max_index - break - - for (index, subindex), entry_declaration in slave_variables.iteritems(): + if etherlab_node_infos.getDynamicPDOs(): + dynamic_pdos = {} + dynamic_pdos_number = 0 + for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), + ("Outputs", 0x1a00, 0x1C00)]: + for sync_manager in sync_managers: + if sync_manager["name"] == category: + category_infos = dynamic_pdos.setdefault(category, {}) + category_infos["sync_manager"] = sync_manager + category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] + if not pdo["fixed"] and pdo["type"] == category] + category_infos["current_index"] = min_index + category_infos["max_index"] = max_index + break - if not entry_declaration["mapped"]: - entry = device_entries.get((index, subindex), None) - if entry is None: - raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \ - (index, subindex, type_infos["device_type"]) + for (index, subindex), entry_declaration in slave_variables.iteritems(): - entry_infos = { - "index": index, - "subindex": subindex, - "name": entry["Name"], - "bitlen": entry["BitSize"], - } - entry_infos.update(type_infos) - - entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"]))) - entry_declaration["mapped"] = True - - if entry_infos["var_type"] != entry["Type"]: - message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] - if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != - self.Controler.GetSizeOfType(entry["Type"])): - raise ValueError, message + if not entry_declaration["mapped"]: + entry = device_entries.get((index, subindex), None) + if entry is None: + raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \ + (index, subindex, type_infos["device_type"]) + + entry_infos = { + "index": index, + "subindex": subindex, + "name": entry["Name"], + "bitlen": entry["BitSize"], + } + entry_infos.update(type_infos) + + entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"]))) + entry_declaration["mapped"] = True + + if entry_infos["var_type"] != entry["Type"]: + message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] + if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != + self.Controler.GetSizeOfType(entry["Type"])): + raise ValueError, message + else: + self.Controler.GetCTRoot().logger.write_warning(message + "\n") + + if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]: + pdo_type = "Inputs" + elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]: + pdo_type = "Outputs" else: - self.Controler.GetCTRoot().logger.write_warning(message + "\n") - - if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]: - pdo_type = "Inputs" - elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]: - pdo_type = "Outputs" - else: - raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] - - if not dynamic_pdos.has_key(pdo_type): - raise ValueError, _("No Sync manager defined for %s!") % pdo_type - - ConfigureVariable(entry_infos, str_completion) - - if len(dynamic_pdos[pdo_type]["pdos"]) > 0: - pdo = dynamic_pdos[pdo_type]["pdos"][0] - else: - while dynamic_pdos[pdo_type]["current_index"] in pdos_index: - dynamic_pdos[pdo_type]["current_index"] += 1 - if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]: - raise ValueError, _("No more free PDO index available for %s!") % pdo_type - pdos_index.append(dynamic_pdos[pdo_type]["current_index"]) + raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] - dynamic_pdos_number += 1 - pdo = {"slave": slave_idx, - "index": dynamic_pdos[pdo_type]["current_index"], - "name": "Dynamic PDO %d" % dynamic_pdos_number, - "type": pdo_type, - "entries": [], - "entries_number": 0, - "fixed": False} - dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1 - dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo) - dynamic_pdos[pdo_type]["pdos"].append(pdo) - - pdo["entries"].append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) - pdo["entries_number"] += 1 - - if pdo["entries_number"] == 255: - dynamic_pdos[pdo_type]["pdos"].pop(0) + if not dynamic_pdos.has_key(pdo_type): + raise ValueError, _("No Sync manager defined for %s!") % pdo_type + + ConfigureVariable(entry_infos, str_completion) + + if len(dynamic_pdos[pdo_type]["pdos"]) > 0: + pdo = dynamic_pdos[pdo_type]["pdos"][0] + else: + while dynamic_pdos[pdo_type]["current_index"] in pdos_index: + dynamic_pdos[pdo_type]["current_index"] += 1 + if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]: + raise ValueError, _("No more free PDO index available for %s!") % pdo_type + pdos_index.append(dynamic_pdos[pdo_type]["current_index"]) + + dynamic_pdos_number += 1 + pdo = {"slave": slave_idx, + "index": dynamic_pdos[pdo_type]["current_index"], + "name": "Dynamic PDO %d" % dynamic_pdos_number, + "type": pdo_type, + "entries": [], + "entries_number": 0, + "fixed": False} + dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1 + dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo) + dynamic_pdos[pdo_type]["pdos"].append(pdo) + + pdo["entries"].append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) + pdo["entries_number"] += 1 + + if pdo["entries_number"] == 255: + dynamic_pdos[pdo_type]["pdos"].pop(0) pdo_offset = 0 entry_offset = 0 diff -r c7a2c9362d63 -r c485269ec443 etherlab/images/CIA402AxisRef.png Binary file etherlab/images/CIA402AxisRef.png has changed diff -r c7a2c9362d63 -r c485269ec443 etherlab/images/icons.svg --- a/etherlab/images/icons.svg Wed May 23 16:30:41 2012 +0200 +++ b/etherlab/images/icons.svg Sun Jun 10 20:16:17 2012 +0200 @@ -43,9 +43,9 @@ pagecolor="#ffffff" id="base" showgrid="false" - inkscape:zoom="5.6568542" - inkscape:cx="366.34384" - inkscape:cy="861.79751" + inkscape:zoom="0.5" + inkscape:cx="904.45004" + inkscape:cy="452.59174" inkscape:window-x="0" inkscape:window-y="24" inkscape:current-layer="svg2" @@ -58872,6 +58872,305 @@ y1="275.58682" x2="452.19373" y2="88.438019" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + %%ImportESI ScanNetwork editSlave editCIA402Slave %% + y="120.42097">%%ImportESI ScanNetwork editSlave editCIA402Slave CIA402AxisRef %% @@ -60998,4 +61297,131 @@ transform="matrix(0.51386408,0,0,0.51386408,45.954134,148.43892)" width="744.09448" height="1052.3622" /> + + + + + + + + + + + + + + + + + + + + + R + E + F + + +