titanium-as / TitaniumAS.Opc.Client

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

ItemId error #47

Closed richard-palm closed 3 years ago

richard-palm commented 3 years ago

Hello,

I have just set up an application to retrieve data by OPC. Everything works perfectly well, however, when I want to retrieve data and their name contains the ":" character, my programme returns an error.

Do you know if there is a way to add variable names with the ":" character in a group?

Variable: D13:Drive.Speed.Act

Below is a simplified piece of code from my program with one of the variables I have a problem with:

using System; using TitaniumAS.Opc.Client.Da; using System.Threading;

namespace OPCDA { class Program { static void Main(string[] args) { const string AdresseServeur = "ServerAddress"; //Adresse du serveur OPC const string IpServeur = "ServerIP"; //Adresse du serveur OPC const string TypeServeurOPC = "opcda"; //Adresse du serveur OPC

        var uriBuilder = new UriBuilder
        {
            Scheme = TypeServeurOPC,
            Host = IpServeur,
            Path = AdresseServeur
        };
        var uri = uriBuilder.Uri;

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

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

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

            var itemBool = new OpcDaItemDefinition
            {
                ItemId = "D13:Drive.Speed.Act",
                IsActive = true
            };

            OpcDaItemDefinition[] opcDaItems = { itemBool };
            OpcDaItemResult[] results = group.AddItems(opcDaItems);

            foreach (OpcDaItemResult result in results)
            {
                if (result.Error.Failed)
                    Console.WriteLine("Error adding items: {0}", result.Error);
            }

            while (true)
            {
                OpcDaItemValue[] values = group.Read(group.Items, OpcDaDataSource.Device);
                Console.WriteLine("Value is {0}", Convert.ToString(values[0].Value));
                Thread.Sleep(3000);
            }
        }
    }
}

}

Thank you in advance for your help.

Best regards,