etherlab/etherlab.py
changeset 2043 27d4cb689a79
parent 2042 563ccc918ded
child 2045 62e102935f3e
equal deleted inserted replaced
2042:563ccc918ded 2043:27d4cb689a79
     5 import wx
     5 import wx
     6 
     6 
     7 from xmlclass import *
     7 from xmlclass import *
     8 from plugger import PlugTemplate
     8 from plugger import PlugTemplate
     9 from PLCControler import UndoBuffer, LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
     9 from PLCControler import UndoBuffer, LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP, LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
    10 from ConfigEditor import NodeEditor, DS402NodeEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
    10 from ConfigEditor import NodeEditor, CIA402NodeEditor, ETHERCAT_VENDOR, ETHERCAT_GROUP, ETHERCAT_DEVICE
    11 
    11 
    12 try:
    12 try:
    13     from plugins.motion import Headers, AxisXSD
    13     from plugins.motion import Headers, AxisXSD
    14     HAS_MCL = True
    14     HAS_MCL = True
    15 except:
    15 except:
    16     HAS_MCL = False
    16     HAS_MCL = False
    17 
    17 
       
    18 PLUGINFOLDER = os.path.split(os.path.realpath(__file__))[0]
    18 
    19 
    19 TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
    20 TYPECONVERSION = {"BOOL" : "X", "SINT" : "B", "INT" : "W", "DINT" : "D", "LINT" : "L",
    20     "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", 
    21     "USINT" : "B", "UINT" : "W", "UDINT" : "D", "ULINT" : "L", 
    21     "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"}
    22     "BYTE" : "B", "WORD" : "W", "DWORD" : "D", "LWORD" : "L"}
    22 
    23 
    62 
    63 
    63 class _EthercatSlavePlug:
    64 class _EthercatSlavePlug:
    64 
    65 
    65     NODE_PROFILE = None
    66     NODE_PROFILE = None
    66     EditorType = NodeEditor
    67     EditorType = NodeEditor
       
    68     
       
    69     def GetIconPath(self, icon):
       
    70         return os.path.join(PLUGINFOLDER, "images", icon)
    67     
    71     
    68     def ExtractHexDecValue(self, value):
    72     def ExtractHexDecValue(self, value):
    69         return ExtractHexDecValue(value)
    73         return ExtractHexDecValue(value)
    70     
    74     
    71     def GetSizeOfType(self, type):
    75     def GetSizeOfType(self, type):
   130                  "location": self.GetFullIEC_Channel(),
   134                  "location": self.GetFullIEC_Channel(),
   131                  "children": self.PlugParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
   135                  "children": self.PlugParent.GetDeviceLocationTree(self.GetSlavePos(), self.GetCurrentLocation(), self.BaseParams.getName())
   132         }
   136         }
   133 
   137 
   134     PluginMethods = [
   138     PluginMethods = [
   135         {"bitmap" : os.path.join("images", "EditCfile"),
   139         {"bitmap" : os.path.join(PLUGINFOLDER, "images", "editSlave"),
   136          "name" : _("Edit Node"), 
   140          "name" : _("Edit Slave"), 
   137          "tooltip" : _("Edit Node"),
   141          "tooltip" : _("Edit Slave"),
   138          "method" : "_OpenView"},
   142          "method" : "_OpenView"},
   139     ]
   143     ]
   140 
   144 
   141     def PlugGenerate_C(self, buildpath, locations):
   145     def PlugGenerate_C(self, buildpath, locations):
   142         """
   146         """
   152         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
   156         @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
   153         """
   157         """
   154         return [],"",False
   158         return [],"",False
   155 
   159 
   156 #--------------------------------------------------
   160 #--------------------------------------------------
   157 #                 Ethercat DS402 Node
   161 #                 Ethercat CIA402 Node
   158 #--------------------------------------------------
   162 #--------------------------------------------------
   159 
   163 
   160 if HAS_MCL:
   164 if HAS_MCL:
   161     
   165     
   162     NODE_VARIABLES = [
   166     NODE_VARIABLES = [
   166         ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
   170         ("ModesOfOperationDisplay", 0x06061, 0x00, "SINT", "I"),
   167         ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
   171         ("ActualPosition", 0x6064, 0x00, "DINT", "I"),
   168         ("ErrorCode", 0x603f, 0x00, "UINT", "I"),
   172         ("ErrorCode", 0x603f, 0x00, "UINT", "I"),
   169     ]
   173     ]
   170     
   174     
   171     class _EthercatDS402SlavePlug(_EthercatSlavePlug):
   175     class _EthercatCIA402SlavePlug(_EthercatSlavePlug):
   172         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   176         XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
   173         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   177         <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   174           <xsd:element name="DS402SlaveParams">
   178           <xsd:element name="CIA402SlaveParams">
   175             <xsd:complexType>
   179             <xsd:complexType>
   176               %s
   180               %s
   177             </xsd:complexType>
   181             </xsd:complexType>
   178           </xsd:element>
   182           </xsd:element>
   179         </xsd:schema>
   183         </xsd:schema>
   180         """ % AxisXSD
   184         """ % AxisXSD
   181         
   185         
   182         NODE_PROFILE = 402
   186         NODE_PROFILE = 402
   183         EditorType = DS402NodeEditor
   187         EditorType = CIA402NodeEditor
       
   188         
       
   189         PluginMethods = [
       
   190             {"bitmap" : os.path.join(PLUGINFOLDER, "images", "editCIA402Slave"),
       
   191              "name" : _("Edit CIA402 Slave"), 
       
   192              "tooltip" : _("Edit CIA402 Slave"),
       
   193              "method" : "_OpenView"},
       
   194         ]
   184         
   195         
   185         def PlugGenerate_C(self, buildpath, locations):
   196         def PlugGenerate_C(self, buildpath, locations):
   186             """
   197             """
   187             Generate C code
   198             Generate C code
   188             @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
   199             @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
   222                 str_completion["extern_located_variables_declaration"].append(
   233                 str_completion["extern_located_variables_declaration"].append(
   223                         "IEC_%(var_type)s *%(var_name)s;" % var_infos)
   234                         "IEC_%(var_type)s *%(var_name)s;" % var_infos)
   224                 str_completion["entry_variables"].append(
   235                 str_completion["entry_variables"].append(
   225                         "    IEC_%(var_type)s *%(name)s;" % var_infos)
   236                         "    IEC_%(var_type)s *%(name)s;" % var_infos)
   226                 str_completion["init_entry_variables"].append(
   237                 str_completion["init_entry_variables"].append(
   227                         "    __DS402Node_%(location)s.%(name)s = %(var_name)s;" % var_infos)
   238                         "    __CIA402Node_%(location)s.%(name)s = %(var_name)s;" % var_infos)
   228                 
   239                 
   229                 self.PlugParent.FileGenerator.DeclareVariable(
   240                 self.PlugParent.FileGenerator.DeclareVariable(
   230                         self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
   241                         self.GetSlavePos(), var_infos["index"], var_infos["subindex"], 
   231                         var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
   242                         var_infos["var_type"], var_infos["dir"], var_infos["var_name"])
   232             
   243             
   240                     if param["type"] == "boolean":
   251                     if param["type"] == "boolean":
   241                         param_infos["param_value"] = {True: "true", False: "false"}[param["value"]]
   252                         param_infos["param_value"] = {True: "true", False: "false"}[param["value"]]
   242                     else:
   253                     else:
   243                         param_infos["param_value"] = str(param["value"])
   254                         param_infos["param_value"] = str(param["value"])
   244                     str_completion["init_axis_params"].append(
   255                     str_completion["init_axis_params"].append(
   245                         "        __DS402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_infos)
   256                         "        __CIA402Node_%(location)s.axis->%(param_name)s = %(param_value)s;" % param_infos)
   246             
   257             
   247             for element in ["extern_located_variables_declaration", 
   258             for element in ["extern_located_variables_declaration", 
   248                             "entry_variables", 
   259                             "entry_variables", 
   249                             "init_axis_params", 
   260                             "init_axis_params", 
   250                             "init_entry_variables"]:
   261                             "init_entry_variables"]:
   251                 str_completion[element] = "\n".join(str_completion[element])
   262                 str_completion[element] = "\n".join(str_completion[element])
   252             
   263             
   253             Gen_DS402Nodefile_path = os.path.join(buildpath, "ds402node_%s.c"%location_str)
   264             Gen_CIA402Nodefile_path = os.path.join(buildpath, "ds402node_%s.c"%location_str)
   254             ds402nodefile = open(Gen_DS402Nodefile_path, 'w')
   265             ds402nodefile = open(Gen_CIA402Nodefile_path, 'w')
   255             ds402nodefile.write(plc_ds402node_code % str_completion)
   266             ds402nodefile.write(plc_ds402node_code % str_completion)
   256             ds402nodefile.close()
   267             ds402nodefile.close()
   257             
   268             
   258             return [(Gen_DS402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()))],"",True
   269             return [(Gen_CIA402Nodefile_path, '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath()))],"",True
   259 
   270 
   260 #--------------------------------------------------
   271 #--------------------------------------------------
   261 #                 Ethercat MASTER
   272 #                 Ethercat MASTER
   262 #--------------------------------------------------
   273 #--------------------------------------------------
   263 
   274 
   312     </xsd:schema>
   323     </xsd:schema>
   313     """
   324     """
   314     
   325     
   315     PlugChildsTypes = [("EthercatSlave", _EthercatSlavePlug, "Ethercat Slave")]
   326     PlugChildsTypes = [("EthercatSlave", _EthercatSlavePlug, "Ethercat Slave")]
   316     if HAS_MCL:
   327     if HAS_MCL:
   317         PlugChildsTypes.append(("EthercatDS402Slave", _EthercatDS402SlavePlug, "Ethercat DS402 Slave"))
   328         PlugChildsTypes.append(("EthercatCIA402Slave", _EthercatCIA402SlavePlug, "Ethercat CIA402 Slave"))
   318     
   329     
   319     def __init__(self):
   330     def __init__(self):
   320         filepath = self.ConfigFileName()
   331         filepath = self.ConfigFileName()
   321         
   332         
   322         self.Config = EtherCATConfigClasses["EtherCATConfig"]()
   333         self.Config = EtherCATConfigClasses["EtherCATConfig"]()
   384                         "product_code": slave["product_code"],
   395                         "product_code": slave["product_code"],
   385                         "revision_number":slave["revision_number"],
   396                         "revision_number":slave["revision_number"],
   386                     }
   397                     }
   387                     device = self.GetModuleInfos(type_infos)
   398                     device = self.GetModuleInfos(type_infos)
   388                     if device is not None:
   399                     if device is not None:
   389                         if HAS_MCL and _EthercatDS402SlavePlug.NODE_PROFILE in device.GetProfileNumbers():
   400                         if HAS_MCL and _EthercatCIA402SlavePlug.NODE_PROFILE in device.GetProfileNumbers():
   390                             PlugType = "EthercatDS402Slave"
   401                             PlugType = "EthercatCIA402Slave"
   391                         else:
   402                         else:
   392                             PlugType = "EthercatSlave"
   403                             PlugType = "EthercatSlave"
   393                         self.PlugAddChild("slave%s" % slave["idx"], PlugType, slave["idx"])
   404                         self.PlugAddChild("slave%s" % slave["idx"], PlugType, slave["idx"])
   394                         self.SetSlaveAlias(slave["idx"], slave["alias"])
   405                         self.SetSlaveAlias(slave["idx"], slave["alias"])
   395                         type_infos["device_type"] = device.getType().getcontent()
   406                         type_infos["device_type"] = device.getType().getcontent()
   575         LDFLAGS.append("-lethercat -lrtdm")
   586         LDFLAGS.append("-lethercat -lrtdm")
   576         
   587         
   577         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   588         return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
   578 
   589 
   579     PluginMethods = [
   590     PluginMethods = [
   580         {"bitmap" : os.path.join("images", "Compiler"),
   591         {"bitmap" : os.path.join(PLUGINFOLDER, "images", "ScanNetwork"),
   581          "name" : _("Scan Network"), 
   592          "name" : _("Scan Network"), 
   582          "tooltip" : _("Scan Network"),
   593          "tooltip" : _("Scan Network"),
   583          "method" : "_ScanNetwork"},
   594          "method" : "_ScanNetwork"},
   584     ]
   595     ]
   585 
   596 
  1314             else:
  1325             else:
  1315                 self.GetPlugRoot().logger.write_error(_("No such XML file: %s\n") % filepath)
  1326                 self.GetPlugRoot().logger.write_error(_("No such XML file: %s\n") % filepath)
  1316         dialog.Destroy()  
  1327         dialog.Destroy()  
  1317     
  1328     
  1318     PluginMethods = [
  1329     PluginMethods = [
  1319         {"bitmap" : os.path.join("images", "ImportDEF"),
  1330         {"bitmap" : os.path.join(PLUGINFOLDER, "images", "ImportESI"),
  1320          "name" : _("Import module library"), 
  1331          "name" : _("Import module library"), 
  1321          "tooltip" : _("Import module library"),
  1332          "tooltip" : _("Import module library"),
  1322          "method" : "_ImportModuleLibrary"},
  1333          "method" : "_ImportModuleLibrary"},
  1323     ]
  1334     ]
  1324     
  1335