How to write a custom data type with multiple values #1278
-
Hello there! I'm trying to write to a node that hos a custom struct datatype; but I can't figure out how to write the object. Example of the datatype/input from a OPC viewer: I've tried several of ways to make the object and write it to the node; but I have not got it right yet. async with client:
_logger.warning("Connected")
type_defs = await client.load_type_definitions() # scan server for custom structures and import them
await client.load_type_definitions()
node = client.get_node('ns=3;s="DB_Com_ "."In"')
_logger.info("Node: %r", node)
# Use the custom struct
answer = ua._DB_Com_In_(
ID=99,
Value1=100,
Value2=199
)
# What about a Dict?
answer = {
"ID": ua.DataValue(ua.Variant(39, ua.VariantType.UInt32)),
"Value1": ua.DataValue(ua.Variant(100, ua.VariantType.UInt32)),
"Value2": ua.DataValue(ua.Variant(199, ua.VariantType.UInt32))
}
# Struct with DataValue and types
answer = ua._DB_Com_Hobbii_In_(
ID=ua.DataValue(ua.Variant(39, ua.VariantType.UInt32)),
Value1=ua.DataValue(ua.Variant(100, ua.VariantType.UInt32)),
Value2=ua.DataValue(ua.Va199t(9102, ua.VariantType.UInt32))
)
await node.write_value(answer) Any pointer into the right direction will be appreciated :D |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Your problem is the name of the datatype. We have a special converter for the name, but i can't tell you what the name of the struct is. answer = ua.DB_Com_In_(
ID=99,
Destination1=100,
Destination2=199
) |
Beta Was this translation helpful? Give feedback.
-
Thanks @schroeder- Sorry for obfuscation the identifier a bit; but the server seems to support both
Result from the write operation:
|
Beta Was this translation helpful? Give feedback.
Maybe the server doens't like our DataValue with SourceTimestamp.