Exemple #1
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
 def __init__(self, rootElement, parentObject=None, forcedName=None ):
     plcElementXML.__init__( self, rootElement, parentObject, forcedName )
     self.disabled = "true"
     self.mainRoutineName = ""
     self.tags = []
     self.daughters.append(self.tags)
     
     # The prefix that gets added to program-scoped PLC tags in RSLogix5000 is "Program:" 
     self.prefix = "Program:" + self.name
     self.addNameToPath( self.prefix )
     
     # Check if this program is claimed to be disabled in the XML file, and skip its tags if it is
     if ( "Disabled" in self.root.attrib.keys() ):
         self.disabled = self.root.attrib["Disabled"]
         if( self.disabled == "true" ):
             print "Program <{0}> is disabled, skipping its tags".format( self.name )
     
     if( "MainRoutineName" in self.root.attrib.keys() ):
         self.mainRoutineName  =   self.root.attrib["MainRoutineName"]
     
     # Find all the Tag XML elements in the XML file and build the corresponding objects for them
     tagElms = self.root.xpath( "Tags/Tag")        
     for tagElm in tagElms:
         newTag = plcTag( tagElm, self  )
         self.tags.append( newTag )
     
     return
Exemple #3
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.structures = []
        self.daughters.append(self.structures)

        # ArrayElement (which corresponds to the Element XML tag) has to have Index attribute
        if ("Index" not in self.root.attrib.keys()):
            print "Structure in the array for tag <{0}> does not have Index. Exiting...".format(
                self.parent.name)
            sys.exit(-1)
        self.index = self.root.attrib["Index"]
        # At this point we do not deal with the index, just keep it as it is
        # If it needs to be linearized, we will have to do at a later stage
        self.name += self.index

        # REmove the dot from the end of the path and add the index piece to it
        self.removeLastDotFromPath()
        self.addNameToPath(self.index)

        # Find all daugher Structure XML elements and build the corresponding objects
        structElms = self.root.xpath("Structure")
        for structElm in structElms:
            newStruct = plcStructure(structElm, self)
            self.structures.append(newStruct)

        return
Exemple #4
0
    def __init__(self, rootElement, parentObject=None, forcedName=None):
        plcElementXML.__init__(self, rootElement, parentObject, forcedName)
        self.disabled = "true"
        self.mainRoutineName = ""
        self.tags = []
        self.daughters.append(self.tags)

        # The prefix that gets added to program-scoped PLC tags in RSLogix5000 is "Program:"
        self.prefix = "Program:" + self.name
        self.addNameToPath(self.prefix)

        # Check if this program is claimed to be disabled in the XML file, and skip its tags if it is
        if ("Disabled" in self.root.attrib.keys()):
            self.disabled = self.root.attrib["Disabled"]
            if (self.disabled == "true"):
                print "Program <{0}> is disabled, skipping its tags".format(
                    self.name)

        if ("MainRoutineName" in self.root.attrib.keys()):
            self.mainRoutineName = self.root.attrib["MainRoutineName"]

        # Find all the Tag XML elements in the XML file and build the corresponding objects for them
        tagElms = self.root.xpath("Tags/Tag")
        for tagElm in tagElms:
            newTag = plcTag(tagElm, self)
            self.tags.append(newTag)

        return
Exemple #5
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return
        self.structures = []
        self.daughters.append(self.structures)

        # ArrayElement (which corresponds to the Element XML tag) has to have Index attribute
        if "Index" not in self.root.attrib.keys():
            print "Structure in the array for tag <{0}> does not have Index. Exiting...".format(self.parent.name)
            sys.exit(-1)
        self.index = self.root.attrib["Index"]
        # At this point we do not deal with the index, just keep it as it is
        # If it needs to be linearized, we will have to do at a later stage
        self.name += self.index

        # REmove the dot from the end of the path and add the index piece to it
        self.removeLastDotFromPath()
        self.addNameToPath(self.index)

        # Find all daugher Structure XML elements and build the corresponding objects
        structElms = self.root.xpath("Structure")
        for structElm in structElms:
            newStruct = plcStructure(structElm, self)
            self.structures.append(newStruct)

        return
Exemple #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
Exemple #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.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
Exemple #8
0
    def __init__(self, rootElement, searchRoot=None):
        plcElementXML.__init__(self, rootElement)
        self.tags = []
        self.modules = []
        self.programs = []
        self.daughters.append(self.tags)
        self.daughters.append(self.modules)
        self.daughters.append(self.programs)
        self.processorType = ""
        self.nFailedAliases = 0

        # This static variable should not change while the controller tree is being built
        plcElementXML.treeSeacrh.rootObject = self  # Set the static variable

        if (searchRoot != None):
            # If searching tree is specified, then set it to what was sepcified
            plcElementXML.treeSeacrh.rootObject = searchRoot

        plcElementXML.treeSeacrh.nFailed = 0  # Number of failed searches is zero now

        # Get the processor type attribute
        if ("ProcessorType" in self.root.attrib.keys()):
            self.processorType = self.root.attrib["ProcessorType"]

        # Get all the modules
        moduleElements = self.root.xpath("Modules/Module")
        for moduleElm in moduleElements:
            newModule = plcModule(moduleElm, self)
            self.modules.append(newModule)

        # Get all the programs
        programElements = self.root.xpath("Programs/Program")
        for programElm in programElements:
            newProgram = plcProgram(programElm, self)
            self.programs.append(newProgram)

        # Get all controller scoped tags
        tagElms = self.root.xpath("Tags/Tag")
        for tagElm in tagElms:
            newTag = plcTag(tagElm, self)
            self.tags.append(newTag)

        self.nFailedAliases = plcElementXML.treeSeacrh.nFailed
        print "Number of failed searches is ", plcElementXML.treeSeacrh.nFailed

        return
    def __init__( self, rootElement, searchRoot=None ):
        plcElementXML.__init__( self, rootElement )
        self.tags = []
        self.modules = []
        self.programs = []
        self.daughters.append( self.tags )
        self.daughters.append( self.modules )
        self.daughters.append( self.programs )
        self.processorType = ""
        self.nFailedAliases = 0
            
        # This static variable should not change while the controller tree is being built            
        plcElementXML.treeSeacrh.rootObject = self      # Set the static variable

        if( searchRoot != None ) :
            # If searching tree is specified, then set it to what was sepcified
            plcElementXML.treeSeacrh.rootObject = searchRoot
            
        plcElementXML.treeSeacrh.nFailed = 0                    # Number of failed searches is zero now 
       
        # Get the processor type attribute
        if( "ProcessorType" in self.root.attrib.keys() ):
            self.processorType = self.root.attrib["ProcessorType"]
        
        # Get all the modules
        moduleElements = self.root.xpath("Modules/Module")
        for moduleElm in moduleElements:
            newModule = plcModule( moduleElm, self )
            self.modules.append( newModule )

        # Get all the programs
        programElements = self.root.xpath("Programs/Program")        
        for programElm in programElements:
            newProgram = plcProgram( programElm, self  )
            self.programs.append( newProgram )
            
        # Get all controller scoped tags
        tagElms = self.root.xpath( "Tags/Tag")        
        for tagElm in tagElms:
            newTag = plcTag( tagElm, self  )
            self.tags.append( newTag )

        self.nFailedAliases = plcElementXML.treeSeacrh.nFailed
        print "Number of failed searches is ", plcElementXML.treeSeacrh.nFailed

        return
Exemple #10
0
    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
Exemple #11
0
        def __init__( self, rootElement, parentObj ) :
            plcElementXML.__init__(self, rootElement, parentObj )            
            self.id = rootElement.attrib["Id"]
            self.address = ""
            self.type = ""
            self.upstream = ""
            
            if( "Id" in self.root.attrib.keys() ):
                self.Id = rootElement.attrib["Id"]
            else :
                print "Port in module <{0}> does not have Id. Exiting...".format(self.parentObj)
                sys.exit(-1)

            # Get the port attributes and return                
            if( "Address" in self.root.attrib.keys() ):
                self.address = rootElement.attrib["Address"]
            if( "Type" in self.root.attrib.keys() ):
                self.type = rootElement.attrib["Type"]               
            if( "Upstream" in self.root.attrib.keys() ):
                self.upstream = rootElement.attrib["Upstream"]                             
            return 
Exemple #12
0
    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
Exemple #13
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)

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

        # 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
Exemple #14
0
    def __init__(self, rootElement, parentObj):
        plcElementXML.__init__(self, rootElement, parentObj)
        self.id = rootElement.attrib["Id"]
        self.address = ""
        self.type = ""
        self.upstream = ""

        if ("Id" in self.root.attrib.keys()):
            self.Id = rootElement.attrib["Id"]
        else:
            print "Port in module <{0}> does not have Id. Exiting...".format(
                self.parentObj)
            sys.exit(-1)

        # Get the port attributes and return
        if ("Address" in self.root.attrib.keys()):
            self.address = rootElement.attrib["Address"]
        if ("Type" in self.root.attrib.keys()):
            self.type = rootElement.attrib["Type"]
        if ("Upstream" in self.root.attrib.keys()):
            self.upstream = rootElement.attrib["Upstream"]
        return
Exemple #15
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)

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

        # 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
Exemple #16
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

        self.structures = []
        self.arrayElements = []
        self.aliasTags = []
        self.daughters.append(self.structures)
        self.daughters.append(self.arrayElements)
        self.daughters.append(self.aliasTags)

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

        # If it is an alias create an alias tag and sotre it in the daughters and return
        # The alias tag will have no name, the daughter plcAliasTag itself will not contribute to path
        if (
            "TagType" in self.root.attrib.keys()
            and self.root.attrib["TagType"] == "Alias"
            and "AliasFor" in self.root.attrib.keys()
        ):
            aliasTag = plcAliasTag(self.root, self, "")
            self.aliasTags.append(aliasTag)
            return

        # If we got  here then the tag is not an alias to another tag
        # Refer to plcAliasTag class to what happens to the aliases

        # Check if the tag is an array and set the flag for future use
        self.isArray = False
        if self.dimensions != None:
            self.isArray = True

        self.createChildren()
        return
Exemple #17
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
Exemple #18
0
    def __init__(self, rootElement, parentObj=None, forcedName=None):
        try:
            plcElementXML.__init__(self, rootElement, parentObj, forcedName)
        except UselessDataType as err:
            print err
            return

        self.structures = []
        self.arrayElements = []
        self.aliasTags = []
        self.daughters.append(self.structures)
        self.daughters.append(self.arrayElements)
        self.daughters.append(self.aliasTags)

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

        # If it is an alias create an alias tag and sotre it in the daughters and return
        # The alias tag will have no name, the daughter plcAliasTag itself will not contribute to path
        if ("TagType" in self.root.attrib.keys()
                and self.root.attrib["TagType"] == "Alias"
                and "AliasFor" in self.root.attrib.keys()):
            aliasTag = plcAliasTag(self.root, self, "")
            self.aliasTags.append(aliasTag)
            return

        # If we got  here then the tag is not an alias to another tag
        # Refer to plcAliasTag class to what happens to the aliases

        # Check if the tag is an array and set the flag for future use
        self.isArray = False
        if (self.dimensions != None):
            self.isArray = True

        self.createChildren()
        return
Exemple #19
0
    def __init__(self, rootElement, parentObj=None):
        plcElementXML.__init__(self, rootElement, parentObj)
        self.confTags = []
        self.inTags = []
        self.outTags = []
        self.ports = []

        self.daughters.append(self.inTags)
        self.daughters.append(self.outTags)
        self.daughters.append(self.confTags)

        if (self.name == ""):
            self.name = "UnNamedModule" + str(plcModule.nUnNamed)
            plcModule.nUnNamed += 1

        if ("ParentModule" not in self.root.attrib.keys()):
            print "Module <{0}> does not have ParentModule XML attribute".format(
                self.name)
            sys.exit(-1)
        self.parentModuleName = self.root.attrib["ParentModule"]

        if ("ParentModPortId" not in self.root.attrib.keys()):
            print "Module <{0}> does not have ParentModPortId XML attribute".format(
                self.name)
            sys.exit(-1)
        self.parentModulePortID = self.root.attrib["ParentModPortId"]

        #        print "Creating Module named ", self.name, " type ", self.root.attrib["CatalogNumber"]

        # Get all the ports that have PointIO, Ethernet and ICP interfaces
        self.portElms = self.root.xpath(
            "Ports/Port[@Type='PointIO' or @Type='ICP' or @Type='Ethernet' or @Type='Compact']"
        )
        for portElm in self.portElms:
            #            print "Port: ", portElm.attrib
            newPort = plcPort(portElm, self)
            self.ports.append(newPort)

        subTagName = None
        #        if( self.parentModuleName != "Local" ):
        if (True):
            moduleIsControlled = False
            # Loopo over all the ports to see if the module tags will be called by its name or parents name
            # At this point we will go only one lever up, that is the module tags cannot be named after their grandparents.
            # It is either their name with address 0 or the parents name with the address of the corresponding port.
            portAddress = None
            for port in self.ports:
                if (port.upstream == "true"
                        and port.type in plcPort.controlledTypes):
                    # Apparently this means that this module is controlled from upstream
                    # Declare the module to be controlled by the parent and break out of the loop
                    moduleIsControlled = True
                    portAddress = port.address
                    break
            if (moduleIsControlled):
                #                subTagName = self.parentModuleName + ":" + self.parentModulePortID + ":"
                subTagName = self.parentModuleName + ":" + portAddress + ":"
            else:
                #                subTagName = self.name + ":0:"
                subTagName = self.name + ":"
        else:
            subTagName = self.name + ":0:"

#        print "SubTageName is ", subTagName

# Get all configuration tags for the module
        self.confTagElms = self.root.xpath(
            "Communications/ConfigTag[@ExternalAccess='Read/Write']")
        for tagElm in self.confTagElms:
            #            print "Tag: ", tagElm.attrib
            newTag = plcTag.plcTag(tagElm, self, subTagName + "C")
            self.confTags.append(newTag)

        # Get all input tags for the module
        self.inTagElms = self.root.xpath(
            "Communications/Connections/Connection/InputTag[@ExternalAccess='Read/Write']"
        )
        for tagElm in self.inTagElms:
            #            print "Tag: ", tagElm.attrib
            newTag = plcTag.plcTag(tagElm, self, subTagName + "I")
            self.inTags.append(newTag)

        # Get all output tags for the module
        self.outTagElms = self.root.xpath(
            "Communications/Connections/Connection/OutputTag[@ExternalAccess='Read/Write']"
        )
        for tagElm in self.outTagElms:
            #            print "Tag: ", tagElm.attrib
            newTag = plcTag.plcTag(tagElm, self, subTagName + "O")
            self.outTags.append(newTag)
        return
Exemple #20
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
Exemple #21
0
    def __init__(self, rootElement, parentObj=None ):
        plcElementXML.__init__(self, rootElement, parentObj )            
        self.confTags = []
        self.inTags = []
        self.outTags = []
        self.ports = []

        self.daughters.append(self.inTags)
        self.daughters.append(self.outTags)
        self.daughters.append(self.confTags)
        
        if( self.name == "" ):
            self.name = "UnNamedModule" + str(plcModule.nUnNamed)
            plcModule.nUnNamed += 1                         

        if( "ParentModule" not in self.root.attrib.keys() ):
            print "Module <{0}> does not have ParentModule XML attribute".format( self.name )
            sys.exit(-1)
        self.parentModuleName = self.root.attrib["ParentModule"]
        
        if( "ParentModPortId" not in self.root.attrib.keys() ):
            print "Module <{0}> does not have ParentModPortId XML attribute".format( self.name )
            sys.exit(-1)
        self.parentModulePortID = self.root.attrib["ParentModPortId"]
           
#        print "Creating Module named ", self.name, " type ", self.root.attrib["CatalogNumber"]
 
        # Get all the ports that have PointIO, Ethernet and ICP interfaces              
        self.portElms = self.root.xpath("Ports/Port[@Type='PointIO' or @Type='ICP' or @Type='Ethernet' or @Type='Compact']")
        for portElm in self.portElms:
#            print "Port: ", portElm.attrib
            newPort = plcPort( portElm, self )
            self.ports.append( newPort )
                
        subTagName = None                
#        if( self.parentModuleName != "Local" ):
        if( True ):
            moduleIsControlled = False
            # Loopo over all the ports to see if the module tags will be called by its name or parents name
            # At this point we will go only one lever up, that is the module tags cannot be named after their grandparents. 
            # It is either their name with address 0 or the parents name with the address of the corresponding port. 
            portAddress = None
            for port in self.ports: 
                if( port.upstream == "true" and port.type in plcPort.controlledTypes ):
                    # Apparently this means that this module is controlled from upstream
                    # Declare the module to be controlled by the parent and break out of the loop    
                    moduleIsControlled = True
                    portAddress = port.address
                    break
            if( moduleIsControlled ):                         
#                subTagName = self.parentModuleName + ":" + self.parentModulePortID + ":"
                subTagName = self.parentModuleName + ":" + portAddress + ":"
            else :
#                subTagName = self.name + ":0:"                       
                subTagName = self.name + ":"                       
        else :
            subTagName = self.name+ ":0:"               
                
#        print "SubTageName is ", subTagName
                        
        # Get all configuration tags for the module    
        self.confTagElms = self.root.xpath("Communications/ConfigTag[@ExternalAccess='Read/Write']")
        for tagElm in self.confTagElms :
#            print "Tag: ", tagElm.attrib 
            newTag = plcTag.plcTag(tagElm, self, subTagName+"C" )
            self.confTags.append(newTag)  
                    
        # Get all input tags for the module    
        self.inTagElms = self.root.xpath("Communications/Connections/Connection/InputTag[@ExternalAccess='Read/Write']")
        for tagElm in self.inTagElms :
#            print "Tag: ", tagElm.attrib 
            newTag = plcTag.plcTag(tagElm, self, subTagName+"I" )
            self.inTags.append(newTag)  

        # Get all output tags for the module    
        self.outTagElms = self.root.xpath("Communications/Connections/Connection/OutputTag[@ExternalAccess='Read/Write']")
        for tagElm in self.outTagElms :
#            print "Tag: ", tagElm.attrib 
            newTag = plcTag.plcTag(tagElm, self, subTagName+"O" )
            self.outTags.append(newTag)  
        return
Exemple #22
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