Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Events 事件处理器_Events_Notifications_Opc Ua - Fatal编程技术网

Events 事件处理器

Events 事件处理器,events,notifications,opc-ua,Events,Notifications,Opc Ua,我正在尝试使用opc ua将服务器与客户机通信,它工作正常,直到我希望程序返回值为止。Im使用OnNotification功能: public void OnNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e) { // Debug.Log("Entre aqui"); foreach (var value in item.DequeueValues()) { // De

我正在尝试使用opc ua将服务器与客户机通信,它工作正常,直到我希望程序返回值为止。Im使用OnNotification功能:

public void OnNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e)
{
   // Debug.Log("Entre aqui");

    foreach (var value in item.DequeueValues())
    {
       // Debug.Log("Entre aqui otra vez");
        //Console.WriteLine("{0}: {1}, {2}, {3}", item.DisplayName, value.Value, value.SourceTimestamp, value.StatusCode);
        Debug.Log("{0}: {1}, {2}, {3}" + item.DisplayName + value.Value + value.SourceTimestamp + value.StatusCode);
        //rotZ = float.Parse(value.Value.ToString());
        //J1.Rotate(0, 0, rotZ);
    }
}
在这里,我创建了受监视的项,并将MonitoredItem EventHandler添加到函数中,但我不知道为什么I.Notification事件从未发生,因此它从未运行OnNotification函数。 我应该触发事件发生吗?我做错了什么

        var filter = new EventFilter();


        var triggeringItemId = new MonitoredItem(subscription.DefaultItem)
        {
            NodeClass = NodeClass.Object,
            StartNodeId = ObjectIds.Server,
            AttributeId = Attributes.EventNotifier,
            MonitoringMode = MonitoringMode.Reporting,
            SamplingInterval = -1,
            QueueSize = 100,
            CacheQueueSize = 100,
            Filter = filter 
        };
        // Log("Step 5 - Add a list of items you wish to monitor to the subscription.");
        var list = new List<MonitoredItem> {
            triggeringItemId,
            /*
            monitoredItem,
            monitoredItem2
            */
        };

        list.ForEach(i => i.Notification += OnNotification);

        Debug.Log(list);

        subscription.AddItems(list);

        // Log("Step 6 - Add the subscription to the session.");
        session.AddSubscription(subscription);
        subscription.Create();
var filter=neweventfilter();
var triggeringItemId=new MonitoredItem(subscription.DefaultItem)
{
NodeClass=NodeClass.Object,
StartNodeId=objectId.Server,
AttributeId=Attributes.EventNotifier,
MonitoringMode=MonitoringMode.Reporting,
SamplingInterval=-1,
队列大小=100,
CacheQueueSize=100,
过滤器=过滤器
};
//日志(“步骤5-向订阅中添加要监视的项目列表”);
变量列表=新列表{
triggeringItemId,
/*
monitoredItem,
monitoredItem2
*/
};
list.ForEach(i=>i.Notification+=OnNotification);
调试日志(列表);
订阅。附加项(列表);
//日志(“步骤6-将订阅添加到会话。”);
会话.添加订阅(订阅);
subscription.Create();

按此顺序,它对我有效:

session.AddSubscription(subscription);
subscription.Create();
然后我创建
MonitoredItems
,然后将它们添加到订阅和您错过的最后一步:

subscription.ApplyChanges();

尝试向EventFilter添加一些“Select”子句。以下列表对应于基本事件类型。AlarmCondition类型提供了更多字段

var filter=neweventfilter()

filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.EventId); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.EventType); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.SourceNode); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.SourceName); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.Time); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.ReceiveTime); filter.AddSelectClause(ObjectTypes.BaseEventType,Opc.Ua.BrowseNames.LocalTime); filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.Message);
filter.AddSelectClause(ObjectTypes.BaseEventType、Opc.Ua.BrowseNames.Severity)

嘿,我知道这已经有一段时间没有发布了。但是,在哪里可以使用OnNotification方法检索事件信息,并且监视的项目具有一个EventNotifier属性?