I am trying to read a structured type from a server at runtime. From what i gathered from this topic: http://forum.unified-automation.com/post1549.html , it is possible to read the data into a Dictionary. However, I cant find any documentation or example on how to perform this.
I am using the SDK version 2.4.0
I use the following code to read and parse data from the server.
Code: Select all
DataTypeManager mgr = new DataTypeManager(session);
DataValue result = readNode(eQ.m_session, obj.Variables["measurements"].nodeId); //this is a custom method
ExtensionObject[] extObs = (ExtensionObject[])(result.Value);
if (extObs != null)
{
List<KeyValue> keyValueList = new List<KeyValue>();
foreach (ExtensionObject extOb in extObs)
{
KeyValue kv = new KeyValue(); //custom object ( string key, string[] value, enum type )
GenericEncodeableObject tempObj = mgr.ParseValue(extOb);
Variant readValue;
if (tempObj.TryGetFieldValue("key", out readValue))
{
kv.key = readValue.ToString();
if (!kv.key.Equals(""))
{
tempObj.TryGetFieldValue("value", out readValue);
kv.value = readValue.ToStringArray();
tempObj.TryGetFieldValue("typeId", out readValue);
kv.typeId = (KeyValueType)readValue.ToInt32();
keyValueList.Add(kv);
}
}
}
}
With the following code I am able to read the dictionary and when inspecting the actual data i can see that it contains what i need.
The 2.4.0 changenotes say something about a generic object type:
but i dont see how i can get there from where i am now :Generic structured DataType support.
Adds a class for creating structured DataTypes at runtime. This class registers
the new structured DataType at the OPC UA communication stack.
Adds a class for setting values where the fields of the structure can be
accessed by name or by index.
Code: Select all
DataTypeManager mgr = new DataTypeManager(session);
DataTypeDictionary dict = mgr.GetDictionary(new ExpandedNodeId("PLC1Dictionary", 4));
BinarySchemaBuilder bd = new BinarySchemaBuilder(dict.SchemaData);