I'm attempting to define and use structures in my implementation of a .net opc-ua server. I've been able to define my new structure type (using the uamodeler to ease the generation of the xml file and class file), and I can see the new structure data type and it's field definitions in uaExpert - so far so good. But what is the correct way to instantiate and return a 'structure' data item in response to a read request? There is no documentation on this, and no code examples to draw from.
Regards,
Nathan
Structures and ExtensionObjects
Moderator: uasdknet
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Structures and ExtensionObjects
Hi Nathan,
I am wondering about the fact, that you can see the field definitions of the structured DataType in UaExpert. You can only see the structure definition in UaModeler, UaExpert does not support this feature. Did you add a VariableType in addition to the structured DataType?
For using the structured DataType for Read you have to
To test reading and writing values of complex DataTypes you have to implement your own client. Have a look at the documentation of the UaModeler to get a code example.
I am wondering about the fact, that you can see the field definitions of the structured DataType in UaExpert. You can only see the structure definition in UaModeler, UaExpert does not support this feature. Did you add a VariableType in addition to the structured DataType?
For using the structured DataType for Read you have to
- create the complex value
- create an ExtensionObject
- create a DataValue
Code: Select all
protected override DataValue Read(
RequestContext context,
NodeAttributeHandle nodeHandle,
string indexRange,
QualifiedName dataEncoding)
{
if (nodeHandle.AttributeId == Attributes.Value
&& nodeHandle.NodeId.Equals(new NodeId(ComplexNodeIdIdentifier, NamespaceIndex)))
{
Vector value = new Vector()
{
X = 12,
Y = 24,
Z = 36
};
ExtensionObject e = new ExtensionObject(value);
Variant v = new Variant(e);
DataValue ret = new DataValue(v);
return ret;
}
return base.Read(context, nodeHandle, indexRange, dataEncoding);
}
-
- Sr. Member
- Posts: 14
- Joined: 16 Oct 2012, 16:33
Re: Structures and ExtensionObjects
Well, yes - that's true - I am not seeing the structure items under DataTypes->Structure.myStructure, but it does appear under Variable Types.
I guess that confirms essentially what I was trying to accomplish and surmised those were the steps based on what I could glean from the class definitions and some bits of information I found - however, I was not able to get the same result as say - ServerStatus - so I'm guessing there is some other technique involved - i.e. it's not using an ExtensionObject?
I see that the ServerStatus has a DataType defined under Structure, it also has a VariableType defined, but the elements of the ServerStatus structure appear when browsing in UAExpert. When I used the ExtensionObject, all I could see was "ExtensionObject" and no structure data.
So what is the difference in implementation between a Structure wrapped in an ExtensionObject, and the ServerStatus Structure?
Regards,
Nathan
I guess that confirms essentially what I was trying to accomplish and surmised those were the steps based on what I could glean from the class definitions and some bits of information I found - however, I was not able to get the same result as say - ServerStatus - so I'm guessing there is some other technique involved - i.e. it's not using an ExtensionObject?
I see that the ServerStatus has a DataType defined under Structure, it also has a VariableType defined, but the elements of the ServerStatus structure appear when browsing in UAExpert. When I used the ExtensionObject, all I could see was "ExtensionObject" and no structure data.
So what is the difference in implementation between a Structure wrapped in an ExtensionObject, and the ServerStatus Structure?
Regards,
Nathan
- Support Team
- Hero Member
- Posts: 3072
- Joined: 18 Mar 2011, 15:09
Re: Structures and ExtensionObjects
Hi Nathan,
I try to explain the differences between complex DataTypes and VariableTypes with the example of ServerStatusDataType and ServerStatusType.
The ServerStatusType exposes the fields of the ServerStatusDataType as components in the AddressSpace. This allows access to simple values (e.g. CurrentTime) as well as access to the whole information at once in a transactional context (the value of the "root" node of the type contains the whole information in an ExtensionObject).
This solution has the following advatages:
The .NET SDK does not contain utility functions to keep the values constistent. It depends on the concrete use case to decide on an way of implementation.
In a first step you can use "SetVariableDefaultValuemethod" of the BaseNodeManage for each component of the type if the structure changes. Depending on the use case you can make optimizations (e.g. implementing Read, Write and Subscribe methods of the NodeManager) in a second step.
Best regards,
Unified Automation Support Team
I try to explain the differences between complex DataTypes and VariableTypes with the example of ServerStatusDataType and ServerStatusType.
The ServerStatusType exposes the fields of the ServerStatusDataType as components in the AddressSpace. This allows access to simple values (e.g. CurrentTime) as well as access to the whole information at once in a transactional context (the value of the "root" node of the type contains the whole information in an ExtensionObject).
This solution has the following advatages:
- You can read the whole information at once
- If you are interested just in a single part of the information, you can read just this part
- Most generic clients that are available now cannot interprete ExtensionObjects of unknown DataTypes
The .NET SDK does not contain utility functions to keep the values constistent. It depends on the concrete use case to decide on an way of implementation.
In a first step you can use "SetVariableDefaultValuemethod" of the BaseNodeManage for each component of the type if the structure changes. Depending on the use case you can make optimizations (e.g. implementing Read, Write and Subscribe methods of the NodeManager) in a second step.
Best regards,
Unified Automation Support Team
-
- Sr. Member
- Posts: 14
- Joined: 16 Oct 2012, 16:33
Re: Structures and ExtensionObjects
Thank you, that was helpful and exactly what I did. Because I am able to create the model programmatically by extracting the model from the source I am able to generate the UA model dynamically so I can keep the entire structure at the root node, and all it's structure elements (variable nodes below the root) in sync, so I get the best of both worlds - the ability to get the entire structure, get at it's members individually. Dynamically generating the model also makes it unnecessary to manually create and maintain the model, either manually or through the UA Modeller - much more efficient and maintainable for development.
Thanks for your help.
Nathan Whelchel
Software Developer/Consultant
for KLA_Tencor
Thanks for your help.
Nathan Whelchel
Software Developer/Consultant
for KLA_Tencor