コード例 #1
0
ファイル: plcTag.py プロジェクト: rafopar/epics
    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
コード例 #2
0
ファイル: plcTag.py プロジェクト: JeffersonLab/hps-epics
    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
コード例 #3
0
ファイル: plcTag.py プロジェクト: rafopar/epics
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        # Inherit from plcTag since it does almost the same.
        # Finds the structures or sees that is is an arrays for scaler tags
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

#        self.array = None
        self.arrayElements = []
        self.daughters.append(self.arrayElements)

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

        # Array has to have a type
        if (self.dataType == ""):
            print "ArrayMember <{0}> does not have DataType".format(self.name)
            sys.exit(-1)

        # Array has to have dimensions
        if (self.dimensions == None or self.dimensions == ""):
            print "ArrayMemeber <{0}> does not have dimensions".format(
                self.name)
            sys.exit(-1)

        # Create the correct object and store it
        if (self.dataType in plcData.atomicTypes):
            # This is an array of atomic type
            self.array = plcData.plcArray(self.path, self.dataType,
                                          self.dimensions)
        else:
            # This is an array of user-specified structures
            # Loop through the elements and build the corresponding objects
            arrayElms = self.root.xpath("Element")
            for arrElm in arrayElms:
                newArrElm = plcArrayElement(arrElm, self)
                self.arrayElements.append(newArrElm)
#        print "Completed Array member <{0}>".format(self.name) + str(self)
        return
コード例 #4
0
ファイル: plcTag.py プロジェクト: JeffersonLab/hps-epics
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        # Inherit from plcTag since it does almost the same.
        # Finds the structures or sees that is is an arrays for scaler tags
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

        #        self.array = None
        self.arrayElements = []
        self.daughters.append(self.arrayElements)

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

        # Array has to have a type
        if self.dataType == "":
            print "ArrayMember <{0}> does not have DataType".format(self.name)
            sys.exit(-1)

        # Array has to have dimensions
        if self.dimensions == None or self.dimensions == "":
            print "ArrayMemeber <{0}> does not have dimensions".format(self.name)
            sys.exit(-1)

        # Create the correct object and store it
        if self.dataType in plcData.atomicTypes:
            # This is an array of atomic type
            self.array = plcData.plcArray(self.path, self.dataType, self.dimensions)
        else:
            # This is an array of user-specified structures
            # Loop through the elements and build the corresponding objects
            arrayElms = self.root.xpath("Element")
            for arrElm in arrayElms:
                newArrElm = plcArrayElement(arrElm, self)
                self.arrayElements.append(newArrElm)
        #        print "Completed Array member <{0}>".format(self.name) + str(self)
        return