titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
193 stars 94 forks source link

System.NullReferenceException in HRESULT[] results = group.Write(items, values); #71

Closed MarioLedge closed 1 year ago

MarioLedge commented 1 year ago

the read works just fine but the sync write does not, i have this exception, the itemID is correct as it works with the read. pretty new to C# and kinda stuck for a week bcz of it, any help ?

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;

            OpcDaItem int2 = group.Items.FirstOrDefault(i => i.ItemId == "Channel1.Device1.Woord");

            OpcDaItem[] items = { int2 };
            object[] values = { 15601 };
            HRESULT[] results = group.Write(items, values);

        }
    }
}

}

MarioLedge commented 1 year ago

the tags must be declared as in the exemple (lines before Read) so u can write them