LinkModelToNode

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

Moderator: uasdknet

Post Reply
k47s
Full Member
Full Member
Posts: 5
Joined: 12 Feb 2016, 07:48

LinkModelToNode

Post by k47s »

Hello,

I'm programatically creating a double variable under a BaseObject (NodeId 5003) with this code.
It works and I can see it in the UAExpert.

Code: Select all

AddNodeSettings addNodesItem = new AddNodeSettings()
                {

                    ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
                    RequestedNodeId = new NodeId("TestVar", DefaultNamespaceIndex),

                    BrowseName = new QualifiedName("TestVar", DefaultNamespaceIndex),
                    ParentNodeId = new NodeId(5003, 2),
                    Attributes = new VariableAttributes()
                    {
                        DisplayName = "TestVar",
                        DataType = UnifiedAutomation.UaBase.DataTypeIds.Double,
                        AccessLevel = (AccessLevels.CurrentReadOrWrite | AccessLevels.HistoryReadOrWrite),
                        UserAccessLevel = (AccessLevels.CurrentReadOrWrite | AccessLevels.HistoryReadOrWrite),
                        ValueRank = ValueRanks.OneDimension,
                        Historizing = true,
                        Value = variableValue,
                        SpecifiedAttributes = (uint)NodeAttributesMask.Value | (uint)NodeAttributesMask.DataType | (uint)NodeAttributesMask.ValueRank | (uint)NodeAttributesMask.Historizing | (uint)NodeAttributesMask.AccessLevel
                    }
                };
                StatusCode error = AddNode(Server.DefaultRequestContext, addNodesItem, out requestedNodeId);

If I want to use LinkModelToNode() how does my model need to look like?


Greetings,
Michael

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

Re: LinkModelToNode

Post by Support Team »

Hello,

There are example in DemoServer application. Please see file ModelClasses.cs.

In your case there is only one variable that you want to update using LinkModelToNode. This variable has the TypeDefinition BaseDataVariableType (from standard OPC Foundation namespace). So you can use the built in class BaseDataVariableModel.

Code: Select all

                BaseDataVariableModel<double> model = new BaseDataVariableModel<double>();
                LinkModelToNode(requestedNodeId, model, null, null, 500);
Best regards
Support Team

k47s
Full Member
Full Member
Posts: 5
Joined: 12 Feb 2016, 07:48

Re: LinkModelToNode

Post by k47s »

Thank you that worked perfectly.

I have another question:

I've created a DataType. Let's call it MachineModel:
MachineModel : baseObjectType
-> Variable NumberValues : Array<KeyValuePair>
-> Variable Picture : ImagePNG
-> Variable StringValues : Array<KeyValuePair>

NumberValues and StringValues are Arrays from Type KeyValuePair. KeyValuePair consists of 2 Strings Key and Value.
I have generated the Classes with UAModeler.

In the Server I created a model field:

Code: Select all

private MachineModel _machineObject = new MachineModel();
And created an instance of the Machine and linked it with the model:

Code: Select all

CreateObjectSettings machineObject = new CreateObjectSettings()
            {
                BrowseName = new QualifiedName("MachineObject", DefaultNamespaceIndex),
                EventNotifier = EventNotifiers.SubscribeToEvents,
                NotifierParent = UnifiedAutomation.UaBase.ObjectIds.Server,
                ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
                ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
                RequestedNodeId = new NodeId("MachineObject", DefaultNamespaceIndex),
                TypeDefinitionId = new NodeId(ObjectTypes.MachineModel, DefaultNamespaceIndex),
            };
            ObjectNode objectNode = CreateObject(Server.DefaultRequestContext, machineObject);
            
            KeyValuePair[] kvpArray = new KeyValuePair[1];
            kvpArray[0] = new KeyValuePair() { Key = "Temperature", Value = "0" };

            _machineObject.StringValues = kvpArray;

            LinkModelToNode(objectNode.NodeId, _machineObject, null, null, 500);
So far no Problem. I can access the Object with UAExpert and can view the KeyValuePair Array.

Then I dragged the StringValues Attribute to the Data Access View in the UA Expert and set the the Value of the Temperature-KeyValuePair to a random Value every ten seconds.
But the Values in the UA Expert aren't updated. Do I have to modify the MachineModel so it can notify the Server that changes were done?

For better understanding Types and Classes Files:
ModelingTypes.txt
ModelingClasses.txt

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

Re: LinkModelToNode

Post by Support Team »

Hello Michael,

You have to assign a new values of KeyValuePairs.

Code: Select all

_machineModel.StringValues[0].Key = "NewKey";
will not update the value.

Code: Select all

_machineModel.StringValues[0] = new KeyValuePair()
{
    Key = "NewKey"
}
will update the value.

We do not create deep copy for the properties with structured DataType because of performance reasons. There are many use cases where there are created new values in the NodeManager anyway. In these use cases the SDK would create copies although the copies are not needed.

Best regards
Support Team

dietmar123
Jr. Member
Jr. Member
Posts: 1
Joined: 09 Jan 2019, 14:09

Re: LinkModelToNode

Post by dietmar123 »

I just started working on a server project based on the standard project build by UaModeler with some model classes included based on custom object types. All works well, but when I try to use
a model class by calling LinkModelToNode, the actual model class will not be used. The binding does not seem to work even in such a trivial case, although the call to LinkModelToNode was successfully returning a plausible result.

See following code snippet from the generated node manager:

public override void Startup()
{
DefaultNamespaceIndex = AddNamespaceUri("http://desma.de/DESMA-OPCUA-Standard/");
ImportUaNodeset(Assembly.GetEntryAssembly(), "desma-standard-v2.xml");

var mdaFolderType = new RGE_MDA_FolderModel();
var mdaId = ObjectIds.Machinery_Machine_RGE_RGE01_MDA;
var nodeId = new NodeId(mdaId.IdType, mdaId.Identifier, DefaultNamespaceIndex);

var result = LinkModelToNode(nodeId, mdaFolderType, null, null, 500);
}

Do I miss some special setup needed? Up to this point I only used modeler generated model classes, only adding the linking code seen above.

Best regards
Dietmar Dreyer

Post Reply