etherlab/EthercatCIA402Slave.py
changeset 2407 5f2b1bb464a0
parent 2406 ffd091b51cd0
child 2413 803daf19a1b5
equal deleted inserted replaced
2406:ffd091b51cd0 2407:5f2b1bb464a0
   162                 "location": location_frmt % (".".join(map(str, current_location))),
   162                 "location": location_frmt % (".".join(map(str, current_location))),
   163                 "description": "",
   163                 "description": "",
   164                 "children": []
   164                 "children": []
   165             }
   165             }
   166             for name_frmt, iec_type, var_name_frmt, location_frmt in [
   166             for name_frmt, iec_type, var_name_frmt, location_frmt in [
   167                     ("%s Network Position", "UINT", "%s_pos", "%%IW%s"),
   167                 ("%s Network Position", "UINT", "%s_pos", "%%IW%s"),
   168                     ("%s Axis Ref", "AXIS_REF", "%s", "%%IW%s.402")
   168                 ("%s Axis Ref", "AXIS_REF", "%s", "%%IW%s.402")
   169             ]
   169             ]
   170         ]
   170         ]
   171         children.extend(self.CTNParent.GetDeviceLocationTree(
   171         children.extend(self.CTNParent.GetDeviceLocationTree(self.GetSlavePos(),
   172                             self.GetSlavePos(), current_location, axis_name))
   172                                                              current_location,
       
   173                                                              axis_name))
   173         return {
   174         return {
   174             "name": axis_name,
   175             "name": axis_name,
   175             "type": LOCATION_CONFNODE,
   176             "type": LOCATION_CONFNODE,
   176             "location": self.GetFullIEC_Channel(),
   177             "location": self.GetFullIEC_Channel(),
   177             "children": children,
   178             "children": children,
   227         for blocktype_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES:
   228         for blocktype_infos in FIELDBUS_INTERFACE_GLOBAL_INSTANCES:
   228             blocktype = blocktype_infos["blocktype"]
   229             blocktype = blocktype_infos["blocktype"]
   229             ucase_blocktype = blocktype.upper()
   230             ucase_blocktype = blocktype.upper()
   230             blockname = "_".join([ucase_blocktype, location_str])
   231             blockname = "_".join([ucase_blocktype, location_str])
   231 
   232 
   232             extract_inputs = "\n".join(["""\
   233             extract_inputs = "\n".join([
   233     __SET_VAR(%s->, %s,, %s);""" % (blockname, input_name, input_value)
   234                 """\
   234                 for (input_name, input_value) in [
   235                 __SET_VAR(%s->, %s,, %s);""" % (blockname, input_name, input_value)
   235                     ("EXECUTE", "__GET_VAR(data__->EXECUTE)")] + [
   236                 for (input_name, input_value) in
       
   237                 [("EXECUTE", "__GET_VAR(data__->EXECUTE)")] + [
   236                     (input["name"].upper(),
   238                     (input["name"].upper(),
   237                      "__GET_VAR(data__->%s)" % input["name"].upper())
   239                      "__GET_VAR(data__->%s)" % input["name"].upper())
   238                     for input in blocktype_infos["inputs"]]
   240                     for input in blocktype_infos["inputs"]
   239                 ])
   241                 ]])
   240 
   242 
   241             return_outputs = "\n".join([
   243             return_outputs = "\n".join([
   242                 """\
   244                 """\
   243                 __SET_VAR(data__->,%(output_name)s,,
   245                 __SET_VAR(data__->,%(output_name)s,,
   244                 __GET_VAR(%(blockname)s->%(output_name)s));""" % {
   246                 __GET_VAR(%(blockname)s->%(output_name)s));""" % {
   245                     "output_name": output_name,
   247                     "output_name": output_name,
   246                     "blockname": blockname
   248                     "blockname": blockname
   247                 }
   249                 }
   248                 for output_name in ["DONE", "BUSY", "ERROR"] + [
   250                 for output_name in ["DONE", "BUSY", "ERROR"] + [
   249                         output["name"].upper()
   251                     output["name"].upper()
   250                         for output in blocktype_infos["outputs"]]
   252                     for output in blocktype_infos["outputs"]]
   251             ])
   253             ])
   252 
   254 
   253             loc_dict = {
   255             loc_dict = {
   254                 "ucase_blocktype": ucase_blocktype,
   256                 "ucase_blocktype": ucase_blocktype,
   255                 "blocktype": blocktype,
   257                 "blocktype": blocktype,
   336             var_name = """\
   338             var_name = """\
   337 __%(dir)s%(var_size)s%(location_str)s_%(index)d_%(subindex)d""" % loc_dict
   339 __%(dir)s%(var_size)s%(location_str)s_%(index)d_%(subindex)d""" % loc_dict
   338             loc_dict["var_name"] = var_name
   340             loc_dict["var_name"] = var_name
   339 
   341 
   340             extern_located_variables_declaration.append(
   342             extern_located_variables_declaration.append(
   341                     "IEC_%(var_type)s *%(var_name)s;" % loc_dict)
   343                 "IEC_%(var_type)s *%(var_name)s;" % loc_dict)
   342             entry_variables.append(
   344             entry_variables.append(
   343                     "    IEC_%(var_type)s *%(name)s;" % loc_dict)
   345                 "    IEC_%(var_type)s *%(name)s;" % loc_dict)
   344             init_entry_variables.append(
   346             init_entry_variables.append(
   345                     "    AxsPub.%(name)s = %(var_name)s;" % loc_dict)
   347                 "    AxsPub.%(name)s = %(var_name)s;" % loc_dict)
   346 
   348 
   347             self.CTNParent.FileGenerator.DeclareVariable(
   349             self.CTNParent.FileGenerator.DeclareVariable(
   348                     slave_pos, index, subindex, var_type, dir, var_name)
   350                 slave_pos, index, subindex, var_type, dir, var_name)
   349 
   351 
   350         # Add newline between string in list of generated strings for sections
   352         # Add newline between string in list of generated strings for sections
   351         [fieldbus_interface_declaration, fieldbus_interface_definition,
   353         [fieldbus_interface_declaration, fieldbus_interface_definition,
   352          init_axis_params, extra_variables_retrieve, extra_variables_publish,
   354          init_axis_params, extra_variables_retrieve, extra_variables_publish,
   353          extern_located_variables_declaration, entry_variables,
   355          extern_located_variables_declaration, entry_variables,
   354          init_entry_variables] = map("\n".join, [
   356          init_entry_variables] = map("\n".join, [
   355             fieldbus_interface_declaration, fieldbus_interface_definition,
   357              fieldbus_interface_declaration, fieldbus_interface_definition,
   356             init_axis_params, extra_variables_retrieve, extra_variables_publish,
   358              init_axis_params, extra_variables_retrieve, extra_variables_publish,
   357             extern_located_variables_declaration, entry_variables,
   359              extern_located_variables_declaration, entry_variables,
   358             init_entry_variables])
   360              init_entry_variables])
   359 
   361 
   360         # Write generated content to CIA402 node file
   362         # Write generated content to CIA402 node file
   361         Gen_CIA402Nodefile_path = os.path.join(buildpath,
   363         Gen_CIA402Nodefile_path = os.path.join(buildpath,
   362                                                "cia402node_%s.c" % location_str)
   364                                                "cia402node_%s.c" % location_str)
   363         cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')
   365         cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')