Пример #1
0
    def __init__(self, rootElement, parentObj, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.value = ""
        self.radix = ""
        #        self.scalar = None

        # For tags name contributes to the path
        self.addNameToPath(self.name)

        # Data value member has to have a name
        if self.name == "":
            print "No name specified for DataValueMemeber of tag <{0}>".format(self.parent.name)
            sys.exit(-1)
        # Data value member has to have a type
        if self.dataType == "":
            print "DataType is no specified for DataValueMember <{0}>".format(self.name)
            sys.exit(-1)

        # Get defualt value and "Radix"
        if "Value" in rootElement.attrib.keys():
            self.value = rootElement.attrib["Value"]
        if "Radix" in rootElement.attrib.keys():
            self.radix = rootElement.attrib["Radix"]

        # Create the scalar data object and store its reference in the objects attribute
        self.scalar = plcData.plcScalar(self.path, self.dataType, self.value, self.radix)

        #        print "Finished constructing DataValueMemeber <{0}>".format( self.path )

        return
Пример #2
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

        self.dataValueMembers = []
        self.arrayMembers = []
        self.structureMembers = []

        self.daughters.append(self.dataValueMembers)
        self.daughters.append(self.arrayMembers)
        self.daughters.append(self.structureMembers)

        if (self.name == ""):
            print "StrucureMember of <{0}> does not have a name. Exiting...".format(
                self.parent.name)

        # The name can contribute to the path
        self.addNameToPath(self.name)

        # Check to see if DataType is defined
        if (self.dataType == ""):
            print "Structure {0} does not know its DataType".format(self.name)
            sys.exit(-1)

        if (self.dataType in plcData.atomicTypes):
            # This tag is PLC atomic type, it seems like it can only be scalar
            # Assume that this is a scalar number of atomic type. Define the scaler data
            # and move on
            dataValue = None
            dataRadix = ""
            if ("Radix" in self.root.attrib.keys()):
                dataRadix = self.root.attrib["Radix"]
            if ("Value" in self.root.attrib.keys()):
                dataValue = self.root.attrib["Value"]
            self.scalar = plcData.plcScalar(self.path, self.dataType,
                                            dataValue, dataRadix)
            return

        # Get all DataValueMembers. Here it is pretty straightforward
        dvElms = self.root.xpath("DataValueMember")
        for dvElm in dvElms:
            newDataValue = plcDataValueMember(dvElm, self)
            self.dataValueMembers.append(newDataValue)

        # Get all ArrayMembers inside this tag
        amElms = self.root.xpath("ArrayMember")
        for amElm in amElms:
            newArray = plcArrayMember(amElm, self)
            self.arrayMembers.append(newArray)

        # Get all StructureMEmbers inside this tag
        smElms = self.root.xpath("StructureMember")
        for smElm in smElms:
            newStruct = plcStructureMember(smElm, self)
            self.structureMembers.append(newStruct)

        return
Пример #3
0
    def createChildren(self):
        if ((self.dataType != "") and (self.dataType in plcData.atomicTypes)):
            # This tag is PLC atomic type, not sure yet if it is scalar or array

            if (not self.isArray):
                # This is a scalar number of atomic type. Define the scaler data
                # and move on
                dataValue = None
                dataRadix = ""
                if ("Radix" in self.root.attrib.keys()):
                    dataRadix = self.root.attrib["Radix"]
                if ("Value" in self.root.attrib.keys()):
                    dataValue = self.root.attrib["Value"]
                self.scalar = plcData.plcScalar(self.path, self.dataType,
                                                dataValue, dataRadix)
            else:
                # This is an array if atomic elements. Create an array of atomic elemtss
                self.array = plcData.plcArray(self.path, self.dataType,
                                              self.dimensions)
        else:
            # This is not an atomic type tag, not sure yet scalar or array
            if (not self.isArray):
                # If the DataType is not a PLC type  then it has to be a structure
                # Get all structure elements in the tag element. There should be only one!
                self.structElms = self.root.xpath(
                    "Data[@Format='Decorated']/Structure")
                if (len(self.structElms) != 1):
                    print "Tag <{0}> does not contain data strcuture".format(
                        self.name)
                    return
                for structElm in self.structElms:
                    #                    print "Data Structure: ", structElm.attrib
                    # For tags that do not have name but the structure does we may want to use
                    # the structure name in the path. Need to switch if decide to it that way
                    if (self.name == ""
                            and "DataType" in structElm.attrib.keys()):
                        #                        self.path += plcElementXML.elementSeparator + structElm.attrib["DataType"]
                        self.name = "UnNamedTag" + str(plcTag.nUnNamed)
                        self.addNameToPath(self.name)
                        #                        self.addNameToPath( structElm.attrib["DataType"] )
                        plcTag.nUnNamed += 1
                    elif (self.name == ""):
                        self.name = "UnNamedTag" + str(plcTag.nUnNamed)
                        self.addNameToPath(self.name)
                        plcTag.nUnNamed += 1

                    # Create the new structure object and store it in the list of structures
                    newStruct = plcStructure(structElm, self)
                    self.structures.append(newStruct)
            else:
                # This is am arrasy of user-defined structures. Find all Elements define under it in the XML file
                # and create correspondinf ArrayElement objects.
                arrayElms = self.root.xpath(
                    "Data/Array[@DataType=$dt]/Element", dt=self.dataType)
                for arrElm in arrayElms:
                    newArrElm = plcArrayElement(arrElm, self)
                    self.arrayElements.append(newArrElm)
        return
Пример #4
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

        self.dataValueMembers = []
        self.arrayMembers = []
        self.structureMembers = []

        self.daughters.append(self.dataValueMembers)
        self.daughters.append(self.arrayMembers)
        self.daughters.append(self.structureMembers)

        if self.name == "":
            print "StrucureMember of <{0}> does not have a name. Exiting...".format(self.parent.name)

        # The name can contribute to the path
        self.addNameToPath(self.name)

        # Check to see if DataType is defined
        if self.dataType == "":
            print "Structure {0} does not know its DataType".format(self.name)
            sys.exit(-1)

        if self.dataType in plcData.atomicTypes:
            # This tag is PLC atomic type, it seems like it can only be scalar
            # Assume that this is a scalar number of atomic type. Define the scaler data
            # and move on
            dataValue = None
            dataRadix = ""
            if "Radix" in self.root.attrib.keys():
                dataRadix = self.root.attrib["Radix"]
            if "Value" in self.root.attrib.keys():
                dataValue = self.root.attrib["Value"]
            self.scalar = plcData.plcScalar(self.path, self.dataType, dataValue, dataRadix)
            return

        # Get all DataValueMembers. Here it is pretty straightforward
        dvElms = self.root.xpath("DataValueMember")
        for dvElm in dvElms:
            newDataValue = plcDataValueMember(dvElm, self)
            self.dataValueMembers.append(newDataValue)

        # Get all ArrayMembers inside this tag
        amElms = self.root.xpath("ArrayMember")
        for amElm in amElms:
            newArray = plcArrayMember(amElm, self)
            self.arrayMembers.append(newArray)

        # Get all StructureMEmbers inside this tag
        smElms = self.root.xpath("StructureMember")
        for smElm in smElms:
            newStruct = plcStructureMember(smElm, self)
            self.structureMembers.append(newStruct)

        return
Пример #5
0
    def createChildren(self):
        if (self.dataType != "") and (self.dataType in plcData.atomicTypes):
            # This tag is PLC atomic type, not sure yet if it is scalar or array

            if not self.isArray:
                # This is a scalar number of atomic type. Define the scaler data
                # and move on
                dataValue = None
                dataRadix = ""
                if "Radix" in self.root.attrib.keys():
                    dataRadix = self.root.attrib["Radix"]
                if "Value" in self.root.attrib.keys():
                    dataValue = self.root.attrib["Value"]
                self.scalar = plcData.plcScalar(self.path, self.dataType, dataValue, dataRadix)
            else:
                # This is an array if atomic elements. Create an array of atomic elemtss
                self.array = plcData.plcArray(self.path, self.dataType, self.dimensions)
        else:
            # This is not an atomic type tag, not sure yet scalar or array
            if not self.isArray:
                # If the DataType is not a PLC type  then it has to be a structure
                # Get all structure elements in the tag element. There should be only one!
                self.structElms = self.root.xpath("Data[@Format='Decorated']/Structure")
                if len(self.structElms) != 1:
                    print "Tag <{0}> does not contain data strcuture".format(self.name)
                    return
                for structElm in self.structElms:
                    #                    print "Data Structure: ", structElm.attrib
                    # For tags that do not have name but the structure does we may want to use
                    # the structure name in the path. Need to switch if decide to it that way
                    if self.name == "" and "DataType" in structElm.attrib.keys():
                        #                        self.path += plcElementXML.elementSeparator + structElm.attrib["DataType"]
                        self.name = "UnNamedTag" + str(plcTag.nUnNamed)
                        self.addNameToPath(self.name)
                        #                        self.addNameToPath( structElm.attrib["DataType"] )
                        plcTag.nUnNamed += 1
                    elif self.name == "":
                        self.name = "UnNamedTag" + str(plcTag.nUnNamed)
                        self.addNameToPath(self.name)
                        plcTag.nUnNamed += 1

                    # Create the new structure object and store it in the list of structures
                    newStruct = plcStructure(structElm, self)
                    self.structures.append(newStruct)
            else:
                # This is am arrasy of user-defined structures. Find all Elements define under it in the XML file
                # and create correspondinf ArrayElement objects.
                arrayElms = self.root.xpath("Data/Array[@DataType=$dt]/Element", dt=self.dataType)
                for arrElm in arrayElms:
                    newArrElm = plcArrayElement(arrElm, self)
                    self.arrayElements.append(newArrElm)
        return
Пример #6
0
    def __init__(self, rootElement, parentObj, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.value = ""
        self.radix = ""
        #        self.scalar = None

        # For tags name contributes to the path
        self.addNameToPath(self.name)

        # Data value member has to have a name
        if (self.name == ""):
            print "No name specified for DataValueMemeber of tag <{0}>".format(
                self.parent.name)
            sys.exit(-1)
        # Data value member has to have a type
        if (self.dataType == ""):
            print "DataType is no specified for DataValueMember <{0}>".format(
                self.name)
            sys.exit(-1)

        # Get defualt value and "Radix"
        if ("Value" in rootElement.attrib.keys()):
            self.value = rootElement.attrib["Value"]
        if ("Radix" in rootElement.attrib.keys()):
            self.radix = rootElement.attrib["Radix"]

        # Create the scalar data object and store its reference in the objects attribute
        self.scalar = plcData.plcScalar(self.path, self.dataType, self.value,
                                        self.radix)

        #        print "Finished constructing DataValueMemeber <{0}>".format( self.path )

        return
Пример #7
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.targets = []
        #        self.scalar = None
        self.daughters.append(self.targets)

        # Double check that this is an Alias tag in the XML file. If not then exit.
        if ("AliasFor" not in self.root.attrib.keys()
                or "TagType" not in self.root.attrib.keys()
                or self.root.attrib["TagType"] != "Alias"):
            print "Either AliasFor or TagType attributes missing for alias tag <{0}>. Exiting...".format(
                self.root.name)
            sys.exit(-1)

        # Find the target of this alias to get the datatype or the substructure for it
        self.tgtName = self.root.attrib["AliasFor"]

        isArrayElement = self.checkPattern4ArrayElement(self.tgtName)
        isBitElement = self.checkPattern4BitElement(self.tgtName)

        if (not isArrayElement and not isBitElement):
            # The alias target is neither an array element nor a bit of an integral type
            # It is the most straightforward case when the alias is defined by actual target tag name
            # Find the target element such that the path of the object is identical to the name
            # given in the alias definition in the XML file. This is done so that the internal structure,
            # if any can be traced
            tgtTag = self.findTargetElm(self.tgtName)
            if (tgtTag != None):
                tgtElm = tgtTag.root
                # Create names less plcTag or plcAliasTag objects and store them
                if ("DataType" in tgtElm.attrib.keys()
                        and tgtElm.attrib["DataType"] in plcData.atomicTypes):
                    # Target is not  an alias, the target will have empty name
                    newTag = plcTag(tgtElm, self, "")
                    self.targets.append(newTag)
                else:
                    # The target will be an alias too, the target will have empty name
                    #                    newAliasTag = plcAliasTag( tgtElm, self, "" )
                    newTag = plcTag(tgtElm, self, "")
                    self.targets.append(newTag)
            else:
                # Did not find the target by that name (path to be precise)
                print "No target found for Alias <{0}>".format(self.name)
        elif (isArrayElement):
            # It is an element of an array. It cannot be an alias
            #            print "Looking for array element for alias <{0}>".format( self.tgtName )
            strippedName = self.stripAliasBrackets(
                self.tgtName)  # Strip the bracket part off from the right side
            tgtTag = self.findTargetElm(
                strippedName
            )  # Find  the target that corresponds to the array name
            # Keep stripping the last brackets until the tagret is not an array element
            while (tgtTag != None
                   and self.checkPattern4ArrayElement(tgtTag.name)):
                strippedName = self.stripAliasBrackets(
                    self.tgtName
                )  # Strip the bracket part off from the right side
                tgtTag = self.findTargetElm(strippedName)
            # Once the target is not an array element we will be able to determine the type of the alias tag
            if (tgtTag != None):  # At least one target was found for the array
                # Get the structure of the array elemement based on the structure of the array found
                if (tgtTag.dataType in plcData.atomicTypes):
                    # Atomic type. Add the bracket string to the path, create a scaler and keep the value in the scalar list
                    #                    self.addNameToPath( self.name )
                    self.scalar = plcData.plcScalar(self.path, tgtTag.dataType,
                                                    None, None)
                else:
                    # Target is a user-defined tructure
                    parentTag = plcTag(tgtTag.root, self,
                                       "")  # Array tag will be target, no name
                    self.targets.append(parentTag)
            else:
                # Did not find the target by that name (path to be precise)
                print "No target found for Alias <{0}>, was looking for array <{1}>".format(
                    self.name, strippedName)
        elif (isBitElement):
            # Since we know it is a bit, we do not care what the target is and we simply create a BIT scalar object
            self.scalar = plcData.plcScalar(self.path, "BIT", None, "Binary")

#        print "Finished dealing with alias", str(self) + "\n"
        return
Пример #8
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.targets = []
        #        self.scalar = None
        self.daughters.append(self.targets)

        # Double check that this is an Alias tag in the XML file. If not then exit.
        if (
            "AliasFor" not in self.root.attrib.keys()
            or "TagType" not in self.root.attrib.keys()
            or self.root.attrib["TagType"] != "Alias"
        ):
            print "Either AliasFor or TagType attributes missing for alias tag <{0}>. Exiting...".format(self.root.name)
            sys.exit(-1)

        # Find the target of this alias to get the datatype or the substructure for it
        self.tgtName = self.root.attrib["AliasFor"]

        isArrayElement = self.checkPattern4ArrayElement(self.tgtName)
        isBitElement = self.checkPattern4BitElement(self.tgtName)

        if not isArrayElement and not isBitElement:
            # The alias target is neither an array element nor a bit of an integral type
            # It is the most straightforward case when the alias is defined by actual target tag name
            # Find the target element such that the path of the object is identical to the name
            # given in the alias definition in the XML file. This is done so that the internal structure,
            # if any can be traced
            tgtTag = self.findTargetElm(self.tgtName)
            if tgtTag != None:
                tgtElm = tgtTag.root
                # Create names less plcTag or plcAliasTag objects and store them
                if "DataType" in tgtElm.attrib.keys() and tgtElm.attrib["DataType"] in plcData.atomicTypes:
                    # Target is not  an alias, the target will have empty name
                    newTag = plcTag(tgtElm, self, "")
                    self.targets.append(newTag)
                else:
                    # The target will be an alias too, the target will have empty name
                    #                    newAliasTag = plcAliasTag( tgtElm, self, "" )
                    newTag = plcTag(tgtElm, self, "")
                    self.targets.append(newTag)
            else:
                # Did not find the target by that name (path to be precise)
                print "No target found for Alias <{0}>".format(self.name)
        elif isArrayElement:
            # It is an element of an array. It cannot be an alias
            #            print "Looking for array element for alias <{0}>".format( self.tgtName )
            strippedName = self.stripAliasBrackets(self.tgtName)  # Strip the bracket part off from the right side
            tgtTag = self.findTargetElm(strippedName)  # Find  the target that corresponds to the array name
            # Keep stripping the last brackets until the tagret is not an array element
            while tgtTag != None and self.checkPattern4ArrayElement(tgtTag.name):
                strippedName = self.stripAliasBrackets(self.tgtName)  # Strip the bracket part off from the right side
                tgtTag = self.findTargetElm(strippedName)
            # Once the target is not an array element we will be able to determine the type of the alias tag
            if tgtTag != None:  # At least one target was found for the array
                # Get the structure of the array elemement based on the structure of the array found
                if tgtTag.dataType in plcData.atomicTypes:
                    # Atomic type. Add the bracket string to the path, create a scaler and keep the value in the scalar list
                    #                    self.addNameToPath( self.name )
                    self.scalar = plcData.plcScalar(self.path, tgtTag.dataType, None, None)
                else:
                    # Target is a user-defined tructure
                    parentTag = plcTag(tgtTag.root, self, "")  # Array tag will be target, no name
                    self.targets.append(parentTag)
            else:
                # Did not find the target by that name (path to be precise)
                print "No target found for Alias <{0}>, was looking for array <{1}>".format(self.name, strippedName)
        elif isBitElement:
            # Since we know it is a bit, we do not care what the target is and we simply create a BIT scalar object
            self.scalar = plcData.plcScalar(self.path, "BIT", None, "Binary")

        #        print "Finished dealing with alias", str(self) + "\n"
        return