Hello,
I am trying to create basic server with a custom object type and custom structure.
However I have trouble to initialize the structure in the server side code when the structure have arrays in it.
I based my tries on the webinar videos and examples.
When I start the server I can connect via UaExpert , I see my structured variable and I can expand it in the address space view seeing all the children.
However they are all not initialized if the structure has some array variables. If there are no arrays everything is fine.
Would be great if you could show me an example similar to the webinar code how to initialize structure which contains arrays.
My initialization code for my model looks like this:
MyModel = new Model.TestModel();
MyModel.VDouble.Value = 0;
MyModel.VInt.Value = 0;
MyModel.VArray = str; //str is a array of strings
Model.MyStruct t = new Model.MyStruct();
SetVariableDefaultValue(rootId, new Variant(t));
MyModel.VStructure = = new Model.MyStructModel() { Value = t };
Also how can I write new values into the structure from the client?
Thanks a lot!
Initializing structures
Moderator: uasdknet
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Initializing structures
Hello,
You did not tell us how your structured DataType is defined. So we created a structured DataType containg a double and a double array as fields. We also creates an ObjectType similar to the ObjectType of your post. The DataType, the ObjectType and an instance of the ObjectType have been created using UaModeler.
The following code sets the values of the Variables of the instance using LinkModelToNode:
Please see the tutorial of UaModeler for the client side usage of structured DataTypes that are known at compile time: documentation.
Best regards
Support Team
You did not tell us how your structured DataType is defined. So we created a structured DataType containg a double and a double array as fields. We also creates an ObjectType similar to the ObjectType of your post. The DataType, the ObjectType and an instance of the ObjectType have been created using UaModeler.
The following code sets the values of the Variables of the instance using LinkModelToNode:
Code: Select all
TestModel MyModel = new TestModel();
MyModel.VDouble = 0;
MyModel.VInt = 0;
string[] str = new string[] { "OPC UA", "is", "great" };
MyModel.VArray = str;
TestStructure t = new TestStructure()
{
Double = 1.11,
DoubleArray = new DoubleCollection()
};
t.DoubleArray.Add(1.11);
t.DoubleArray.Add(2.22);
MyModel.VStructure = t;
LinkModelToNode(
ObjectIds.Test.ToNodeId(Server.NamespaceUris),
MyModel,
null,
null,
500);
Best regards
Support Team