Create DataType dynamically in .NET

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
miles98
Jr. Member
Jr. Member
Posts: 1
Joined: 27 Mar 2024, 14:18

Create DataType dynamically in .NET

Post by miles98 »

Hi,
I want to create a custom DataType starting from a class in .NET.

Let's assume I have this class in my code:

Code: Select all

public class ExampleType
{
    public int Number { get; set; }
    public string Text { get; set; }
}
How can I create a Data Type in runtime to use inside the CreateVariableNode method? I don't want to use UaModeler....

Thanks.

User avatar
Support Team
Hero Member
Hero Member
Posts: 3072
Joined: 18 Mar 2011, 15:09

Re: Create DataType dynamically in .NET

Post by Support Team »

Hi,

We can distinguish between a) structured DataTypes that are known at compile time and b) structured DataTypes that are known at runtime.

a) For structured DataTypes that are knwon at compile time you can write a class in C# represting the DataType. This class shall implement the interface IEncodeable. It can get registered at the communication stack. The decoder will directly decode it in this case and you can work with the class. In addition you need to add all required Nodes, including the Encoding nodes and the DataTypeDefinition attribute. If you want to support the DataTypeDictionary you need to add the DataTypeDescription nodes, the DataTypeDictionary and set correct values for these nodes.

The comple work can be done with a few clicks when using UaModeler. So we recommend to use UaModeler for creating the DataTypes and use the generated code. Otherwise you will need to write the code by hand that UaModeler can create for you.

b) For structured DataTypes that are known at runtime, you cannot create a class of course. You can create the DataTypeNodes using the helper functions CreateTypeDictionary and CreateGenericDataType. In this case you can set values using GenericStructureValue

Alternatively you can create the structure DataType using the helper function CreateGenericStructure and set values with GenericEncodeableStructure.

https://documentation.unified-automation.com/uasdknet/4.0.0/html/classUnifiedAutomation_1_1UaServer_1_1BaseNodeManager.html#a18b3c9cf5d3766e55aed80cb35a2ad12

https://documentation.unified-automation.com/uasdknet/4.0.0/html/classUnifiedAutomation_1_1UaServer_1_1BaseNodeManager.html#af8b7e115b0978f30b3e53f9c3f4e07b0

https://documentation.unified-automation.com/uasdknet/4.0.0/html/classUnifiedAutomation_1_1UaBase_1_1GenericStructuredValue.html

https://documentation.unified-automation.com/uasdknet/4.0.0/html/classUnifiedAutomation_1_1UaServer_1_1BaseNodeManager.html#a8cb9062a19fc7318e5e2291c03056db5
https://documentation.unified-automation.com/uasdknet/4.0.0/html/classUnifiedAutomation_1_1UaBase_1_1GenericEncodeableStructure.html
Best regards
Unified Automation Support Team

Post Reply