How to update nodes in a OPC UA Server

房东的猫 提交于 2020-01-24 21:47:08

问题


I've a new question: How to update nodes in a OPC UA Server - C#?

I've created the nodes in CreateAddressSpace of EmptyNodeManager.cs. All work fine, yet when the value changing on the real node, the client not observe the variation.

Down there's code:

PropertyState variableA = new PropertyState(i);

variableA.NodeId = new NodeId("/System_Memory/I/A", NamespaceIndex);
variableA.Description = "Sensore che individua la posizione iniziale del trapano";
variableA.TypeDefinitionId = VariableTypeIds.PropertyType;
variableA.ReferenceTypeId = ReferenceTypeIds.HasProperty;
variableA.BrowseName = new QualifiedName("A", NamespaceIndex);
variableA.DisplayName = variableA.BrowseName.Name;
variableA.DataType = (uint)BuiltInType.Boolean;
variableA.Value = plc.readFileI(0); // Chiamata al metodo per la lettura

i.AddChild(variableA);

回答1:


Sorry, I can't comment so I can't ask for clarification, so...

You don't show the code you use to update the variable and you don't explicitly say which C# OPC-UA stack you are using - I assume the OPC Foundation stack since it has an EmptyNodeManager.

In that stack updates aren't sent until you call ClearChangeMasks(), so to change a variable I use the following:

    void Update(BaseVariableState variable, object value)
    {
        if (variable == null) throw new ArgumentNullException("variable");
        if (!object.Equals(variable.Value, value))
        {
            variable.Value = value;
            variable.Timestamp = m_timestamp;
            // SystemContext is a property in EmptyNodeManager
            variable.ClearChangeMasks(SystemContext, false);
        }
    }

Note that the client won't see the update unless it has subscribed to changes for that variable.



来源:https://stackoverflow.com/questions/39618461/how-to-update-nodes-in-a-opc-ua-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!