Opc数据更改事件未触发C#

时间:2017-02-28 10:16:59

标签: c# events memory opc

我正在创建一个需要与PLC通信的C#应用​​程序。我正在使用带有OPCAutomation.dll的Kepserver。

代码:

public void Create()
{
    OPCAutomation.OPCGroup oGroup1 = this._oServer.OPCGroups.Add("Group1");

    oGroup1.DeadBand = 0;
    oGroup1.UpdateRate = 100;
    oGroup1.IsSubscribed = true;
    oGroup1.IsActive = true;

    oGroup1.OPCItems.AddItem("Channel1.Plc1.Group1.Tag1", 1);
    oGroup1.OPCItems.AddItem("Channel1.Plc1.Group1.Tag2", 2);
    ...

    oGroup1.DataChange += new OPCAutomation.DIOPCGroupEvent_DataChangeEventHandler(Notify);
}

public void Notify(int TransactionID, int ModifiedTagsCount, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
{
    Console.WriteLine("Notification!");
}

我的问题是,如果我的应用程序中只有这个代码块,那么一切都运行良好但是只要我添加一些其他代码(没有与OPC的链接),比如创建其他类等...,我不会再收到通知,我不知道为什么......

为了验证它,我在初始化OPC部分之后就这样做了:

List<RandomClass> test = new List<RandomClass>();

for (int i = 0; i < 9999; i++)
{
    Console.WriteLine(i);
    test.Add(new RandomClass());
    Task.Delay(10).Wait();
}

我在开始时收到了通知,但是在达到特定数量的i后(平均每个应用程序启动时平均为1XXX且几乎相同的数字),不再收到通知,我不知道原因。

感谢您的帮助

0 个答案:

没有答案