Programatically add optional property to nested variable nod

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

Moderator: uasdknet

Post Reply
MortenSchou
Full Member
Full Member
Posts: 9
Joined: 14 Feb 2018, 10:49

Programatically add optional property to nested variable nod

Post by MortenSchou »

I am creating an instance of AlarmConditionType programatically:

Code: Select all

var alarmConditionObject = CreateObject(Server.DefaultRequestContext, new CreateObjectSettings
            {
                ParentNodeId = new NodeId(...),
                ReferenceTypeId = ReferenceTypeIds.HasCondition,
                RequestedNodeId = new NodeId(...),
                BrowseName = new QualifiedName(alarmDisplayName, InstanceNamespaceIndex),
                TypeDefinitionId = ObjectTypeIds.AlarmConditionType,
                Description = alarmMessage,
            });
However, I would like to also add the optional TransitionTime property to the ActiveState variable of the created instance of AlarmConditionType.

I am aware that this can be done through the UaModeler, but how do I do this programatically?

MortenSchou
Full Member
Full Member
Posts: 9
Joined: 14 Feb 2018, 10:49

Re: Programatically add optional property to nested variable

Post by MortenSchou »

MortenSchou wrote: UPDATE:

I have managed to add the TransitionTime property to the ActiveState variable as follows:

Code: Select all

var alarmConditionObject = CreateObject(Server.DefaultRequestContext, new CreateObjectSettings
            {
                ParentNodeId = new NodeId(...),
                ReferenceTypeId = ReferenceTypeIds.HasCondition,
                RequestedNodeId = new NodeId(...),
                BrowseName = new QualifiedName(alarmDisplayName, InstanceNamespaceIndex),
                TypeDefinitionId = ObjectTypeIds.AlarmConditionType,
                Description = alarmMessage,
            });
var activeStateNode = FindInMemoryNode(alarmConditionObject.NodeId, ReferenceTypeIds.HasComponent, false, new AbsoluteName("ActiveState"));

activeStateNode.AddReference(ReferenceTypeIds.HasProperty, false, new NodeId(9165, 0), true);
I also create an AlarmConditionModel and links this model to the above object:

Code: Select all

var alarmConditionModel = new AlarmConditionModel
            {
                ...
                ActiveState = {Value = ConditionStateNames.Inactive, Id = false, TransitionTime = DateTime.Now},
                ...
            };

LinkModelToNode(alarmConditionObject.NodeId, alarmConditionModel, null, null, 1000);
However, the TransitionTime is not assigned any value when read from a client.

Am I doing it all wrong or what am I missing?

MortenSchou
Full Member
Full Member
Posts: 9
Joined: 14 Feb 2018, 10:49

Re: Programatically add optional property to nested variable

Post by MortenSchou »

Found out how to do this...

Done by specifying the children of children in OptionalBrowsePaths as follows (example adding optional TransitionTime of ActiveState of AlarmConditionType):

Code: Select all

            var alarmConditionObject = CreateObject(Server.DefaultRequestContext, new CreateObjectSettings
            {
                ParentNodeId = ...,
                ReferenceTypeId = ReferenceTypeIds.HasCondition,
                RequestedNodeId = ...,
                BrowseName = ...,
                TypeDefinitionId = ObjectTypeIds.AlarmConditionType,
                OptionalBrowsePaths = new List<string> { "LatchedState", "Reset", AbsoluteName.ToString("ActiveState","TransitionTime") }
            });
Basically, you use the AbsoluteName.ToString to construct the browse path to the optional children of children to include.

Post Reply