OPC UAFX 服务器更新多个节点值

问题描述

大家。我想从我的 OPC 服务器共享 3 个不同的值,我希望通过读取 JSON 文件来更新这些值。

这是我拥有的代码,我可以使用 OPC 客户端读取值,但是当 JSON 文件中的值更新时,客户端仍然接收原始值,而不是最新值。

>

如果你能帮我解决这个问题,我将不胜感激。 问候。

List lastReadings = JsonHandler.ReadLastReadingstemp();

        OpcDataVariableNode<string> pesoNode = new OpcDataVariableNode<string>("Peso_001",lastReadings[0].Message);
        OpcDataVariableNode<string> dateNode = new OpcDataVariableNode<string>("Hora_001",lastReadings[0].Date.ToString());
        OpcDataVariableNode<string> statusNode = new OpcDataVariableNode<string>("Status_001",lastReadings[0].Status.ToString());

        List<OpcDataVariableNode<string>> nodes = new List<OpcDataVariableNode<string>>
        {
            pesoNode,dateNode,statusNode
        };

        int port = Settings.Default.OpcPort;
        string serverAddress = Settings.Default.OpcServer;

        using (var server = new OpcServer($"opc.tcp://{serverAddress}:{port}/",nodes))
        {
            server.Start();

            while (true)
            {
                ////Update values
                lastReadings = JsonHandler.ReadLastReadingstemp();
                nodes[0] = new OpcDataVariableNode<string>("Peso_001",lastReadings[0].Message);
                nodes[1] = new OpcDataVariableNode<string>("Hora_001",lastReadings[0].Date.ToString());
                nodes[2] = new OpcDataVariableNode<string>("Status_001",lastReadings[0].Status.ToString());

                nodes[0].ApplyChanges(server.SystemContext);
                nodes[1].ApplyChanges(server.SystemContext);
                nodes[2].ApplyChanges(server.SystemContext);
                Thread.Sleep(1000);
            }
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)