[Server] How to create an object with default values in some variables

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

Moderator: uasdknet

Post Reply
jramirez-jh
Sr. Member
Sr. Member
Posts: 16
Joined: 14 Jun 2021, 23:39

[Server] How to create an object with default values in some variables

Post by jramirez-jh »

I'm working on a server that creates instances of objects dynamically like this:

Code: Select all

var objectTypeNodeId = new ExpandedNodeId(nId, DefaultNamespaceIndex).ToNodeId(Server.NamespaceUris);

var jhObjectId = new NodeId(jhBuilderModel.ObjectName, DefaultNamespaceIndex);

var settings = new CreateObjectSettings
{
	ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
	ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
	RequestedNodeId = jhObjectId,
	BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
	DisplayName = "a name",
	TypeDefinitionId = objectTypeNodeId
};

CreateObject(Server.DefaultRequestContext, settings);
Each object have N variables, I know the string identifier names of those objects (I'm receiving them also dynamically), my issue is that I need those objects to have default values in some of those variables but I can not find an easy way of doing it.

I've tried using the Write method of the new created object like this:

Code: Select all

var objectNode = CreateObject(Server.DefaultRequestContext, settings);
objectNode.Write(6525, "test value"); //NO LUCK, can't see any default values set
I'm also trying with the NodeData property of the CreateObjectSettings object but as its an object type I've no idea what are the accepted data structures? (there is no documentation about it). I've tried like this without any luck:

Code: Select all

var settings = new CreateObjectSettings
{
	ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
	ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
	RequestedNodeId = jhObjectId,
	BrowseName = new QualifiedName("a name", DefaultNamespaceIndex),
	DisplayName = "a name",
	TypeDefinitionId = objectTypeNodeId,
	NodeData = new Dictionary<string, string>
	{
		{"myobject.status_description", "god help me"}, //using the full identifier objectname.variablename
		{"status_description", "god help me"}, //using only the variable name
	}
};

var objectNode = CreateObject(Server.DefaultRequestContext, settings);
What is the right way of doing this?

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

Re: [Server] How to create an object with default values in some variables

Post by Support Team »

Hello,

You can use the Methode BaseNodeManager.SetVariableDefaultValue for your use case.

Please note: The BrowseName of the child must be correct, especially the NamespaceIndex of the BrowseName.

https://documentation.unified-automation.com/uasdknet/3.1.1/html/classUnifiedAutomation_1_1UaServer_1_1BaseNodeManager.html#af73589a0d9f0f896559aa5ab6b6a2bf1
Best regards
Unified Automation Support Team

Post Reply