BindModel update item in list

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

Moderator: uasdknet

Post Reply
SirTobi
Full Member
Full Member
Posts: 7
Joined: 20 Dec 2023, 14:05

BindModel update item in list

Post by SirTobi »

Hello,

I'm creating a dynamic list of variables and I followed the tutorial "Machine Demo Server - Collections and dynamic object creation". I managed to add and remove the variables. As far as I understood the 'NotifyCollectionChangedEventArgs' communicates with the SDK and adds and removes the OPC-UA nodes.
Currently I'm struggeling to modify an existing variable. If I change it via UaExpert than the value is not changed. If I change the object in the model it does not have any effect on the OPC-UA node.
When I'm using the NotifyCollectionChangedAction.Replace it says only Add, Remove and Reset are supported.


Can anyone help me?

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

Re: BindModel update item in list

Post by Support Team »

Hello,

the question is what you want to change of the variable. Let's say you are adding an AnalogItem (AnalogItemModel<double>).
Later you want to change its value to 10.0. Therefore you only change the value of the existing AnalogItem by assigning 10.0 to its Value property. Same is true for OPC UA properties like the EngineeringUnits, you simply assign a new value to them.

There are, however, cases where this is not enough. Usually whenever you need to either change some fundamentals of the object/variable node (or a child node), like the NodeId or TypeDefinition, or you need to add/remove some child nodes,because an optional item is now present for example. Than the only way is to remove the instance from the collection and add a replacement subsequently.

If you want, for example, exchange the AnalogItem by a more specific AnalogUnitRange (AnalogUnitRangeModel<double>), you have to obviously remove the item, create a new AnalogUnitRangeModel instance and add this to the collection.
Best regards
Unified Automation Support Team

SirTobi
Full Member
Full Member
Posts: 7
Joined: 20 Dec 2023, 14:05

Re: BindModel update item in list

Post by SirTobi »

Hello,

thank you for your answer. The hint with the Variable property helped me and I managed to change the variable value.

I have another question and maybe you could point me in the right direction:

Here is a screenshot from the UaExpert with the dynamic list of variables of the ArborType:
Image

I'm creating the instance settings like this:

Code: Select all

CreateVariableSettings varSettings = new CreateVariableSettings
{
    ParentAsOwner = true,
    ParentNodeId = ObjectIds.Machine_Arbors.ToNodeId(Server.NamespaceUris),
    DataType = DataTypeIds.ArborType.ToNodeId(Server.NamespaceUris),
    TypeDefinitionId = UnifiedAutomation.UaBase.VariableTypeIds.BaseDataVariableType,
    BrowseName = arbor.Id,
    DisplayName = $"{arbor.Name} ({arbor.Id})",
    RequestedNodeId = ArborNodeId(arbor.Id),
    ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.HasComponent,
};
The BindModel creates a OPC-UA Node DSF (ID) and also child variables as seen in the screenshot. If I use the same VariableSettings and manually add a node then I only get a single node DSF (ID) without any child nodes.
Through the UaExpert I can change the value of the DSF node but not the value of the child nodes. This is were my problem originally came from.

I just need the single variable without the child nodes. Can you tell me what I need to change for the BindModel to just create a single OPC-UA node without any child nodes?

SirTobi
Full Member
Full Member
Posts: 7
Joined: 20 Dec 2023, 14:05

Re: BindModel update item in list

Post by SirTobi »

I figured out what was my problem.

I extended the generated FolderModel with "IEnumerable<ArborVariableModel>" and as the ArborVariableModel has all the properties the BindModel automatically created the subnodes for the variable. In the UaModeler I unchecked "Add VariableType" in the DataType Definition and created the model class by hand without the properties and now it behaves the way I want it.

Thank you for your support and the BindModel is a great concept. Maybe you should update your Webinars and present the BindModel way it as well.

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

Re: BindModel update item in list

Post by Support Team »

Hi,

thank you for the feedback. Yes the BindModel is the way to go and save lots of implementation time, doing dynamic object creation in the ".NET-way" of handling such objects. We are already working on improving the documentation and also updating the webinar and our workshop materials.
Best regards
Unified Automation Support Team

Post Reply