コード例 #1
0
result = myClient.read( [address] , attributeId = attributeids.DataType)
dataTypeId = result.targets[0].data # data represents a NodeId

# get the definition of the structure
definition = myClient.structureDefinition(dataTypeId)

# using the original ExtensionObject the StructureDefinition, we can now create the GenericStructureValue:
structureValue = GenericStructureValue(extensionObject, definition)

print("")
print("Let's read a structure which has an array of WorkOrder structures as child number 3:")
printStructure(structureValue)

print("")
print("Let's change one of the array items")
array, opcUaStatusCode = structureValue.genericStructureArray(3) # child number 3 of the main structure

if not SdkStatus(opcUaStatusCode).isGood():
    raise Exception("Oops, we could not get the structure array due to: %s" %SdkStatus(opcUaStatusCode))

status = array[1].setField(2, pyuaf.util.LocalizedText("en", "THIS FIELD WAS CHANGED!!!"))
assert status.isGood()

status = structureValue.setField(3, array)
assert status.isGood()

structureValue.toExtensionObject(extensionObject)

print("Now writing the modified structure")
print("")
try:
コード例 #2
0
# get the definition of the structure
definition = myClient.structureDefinition(dataTypeId)

# using the original ExtensionObject the StructureDefinition, we can now create the GenericStructureValue:
structureValue = GenericStructureValue(extensionObject, definition)

print("")
print(
    "Let's read a structure which has an array of WorkOrder structures as child number 3:"
)
printStructure(structureValue)

print("")
print("Let's change one of the array items")
array, opcUaStatusCode = structureValue.genericStructureArray(
    3)  # child number 3 of the main structure

if not SdkStatus(opcUaStatusCode).isGood():
    raise Exception("Oops, we could not get the structure array due to: %s" %
                    SdkStatus(opcUaStatusCode))

status = array[1].setField(
    2, pyuaf.util.LocalizedText("en", "THIS FIELD WAS CHANGED!!!"))
assert status.isGood()

status = structureValue.setField(3, array)
assert status.isGood()

structureValue.toExtensionObject(extensionObject)

print("Now writing the modified structure")