titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
197 stars 93 forks source link

Null Reference Exception #29

Open jjack230 opened 6 years ago

jjack230 commented 6 years ago

So I've compiled the script and I'm using it in Unity3D. It gives this error for a null reference exception. image

I've already gone through the troubleshooting guide and checked all the compiling outputs. Here is my code:

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

public class Test : MonoBehaviour {

// Use this for initialization
void Start()
{
    Uri url = UrlBuilder.Build("Matrikon.OPC.Simulation.1");
    using (var server = new OpcDaServer(url))
    {
        // Connect to the server first.
        server.Connect();

        // Create a group with items.
        CreateGroupWithItems(server);

        server.Groups.Should().HaveCount(1);
        server.Groups[0].Name.Should().Be("MyGroup");
        server.Groups[0].Items.Should().HaveCount(2);
        server.Groups[0].Items[0].ItemId.Should().Be("Bucket Brigade.Int4");
        server.Groups[0].Items[1].ItemId.Should().Be("Random.Int2");
    }
}

private static OpcDaGroup CreateGroupWithItems(OpcDaServer server)
{
    // Create a group with items.
    OpcDaGroup group = server.AddGroup("MyGroup");
    group.IsActive = true;

    var definition1 = new OpcDaItemDefinition
    {
        ItemId = "Bucket Brigade.Int4",
        IsActive = true
    };
    var definition2 = new OpcDaItemDefinition
    {
        ItemId = "Random.Int2",
        IsActive = true
    };
    OpcDaItemDefinition[] definitions = { definition1, definition2 };
    OpcDaItemResult[] results = group.AddItems(definitions);

    // Handle adding results.
    foreach (OpcDaItemResult result in results)
    {
        if (result.Error.Failed)
            Debug.Log("Error adding items: {0}");
    }

    return group;
}
// Update is called once per frame
void Update () {

}

}

Where have I gone wrong?

skyxh commented 3 years ago

the same as you