plcopen/plcopen.py
changeset 1751 c28db6f7616b
parent 1750 acf02488f37f
child 1759 56e7f4a11046
equal deleted inserted replaced
1750:acf02488f37f 1751:c28db6f7616b
   433         return gettypeElement
   433         return gettypeElement
   434 
   434 
   435     datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType")
   435     datatypes_xpath = PLCOpen_XPath("ppx:types/ppx:dataTypes/ppx:dataType")
   436     filtered_datatypes_xpath = PLCOpen_XPath(
   436     filtered_datatypes_xpath = PLCOpen_XPath(
   437         "ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]")
   437         "ppx:types/ppx:dataTypes/ppx:dataType[@name!=$exclude]")
       
   438 
   438     def getdataTypes(self, exclude=None):
   439     def getdataTypes(self, exclude=None):
   439         if exclude is not None:
   440         if exclude is not None:
   440             return filtered_datatypes_xpath(self, exclude=exclude)
   441             return filtered_datatypes_xpath(self, exclude=exclude)
   441         return datatypes_xpath(self)
   442         return datatypes_xpath(self)
   442     setattr(cls, "getdataTypes", getdataTypes)
   443     setattr(cls, "getdataTypes", getdataTypes)
   481         self.types.removepouElement(name)
   482         self.types.removepouElement(name)
   482     setattr(cls, "removepou", removepou)
   483     setattr(cls, "removepou", removepou)
   483 
   484 
   484     configurations_xpath = PLCOpen_XPath(
   485     configurations_xpath = PLCOpen_XPath(
   485         "ppx:instances/ppx:configurations/ppx:configuration")
   486         "ppx:instances/ppx:configurations/ppx:configuration")
       
   487 
   486     def getconfigurations(self):
   488     def getconfigurations(self):
   487         return configurations_xpath(self)
   489         return configurations_xpath(self)
   488     setattr(cls, "getconfigurations", getconfigurations)
   490     setattr(cls, "getconfigurations", getconfigurations)
   489 
   491 
   490     configuration_xpath = PLCOpen_XPath(
   492     configuration_xpath = PLCOpen_XPath(
   491         "ppx:instances/ppx:configurations/ppx:configuration[@name=$name]")
   493         "ppx:instances/ppx:configurations/ppx:configuration[@name=$name]")
       
   494 
   492     def getconfiguration(self, name):
   495     def getconfiguration(self, name):
   493         configurations = configuration_xpath(self, name=name)
   496         configurations = configuration_xpath(self, name=name)
   494         if len(configurations) == 1:
   497         if len(configurations) == 1:
   495             return configurations[0]
   498             return configurations[0]
   496         return None
   499         return None
   511         self.instances.configurations.remove(configuration)
   514         self.instances.configurations.remove(configuration)
   512     setattr(cls, "removeconfiguration", removeconfiguration)
   515     setattr(cls, "removeconfiguration", removeconfiguration)
   513 
   516 
   514     resources_xpath = PLCOpen_XPath(
   517     resources_xpath = PLCOpen_XPath(
   515         "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]")
   518         "ppx:instances/ppx:configurations/ppx:configuration[@name=$configname]/ppx:resource[@name=$name]")
       
   519 
   516     def getconfigurationResource(self, config_name, name):
   520     def getconfigurationResource(self, config_name, name):
   517         resources = resources_xpath(self, configname=config_name, name=name)
   521         resources = resources_xpath(self, configname=config_name, name=name)
   518         if len(resources) == 1:
   522         if len(resources) == 1:
   519             return resources[0]
   523             return resources[0]
   520         return None
   524         return None
   576             configuration.removeVariableByFilter(address_model)
   580             configuration.removeVariableByFilter(address_model)
   577     setattr(cls, "removeVariableByFilter", removeVariableByFilter)
   581     setattr(cls, "removeVariableByFilter", removeVariableByFilter)
   578 
   582 
   579     enumerated_values_xpath = PLCOpen_XPath(
   583     enumerated_values_xpath = PLCOpen_XPath(
   580         "ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value")
   584         "ppx:types/ppx:dataTypes/ppx:dataType/ppx:baseType/ppx:enum/ppx:values/ppx:value")
       
   585 
   581     def GetEnumeratedDataTypeValues(self):
   586     def GetEnumeratedDataTypeValues(self):
   582         return [value.getname() for value in enumerated_values_xpath(self)]
   587         return [value.getname() for value in enumerated_values_xpath(self)]
   583     setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues)
   588     setattr(cls, "GetEnumeratedDataTypeValues", GetEnumeratedDataTypeValues)
   584 
   589 
   585     def Search(self, criteria, parent_infos=[]):
   590     def Search(self, criteria, parent_infos=[]):
  1068     def updateElementName(self, old_name, new_name):
  1073     def updateElementName(self, old_name, new_name):
  1069         pass
  1074         pass
  1070     setattr(cls, "updateElementName", updateElementName)
  1075     setattr(cls, "updateElementName", updateElementName)
  1071 
  1076 
  1072     enumerated_datatype_values_xpath = PLCOpen_XPath("ppx:values/ppx:value")
  1077     enumerated_datatype_values_xpath = PLCOpen_XPath("ppx:values/ppx:value")
       
  1078 
  1073     def Search(self, criteria, parent_infos=[]):
  1079     def Search(self, criteria, parent_infos=[]):
  1074         search_result = []
  1080         search_result = []
  1075         for i, value in enumerate(enumerated_datatype_values_xpath(self)):
  1081         for i, value in enumerate(enumerated_datatype_values_xpath(self)):
  1076             for result in TestTextElement(value.getname(), criteria):
  1082             for result in TestTextElement(value.getname(), criteria):
  1077                 search_result.append((tuple(parent_infos + ["value", i]),) + result)
  1083                 search_result.append((tuple(parent_infos + ["value", i]),) + result)
  1092 
  1098 
  1093     block_inputs_xpath = PLCOpen_XPath(
  1099     block_inputs_xpath = PLCOpen_XPath(
  1094         "ppx:interface/*[self::ppx:inputVars or self::ppx:inOutVars]/ppx:variable")
  1100         "ppx:interface/*[self::ppx:inputVars or self::ppx:inOutVars]/ppx:variable")
  1095     block_outputs_xpath = PLCOpen_XPath(
  1101     block_outputs_xpath = PLCOpen_XPath(
  1096         "ppx:interface/*[self::ppx:outputVars or self::ppx:inOutVars]/ppx:variable")
  1102         "ppx:interface/*[self::ppx:outputVars or self::ppx:inOutVars]/ppx:variable")
       
  1103 
  1097     def getblockInfos(self):
  1104     def getblockInfos(self):
  1098         block_infos = {
  1105         block_infos = {
  1099             "name": self.getname(),
  1106             "name": self.getname(),
  1100             "type": self.getpouType(),
  1107             "type": self.getpouType(),
  1101             "extensible": False,
  1108             "extensible": False,
  1624 
  1631 
  1625 cls = PLCOpenParser.GetElementClass("body")
  1632 cls = PLCOpenParser.GetElementClass("body")
  1626 if cls:
  1633 if cls:
  1627     cls.currentExecutionOrderId = 0
  1634     cls.currentExecutionOrderId = 0
  1628     cls.checkedBlocksDict = {}
  1635     cls.checkedBlocksDict = {}
       
  1636 
  1629     def resetcurrentExecutionOrderId(self):
  1637     def resetcurrentExecutionOrderId(self):
  1630         object.__setattr__(self, "currentExecutionOrderId", 0)
  1638         object.__setattr__(self, "currentExecutionOrderId", 0)
  1631     setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
  1639     setattr(cls, "resetcurrentExecutionOrderId", resetcurrentExecutionOrderId)
  1632 
  1640 
  1633     def getnewExecutionOrderId(self):
  1641     def getnewExecutionOrderId(self):
  1715             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1723             raise TypeError, _("%s body don't have instances!") % self.content.getLocalTag()
  1716     setattr(cls, "getcontentInstances", getcontentInstances)
  1724     setattr(cls, "getcontentInstances", getcontentInstances)
  1717 
  1725 
  1718     instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
  1726     instance_by_id_xpath = PLCOpen_XPath("*[@localId=$localId]")
  1719     instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]")
  1727     instance_by_name_xpath = PLCOpen_XPath("ppx:block[@instanceName=$name]")
       
  1728 
  1720     def getcontentInstance(self, local_id):
  1729     def getcontentInstance(self, local_id):
  1721         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1730         if self.content.getLocalTag() in ["LD", "FBD", "SFC"]:
  1722             instance = instance_by_id_xpath(self.content, localId=local_id)
  1731             instance = instance_by_id_xpath(self.content, localId=local_id)
  1723             if len(instance) > 0:
  1732             if len(instance) > 0:
  1724                 return instance[0]
  1733                 return instance[0]
  2411         self.content = None
  2420         self.content = None
  2412     setattr(cls, "removeconnections", removeconnections)
  2421     setattr(cls, "removeconnections", removeconnections)
  2413 
  2422 
  2414     connection_xpath = PLCOpen_XPath("ppx:connection")
  2423     connection_xpath = PLCOpen_XPath("ppx:connection")
  2415     connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]")
  2424     connection_by_position_xpath = PLCOpen_XPath("ppx:connection[position()=$pos]")
       
  2425 
  2416     def getconnections(self):
  2426     def getconnections(self):
  2417         return connection_xpath(self)
  2427         return connection_xpath(self)
  2418     setattr(cls, "getconnections", getconnections)
  2428     setattr(cls, "getconnections", getconnections)
  2419 
  2429 
  2420     def getconnection(self, idx):
  2430     def getconnection(self, idx):