Ejemplo n.º 1
0
 def test_client_Client_structures(self):
             
     # read the structure
     result = self.client.read( [self.address_vector] )
     
     self.assertTrue( isinstance(result.targets[0].data, ExtensionObject) )
     extensionObject = result.targets[0].data
     
     result = self.client.read( [self.address_vector] , attributeId = attributeids.DataType)
     
     dataTypeId = result.targets[0].data
     
     self.assertEqual( dataTypeId.identifier().idNumeric, 3002 )
     
     # using the datatypeId, get the definition of the structure
     definition = self.client.structureDefinition(dataTypeId)
     self.assertEqual( definition.isUnion(), False )
     self.assertEqual( definition.child(0).name(), 'X' )
     self.assertEqual( definition.child(1).valueType(), opcuatypes.Double )
     
     # using the original ExtensionObject the StructureDefinition, we can now create the GenericStructureValue:
     structureValue = GenericStructureValue(extensionObject, definition)
     
     # verify the structure:
     fieldType, opcUaStatusCode  = structureValue.valueType(0)
     self.assertEqual( fieldType, structurefielddatatypes.Variant )
     value, statuscode = structureValue.value(0)
     self.assertTrue( isinstance(value, primitives.Double ) )
     self.assertEquals(statuscode, 0)
     # now change the value of the first child (i = 0):
     structureValue.setField(0, primitives.Double(0.1) )
      
     # write back the structure
     newExtensionObject = ExtensionObject()
     structureValue.toExtensionObject(newExtensionObject)
     
     result = self.client.write( [self.address_vector], [newExtensionObject] )
     self.assertTrue( result.overallStatus.isGood() )
     
     result          = self.client.read( [self.address_vector] )
     extensionObject = result.targets[0].data
     structureValue  = GenericStructureValue(extensionObject, definition)
     value, statuscode = structureValue.value(0)
     self.assertEqual( value, primitives.Double(0.1) )
     self.assertEqual( statuscode, 0 )
Ejemplo n.º 2
0
result = myClient.read( [address] , attributeId = attributeids.DataType)

dataTypeId = result.targets[0].data # data represents a NodeId

print("The datatype of the ExtensionObject is: NodeId: %s" %dataTypeId)
print("")

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

print("The definition of the structure:")
print(str(definition))
print("")

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

# print the structure:
print("So we can now print the full structure:")
printStructure(structureValue)

# now change the value of the first child (i = 0):
structureValue.setField(0, primitives.Double(0.1))

# we can also change a field via its name:
structureValue.setField("Y", primitives.Double(0.2))

# write back the structure
newExtensionObject = ExtensionObject()
structureValue.toExtensionObject(newExtensionObject)
result = myClient.read([address], attributeId=attributeids.DataType)

dataTypeId = result.targets[0].data  # data represents a NodeId

print("The datatype of the ExtensionObject is: NodeId: %s" % dataTypeId)
print("")

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

print("The definition of the structure:")
print(str(definition))
print("")

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

# print the structure:
print("So we can now print the full structure:")
printStructure(structureValue)

# now change the value of the first child (i = 0):
structureValue.setField(0, primitives.Double(0.1))

# we can also change a field via its name:
structureValue.setField("Y", primitives.Double(0.2))

# write back the structure
newExtensionObject = ExtensionObject()
structureValue.toExtensionObject(newExtensionObject)