def printStructure(structure, indentation=""): """ Print a structure. Parameters: structure: a pyuaf.util.GenericStructureValue instance. May represent a structure or union or optionset. indentation: a string to print at the beginning of each line (to add indentation when this function is called recursively). """ # get the definition of the structure: definition = structure.definition() # we'll print the contents of the structure print(indentation + "Structure contents:") # loop through the fields of the structure, by looking at the definition: for i in xrange(definition.childrenCount()): # retrieve information both from the definition and from the structure itself: child = definition.child(i) childName = child.name() # a string childType = child.valueType() # datatype, e.g. Double fieldType, opcUaStatusCode = structure.valueType( i) # e.g. Variant, GenericStructure, GenericStructureArray... if not SdkStatus(opcUaStatusCode).isGood(): raise Exception("Oops, we could not get the valueType due to: %s" % SdkStatus(opcUaStatusCode)) print(indentation + " * child number %d:" % i) print(indentation + " - child name = %s" % childName) print(indentation + " - child type = %d (%s)" % (childType, opcuatypes.toString(childType))) print(indentation + " - field type = %s (%s)" % (fieldType, structurefielddatatypes.toString(fieldType))) if fieldType == structurefielddatatypes.Variant: value, opcUaStatusCode = structure.value(i) print(indentation + " - value = %s" % value) elif fieldType == structurefielddatatypes.GenericStructure: print(indentation + " - value:") # recursive call printStructure(structureValue.genericStructureValue(i), indentation + " ") elif fieldType == structurefielddatatypes.GenericStructureArray: array, opcUaStatusCode = structureValue.genericStructureArray(i) if not SdkStatus(opcUaStatusCode).isGood(): raise Exception( "Oops, we could not get the structure due to: %s" % SdkStatus(opcUaStatusCode)) print(indentation + " - value:") # recursive calls to all array items: for j in xrange(len(array)): print(indentation + " array[%d]:" % j) printStructure(array[j], indentation + " ") print("") # empty line
def printStructure(structure, indentation=""): """ Print a structure. Parameters: structure: a pyuaf.util.GenericStructureValue instance. May represent a structure or union or optionset. indentation: a string to print at the beginning of each line (to add indentation when this function is called recursively). """ # get the definition of the structure: definition = structure.definition() # we'll print the contents of the structure print(indentation + "Structure contents:") # loop through the fields of the structure, by looking at the definition: for i in range(definition.childrenCount()): # retrieve information both from the definition and from the structure itself: child = definition.child(i) childName = child.name() # a string childType = child.valueType() # datatype, e.g. Double fieldType, opcUaStatusCode = structure.valueType(i) # e.g. Variant, GenericStructure, GenericStructureArray... if not SdkStatus(opcUaStatusCode).isGood(): raise Exception("Oops, we could not get the valueType due to: %s" %SdkStatus(opcUaStatusCode)) print(indentation + " * child number %d:" %i) print(indentation + " - child name = %s" %childName) print(indentation + " - child type = %d (%s)" %(childType, opcuatypes.toString(childType))) print(indentation + " - field type = %s (%s)" %(fieldType, structurefielddatatypes.toString(fieldType))) if fieldType == structurefielddatatypes.Variant: value, opcUaStatusCode = structure.value(i) print(indentation + " - value = %s" %value) elif fieldType == structurefielddatatypes.GenericStructure: print(indentation + " - value:") # recursive call printStructure(structureValue.genericStructureValue(i), indentation + " ") elif fieldType == structurefielddatatypes.GenericStructureArray: array, opcUaStatusCode = structureValue.genericStructureArray(i) if not SdkStatus(opcUaStatusCode).isGood(): raise Exception("Oops, we could not get the structure due to: %s" %SdkStatus(opcUaStatusCode)) print(indentation + " - value:") # recursive calls to all array items: for j in range(len(array)): print(indentation + " array[%d]:" %j) printStructure(array[j], indentation + " ") print("") # empty line
def printUnion(union, indentation=""): """ Print a structure. Parameters: union: a pyuaf.util.GenericUnionValue instance. indentation: a string to print at the beginning of each line (to add indentation when this function is called recursively). """ # get the definition of the structure: definition = union.definition() # we'll print the contents of the structure print(indentation + "Union contents:") if not definition.isUnion(): raise Exception("The given union is no union!") # let's show the possible values by looking at the definition: for i in xrange(definition.childrenCount()): # retrieve information both from the definition and from the structure itself: child = definition.child(i) childName = child.name() # a string childType = child.valueType() # datatype, e.g. Double print(indentation + " * child number %d:" % i) print(indentation + " - child name = %s" % childName) print(indentation + " - child type = %d (%s)" % (childType, opcuatypes.toString(childType))) # show the active value (the "switchValue") switchValue = union.switchValue() field = union.field() print(indentation + "Switch value: %d" % switchValue) print(indentation + "Field name: %s" % union.field().name()) print(indentation + "Value: %s" % union.value()) print("") # empty line
def printUnion(union, indentation=""): """ Print a structure. Parameters: union: a pyuaf.util.GenericUnionValue instance. indentation: a string to print at the beginning of each line (to add indentation when this function is called recursively). """ # get the definition of the structure: definition = union.definition() # we'll print the contents of the structure print(indentation + "Union contents:") if not definition.isUnion(): raise Exception("The given union is no union!") # let's show the possible values by looking at the definition: for i in range(definition.childrenCount()): # retrieve information both from the definition and from the structure itself: child = definition.child(i) childName = child.name() # a string childType = child.valueType() # datatype, e.g. Double print(indentation + " * child number %d:" %i) print(indentation + " - child name = %s" %childName) print(indentation + " - child type = %d (%s)" %(childType, opcuatypes.toString(childType))) # show the active value (the "switchValue") switchValue = union.switchValue() field = union.field() print(indentation + "Switch value: %d" %switchValue) print(indentation + "Field name: %s" %union.field().name()) print(indentation + "Value: %s" %union.value()) print("") # empty line