简体   繁体   English

如何更新 OPC UA 服务器中的节点

[英]How to update nodes in a OPC UA Server

I've a new question: How to update nodes in a OPC UA Server - C#?我有一个新问题:如何更新 OPC UA 服务器中的节点 - C#?

I've created the nodes in CreateAddressSpace of EmptyNodeManager.cs.我已经在 EmptyNodeManager.cs 的 CreateAddressSpace 中创建了节点。 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);

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.您没有显示用于更新变量的代码,也没有明确说明您使用的是哪个 C# OPC-UA 堆栈 - 我假设是 OPC Foundation 堆栈,因为它有一个 EmptyNodeManager。

In that stack updates aren't sent until you call ClearChangeMasks(), so to change a variable I use the following:在该堆栈中,直到您调用 ClearChangeMasks() 才会发送更新,因此要更改变量,我使用以下命令:

    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.请注意,除非客户端订阅了该变量的更改,否则它不会看到更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM