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);
}
}
}
}