Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Error While Connecting to the Server

More
06 May 2024 13:00 - 06 May 2024 13:15 #12760 by Jannie@Moore
Hi there, I get this error 'An item with the same key has already been added. Key: Underflow'

on this line categoryElements = client.QueryEventCategories("", "Matrikon.OPC.GDA.1");

i have this server Matrikon.OPC.GDA.1 running and i have few Alarm Events configured.

When running the following code
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using System.Reflection.Metadata;
 
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.AlarmsAndEvents.AddressSpace;
using OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel;
using OpcLabs.EasyOpc.OperationModel;
 
namespace OPCAETest
{
    internal class Program
    {
        static void Main(string[] args)
        {
 
 
            // Instantiate the client object.
            var client = new EasyAEClient();
 
            AECategoryElementCollection categoryElements;
            try
            {
                categoryElements = client.QueryEventCategories("", "Matrikon.OPC.GDA.1");
            }
            catch (Exception Exception)
            {
                Console.WriteLine("*** Failure: {0}", Exception.InnerException.Message);
                return;
            }
            //catch (OpcException opcException)
            //{
            //    Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
            //    return;
            //}
 
            foreach (AECategoryElement categoryElement in categoryElements)
            {
                Debug.Assert(categoryElement != null);
 
                Console.WriteLine("Category {0}:", categoryElement);
                foreach (AEAttributeElement attributeElement in categoryElement.AttributeElements)
                {
                    Debug.Assert(attributeElement != null);
 
                    Console.WriteLine("    Information about attribute {0}:", attributeElement);
                    Console.WriteLine("        .AttributeId: {0}", attributeElement.AttributeId);
                    Console.WriteLine("        .Description: {0}", attributeElement.Description);
                    Console.WriteLine("        .DataType: {0}", attributeElement.DataType);
                }
            }
 
 
            var eventHandler = new EasyAENotificationEventHandler(aeClient_Notification);
            client.Notification += eventHandler;
 
            // Keep the application running
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
        // Notification event handler
        static void aeClient_Notification(object sender, EasyAENotificationEventArgs e)
        {
            if (!e.Succeeded)
            {
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
                return;
            }
            if (!e.Refresh && (!(e.EventData is null)))
            {
                // Display all received event attribute IDs and their corresponding values
                Console.WriteLine("Event attribute count: {0}", e.EventData.AttributeValues.Count);
                foreach (KeyValuePair<long, object> pair in e.EventData.AttributeValues)
                    Console.WriteLine("    {0}: {1}", pair.Key, pair.Value);
            }
        }
 
 
 
    }
}
Last edit: 06 May 2024 13:15 by support.

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.045 seconds