etherlab/etherlab.py
changeset 2092 c9776ae8b5d0
parent 2091 d964dbc2c7b0
child 2093 3fdf9d56d803
equal deleted inserted replaced
2091:d964dbc2c7b0 2092:c9776ae8b5d0
   206             {"description": ("DigitalInputs", 0x60FD, 0x00, "UDINT", "I"),
   206             {"description": ("DigitalInputs", 0x60FD, 0x00, "UDINT", "I"),
   207              "publish": None}
   207              "publish": None}
   208             ])
   208             ])
   209     ]
   209     ]
   210     EXTRA_NODE_VARIABLES_DICT = dict([("Enable" + name, value) for name, value in EXTRA_NODE_VARIABLES])
   210     EXTRA_NODE_VARIABLES_DICT = dict([("Enable" + name, value) for name, value in EXTRA_NODE_VARIABLES])
       
   211 
       
   212     BLOCK_INPUT_TEMPLATE = "    __SET_VAR(%(blockname)s.,%(input_name)s, %(input_value)s);"
       
   213     BLOCK_OUTPUT_TEMPLATE = "    __SET_VAR(data__->,%(output_name)s, __GET_VAR(%(blockname)s.%(output_name)s));"
       
   214     
       
   215     BLOCK_FUNCTION_TEMPLATE = """
       
   216 void __%(blocktype)s_%(location)s(MCL_%(ucase_blocktype)s *data__) {
       
   217     extern ETHERLAB%(ucase_blocktype)s %(blockname)s;
       
   218 %(extract_inputs)s
       
   219     ETHERLAB%(ucase_blocktype)s_body__(&%(blockname)s);
       
   220 %(return_outputs)s
       
   221 }
       
   222 """
       
   223     
       
   224     BLOCK_FUNTION_DEFINITION_TEMPLATE = "    __CIA402Node_%(location)s.axis->__mcl_func_%(blocktype)s = &(__%(blocktype)s_%(location)s);"
       
   225     
       
   226     GLOBAL_INSTANCES = [
       
   227         {"blocktype": "GetTorqueLimit", 
       
   228          "inputs": [],
       
   229          "outputs": [{"name": "TorqueLimitPos", "type": "UINT"},
       
   230                      {"name": "TorqueLimitNeg", "type": "UINT"}]},
       
   231         {"blocktype": "SetTorqueLimit", 
       
   232          "inputs": [{"name": "TorqueLimitPos", "type": "UINT"},
       
   233                     {"name": "TorqueLimitNeg", "type": "UINT"}],
       
   234          "outputs": []},
       
   235     ]
   211     
   236     
   212     class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
   237     class _EthercatCIA402SlaveCTN(_EthercatSlaveCTN):
   213         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   238         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   214         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   239         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   215           <xsd:element name="CIA402SlaveParams">
   240           <xsd:element name="CIA402SlaveParams">
   257             return  {"name": axis_name,
   282             return  {"name": axis_name,
   258                      "type": LOCATION_CONFNODE,
   283                      "type": LOCATION_CONFNODE,
   259                      "location": self.GetFullIEC_Channel(),
   284                      "location": self.GetFullIEC_Channel(),
   260                      "children": children,
   285                      "children": children,
   261             }
   286             }
       
   287         
       
   288         def CTNGlobalInstances(self):
       
   289             current_location = self.GetCurrentLocation()
       
   290             return [("%s_%s" % (block_infos["blocktype"], "_".join(map(str, current_location))),
       
   291                      "EtherLab%s" % block_infos["blocktype"]) for block_infos in GLOBAL_INSTANCES]
   262         
   292         
   263         def _getCIA402AxisRef(self):
   293         def _getCIA402AxisRef(self):
   264             data = wx.TextDataObject(str(("%%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
   294             data = wx.TextDataObject(str(("%%IW%s.0" % ".".join(map(str, self.GetCurrentLocation())), 
   265                                           "location", "AXIS_REF", self.CTNName(), "")))
   295                                           "location", "AXIS_REF", self.CTNName(), "")))
   266             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   296             dragSource = wx.DropSource(self.GetCTRoot().AppFrame)
   292             str_completion = {
   322             str_completion = {
   293                 "slave_pos": self.GetSlavePos(),
   323                 "slave_pos": self.GetSlavePos(),
   294                 "location": location_str,
   324                 "location": location_str,
   295                 "MCL_headers": Headers,
   325                 "MCL_headers": Headers,
   296                 "extern_located_variables_declaration": [],
   326                 "extern_located_variables_declaration": [],
       
   327                 "fieldbus_interface_declaration": [],
       
   328                 "fieldbus_interface_definition": [],
   297                 "entry_variables": [],
   329                 "entry_variables": [],
   298                 "init_axis_params": [],
   330                 "init_axis_params": [],
   299                 "init_entry_variables": [],
   331                 "init_entry_variables": [],
   300                 "extra_variables_retrieve": [],
   332                 "extra_variables_retrieve": [],
   301                 "extra_variables_publish": []
   333                 "extra_variables_publish": []
   302             }
   334             }
   303             
   335             
       
   336             for blocktype_infos in GLOBAL_INSTANCES:
       
   337                 texts = {
       
   338                     "blocktype": blocktype_infos["blocktype"],
       
   339                     "ucase_blocktype": blocktype_infos["blocktype"].upper(),
       
   340                     "location": "_".join(map(str, current_location))
       
   341                 }
       
   342                 texts["blockname"] = "%(ucase_blocktype)s_%(location)s" % texts
       
   343                 
       
   344                 inputs = [{"input_name": "POS", "input_value": str(self.GetSlavePos())},
       
   345                           {"input_name": "EXECUTE", "input_value": "__GET_VAR(data__->EXECUTE)"}] +\
       
   346                          [{"input_name": input["name"].upper(), 
       
   347                            "input_value": "__GET_VAR(data__->%s)" % input["name"].upper()}
       
   348                           for input in blocktype_infos["inputs"]]
       
   349                 input_texts = []
       
   350                 for input_infos in inputs:
       
   351                     input_infos.update(texts)
       
   352                     input_texts.append(BLOCK_INPUT_TEMPLATE % input_infos)
       
   353                 texts["extract_inputs"] = "\n".join(input_texts)
       
   354                 
       
   355                 outputs = [{"output_name": output} for output in ["DONE", "BUSY", "ERROR"]] + \
       
   356                           [{"output_name": output["name"].upper()} for output in blocktype_infos["outputs"]]
       
   357                 output_texts = []
       
   358                 for output_infos in outputs:
       
   359                     output_infos.update(texts)
       
   360                     output_texts.append(BLOCK_OUTPUT_TEMPLATE % output_infos)
       
   361                 texts["return_outputs"] = "\n".join(output_texts)
       
   362                 
       
   363                 str_completion["fieldbus_interface_declaration"].append(
       
   364                         BLOCK_FUNCTION_TEMPLATE % texts)
       
   365                 
       
   366                 str_completion["fieldbus_interface_definition"].append(
       
   367                         BLOCK_FUNTION_DEFINITION_TEMPLATE % texts)
       
   368                 
   304             variables = NODE_VARIABLES[:]
   369             variables = NODE_VARIABLES[:]
   305             
   370             
   306             params = self.CTNParams[1].getElementInfos(self.CTNParams[0])
   371             params = self.CTNParams[1].getElementInfos(self.CTNParams[0])
   307             for param in params["children"]:
   372             for param in params["children"]:
   308                 if param["name"] in EXTRA_NODE_VARIABLES_DICT:
   373                 if param["name"] in EXTRA_NODE_VARIABLES_DICT:
   351                 self.CTNParent.FileGenerator.DeclareVariable(
   416                 self.CTNParent.FileGenerator.DeclareVariable(
   352                         self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
   417                         self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
   353                         var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
   418                         var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
   354             
   419             
   355             for element in ["extern_located_variables_declaration", 
   420             for element in ["extern_located_variables_declaration", 
       
   421                             "fieldbus_interface_declaration",
       
   422                             "fieldbus_interface_definition",
   356                             "entry_variables", 
   423                             "entry_variables", 
   357                             "init_axis_params", 
   424                             "init_axis_params", 
   358                             "init_entry_variables",
   425                             "init_entry_variables",
   359                             "extra_variables_retrieve",
   426                             "extra_variables_retrieve",
   360                             "extra_variables_publish"]:
   427                             "extra_variables_publish"]: