etherlab/etherlab.py
changeset 2045 62e102935f3e
parent 2043 27d4cb689a79
child 2047 b0b7bd288b6e
equal deleted inserted replaced
2044:76346b30f6f9 2045:62e102935f3e
   164 if HAS_MCL:
   164 if HAS_MCL:
   165     
   165     
   166     NODE_VARIABLES = [
   166     NODE_VARIABLES = [
   167         ("ControlWord", 0x6040, 0x00, "UINT", "Q"),
   167         ("ControlWord", 0x6040, 0x00, "UINT", "Q"),
   168         ("TargetPosition", 0x607a, 0x00, "DINT", "Q"),
   168         ("TargetPosition", 0x607a, 0x00, "DINT", "Q"),
       
   169         ("ModesOfOperation", 0x06060, 0x00, "SINT", "Q"),
   169         ("StatusWord", 0x6041, 0x00, "UINT", "I"),
   170         ("StatusWord", 0x6041, 0x00, "UINT", "I"),
   170         ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
   171         ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
   171         ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
   172         ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
   172         ("ErrorCode", 0x603f, 0x00, "UINT", "I"),
       
   173     ]
   173     ]
   174     
   174     
   175     class _EthercatCIA402SlavePlug(_EthercatSlavePlug):
   175     class _EthercatCIA402SlavePlug(_EthercatSlavePlug):
   176         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   176         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   177         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   177         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   208             """
   208             """
   209             current_location = self.GetCurrentLocation()
   209             current_location = self.GetCurrentLocation()
   210             
   210             
   211             location_str = "_".join(map(lambda x:str(x), current_location))
   211             location_str = "_".join(map(lambda x:str(x), current_location))
   212             
   212             
   213             plc_ds402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_ds402node.c")
   213             plc_cia402node_filepath = os.path.join(os.path.split(__file__)[0], "plc_cia402node.c")
   214             plc_ds402node_file = open(plc_ds402node_filepath, 'r')
   214             plc_cia402node_file = open(plc_cia402node_filepath, 'r')
   215             plc_ds402node_code = plc_ds402node_file.read()
   215             plc_cia402node_code = plc_cia402node_file.read()
   216             plc_ds402node_file.close()
   216             plc_cia402node_file.close()
   217             
   217             
   218             str_completion = {
   218             str_completion = {
   219                 "location": location_str,
   219                 "location": location_str,
   220                 "MCL_headers": Headers,
   220                 "MCL_headers": Headers,
   221                 "extern_located_variables_declaration": [],
   221                 "extern_located_variables_declaration": [],
   259                             "entry_variables", 
   259                             "entry_variables", 
   260                             "init_axis_params", 
   260                             "init_axis_params", 
   261                             "init_entry_variables"]:
   261                             "init_entry_variables"]:
   262                 str_completion[element] = "\n".join(str_completion[element])
   262                 str_completion[element] = "\n".join(str_completion[element])
   263             
   263             
   264             Gen_CIA402Nodefile_path = os.path.join(buildpath, "ds402node_%s.c"%location_str)
   264             Gen_CIA402Nodefile_path = os.path.join(buildpath, "cia402node_%s.c"%location_str)
   265             ds402nodefile = open(Gen_CIA402Nodefile_path, 'w')
   265             cia402nodefile = open(Gen_CIA402Nodefile_path, 'w')
   266             ds402nodefile.write(plc_ds402node_code % str_completion)
   266             cia402nodefile.write(plc_cia402node_code % str_completion)
   267             ds402nodefile.close()
   267             cia402nodefile.close()
   268             
   268             
   269             return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()))],"",True
   269             return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()))],"",True
   270 
   270 
   271 #--------------------------------------------------
   271 #--------------------------------------------------
   272 #                 Ethercat MASTER
   272 #                 Ethercat MASTER
   924                                     pdo_needed = True
   924                                     pdo_needed = True
   925                                     
   925                                     
   926                                     entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"])))
   926                                     entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"])))
   927                                     entry_declaration["mapped"] = True
   927                                     entry_declaration["mapped"] = True
   928                                     
   928                                     
   929                                     if entry_infos["var_type"] != entry.getDataType().getcontent():
   929                                     entry_type = entry.getDataType().getcontent()
   930                                         raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
   930                                     if entry_infos["var_type"] != entry_type:
       
   931                                         message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
       
   932                                         if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
       
   933                                             self.Controler.GetSizeOfType(entry_type)):
       
   934                                             raise ValueError, message
       
   935                                         else:
       
   936                                             self.Controler.GetPlugRoot().logger.write_warning(message + "\n")
   931                                     
   937                                     
   932                                     if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
   938                                     if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
   933                                         entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
   939                                         entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
   934                                         raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
   940                                         raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
   935                                     
   941                                     
  1002                             
  1008                             
  1003                             entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"])))
  1009                             entry_infos.update(dict(zip(["var_type", "dir", "var_name", "real_var"], entry_declaration["infos"])))
  1004                             entry_declaration["mapped"] = True
  1010                             entry_declaration["mapped"] = True
  1005                             
  1011                             
  1006                             if entry_infos["var_type"] != entry["Type"]:
  1012                             if entry_infos["var_type"] != entry["Type"]:
  1007                                 raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
  1013                                 message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"]
       
  1014                                 if (self.Controler.GetSizeOfType(entry_infos["var_type"]) != 
       
  1015                                     self.Controler.GetSizeOfType(entry["Type"])):
       
  1016                                     raise ValueError, message
       
  1017                                 else:
       
  1018                                     self.Controler.GetPlugRoot().logger.write_warning(message + "\n")
  1008                             
  1019                             
  1009                             if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]:
  1020                             if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]:
  1010                                 pdo_type = "Inputs"
  1021                                 pdo_type = "Inputs"
  1011                             elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]:
  1022                             elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]:
  1012                                 pdo_type = "Outputs"
  1023                                 pdo_type = "Outputs"