System.NullReferenceException in HRESULT[] results = group.Write(items, values) //TitaniumAS OPCda

94 Views Asked by At

i need an opc client for work, i used TitaniumAS as it's really simple, the read works fine but the write doesnt, i have the exception in the title The tagID is correct as it works when i read it.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TitaniumAS.Opc.Client.Common;
using TitaniumAS.Opc.Client.Da;
using TitaniumAS.Opc.Client.Da.Browsing;
using System.Threading;

namespace OPCDA
{
    class Program
    {
        static void Main(string[] args)
        {

            TitaniumAS.Opc.Client.Bootstrap.Initialize();

            Uri url = UrlBuilder.Build("Kepware.KEPServerEX.V6");

            using (var server = new OpcDaServer(url))
            {
                server.Connect();

                //creating tag group
                OpcDaGroup group = server.AddGroup("MyGroup");
                group.IsActive= true;

//Write
                OpcDaItem int2 = group.Items.FirstOrDefault(i => i.ItemId == "Channel1.Device1.Woord");
      
                OpcDaItem[] items = { int2 };
                object[] values = { 15601 };
                HRESULT[] results = group.Write(items, values);

            }
        }
    }
}
1

There are 1 best solutions below

0
On
                OpcDaGroup group = server.AddGroup("MyGroup");
                group.IsActive= true;

//Write
                OpcDaItem int2 = group.Items.FirstOrDefault(i => i.ItemId == "Channel1.Device1.Woord");
// no such item, int2 is null

group is empty, you added nothing to it.