OPC UAFX Server updating multiple node values

Viewed 159

everyone. I want to share 3 different values from my OPC server and I want those values to be updated through reading a JSON file.

This is the code that I have, I am able to read the values with an OPC client, but when the value is updated in the JSON file, the client it's still receiving the original value, not the newest one.

If you can help me with this, I will be very grateful. Regards.

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);
            }
        }
0 Answers
Related