当前位置: 首页>>代码示例>>C#>>正文


C# MonitoredItem.GetFieldValue方法代码示例

本文整理汇总了C#中Opc.Ua.Client.MonitoredItem.GetFieldValue方法的典型用法代码示例。如果您正苦于以下问题:C# MonitoredItem.GetFieldValue方法的具体用法?C# MonitoredItem.GetFieldValue怎么用?C# MonitoredItem.GetFieldValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Opc.Ua.Client.MonitoredItem的用法示例。


在下文中一共展示了MonitoredItem.GetFieldValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ItemNotification

    /// <summary>
    /// Processes a Publish response from the server.
    /// </summary>
    /// 
    void ItemNotification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
    {
      if (InvokeRequired)
      {
        BeginInvoke(new MonitoredItemNotificationEventHandler(ItemNotification), monitoredItem, e);
        return;
      }
      else if (!IsHandleCreated)
      {
        return;
      }
      try
      {
        if (monitoredItem != null)
        {
          string Key = monitoredItem.StartNodeId.Identifier.ToString() + "." + monitoredItem.RelativePath;
          ListViewItem[] lvis = listView1.Items.Find(Key, true);
          Opc.Ua.MonitoredItemNotification change = e.NotificationValue as Opc.Ua.MonitoredItemNotification;
          if(change != null)
          {
            DataValue dv = change.Value;
            if (lvis.Length == 1)
            {
              ListViewItem lvi = lvis[0];
              int subindex = lvi.SubItems.IndexOfKey(Key);
              ListViewItem.ListViewSubItem si = lvi.SubItems[subindex];
              TypedMonitoredItem mi = si.Tag as TypedMonitoredItem;
              
              if (mi != null)
              {
                if (mi.ClientHandle == monitoredItem.ClientHandle)
                {
                  if (dv != null && dv.Value != null)
                  {
                    if (monitoredItem.Status.Id == StatusCodes.BadNodeIdUnknown)
                    {
                      // Randy said we would get this, but we don't
                      RemoveSessionItem(lvi, true);
                    }
                    else
                    {
                     si.Text = mi.ToString(dv);
                    }
                  }
                  else
                  {
                    // This is what we get
                    RemoveSessionItem(lvi, true);
                  }
                }
                else
                {
                  Utils.Trace("(mi.ClientHandle != monitoredItem.ClientHandle " + MethodBase.GetCurrentMethod());
                }
              }
              else
              {
                Utils.Trace("mi is null " + MethodBase.GetCurrentMethod());
              }
            }
            else
            {
              Utils.Trace("lvis.Length != 1 " + MethodBase.GetCurrentMethod());
            }
          }
          else
          {
            EventFieldList eventFields = e.NotificationValue as EventFieldList;
            if (eventFields != null)
            {

              // get the event fields.
              NodeId eventType      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.EventType) as NodeId;
              string sourceName     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceName) as string;
              DateTime? time        = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Time) as DateTime?;
              ushort? severity      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Severity) as ushort?;
              LocalizedText message = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Message) as LocalizedText;
              NodeId sourceNode     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceNode) as NodeId;
              //Utils.Trace("eventType: {0}, message: {1}, sourceName: {2} sourceNode: {3}", eventType.ToString(), message.Text.ToString(), sourceName.ToString(), sourceNode.ToString());
              if (eventType == new NodeId(ObjectTypes.AuditActivateSessionEventType))
              {
                Utils.Trace("AuditActivateSessionEventType detected " + MethodBase.GetCurrentMethod());
                AddSessions();
                m_Subscription.ModifyItems();
                m_Subscription.ApplyChanges();
              }
            }
            else
            {
              Utils.Trace("eventFields is null " + MethodBase.GetCurrentMethod());
            }
          }
        }
        else
        {
          Utils.Trace("monitoredItem is null " + MethodBase.GetCurrentMethod());
//.........这里部分代码省略.........
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:101,代码来源:SessionCtrl.cs

示例2: AddressSpaceChange_Notification

        /// <summary>
        /// Processes a Publish response from the UA server for AddressSpace changes.
        /// </summary>
        /// <param name="monitoredItem"></param>
        /// <param name="e"></param>
        void AddressSpaceChange_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                EventFieldList eventFields = e.NotificationValue as EventFieldList;

                if (eventFields == null)
                {
                    return;
                }
                if (monitoredItem != null)
                {
                    if (monitoredItem.ClientHandle != eventFields.ClientHandle)
                    {
                        return;
                    }
                }
                INode eventUA = monitoredItem.GetEventType(eventFields);
                if (eventUA.NodeId == new NodeId(Opc.Ua.ObjectTypes.BaseModelChangeEventType))
                {
                    //TODO:if we get this event we know a change was made, but we do not know what so we will beed to get all EventTypes and compare and update our config data
                }
                else if (eventUA.NodeId != new NodeId(Opc.Ua.ObjectTypes.GeneralModelChangeEventType))
                {
                    //We are not interested in any other event, so we will return.
                    //If we can set the where clause on the filter for this item, this else clause can be removed.
                    return;
                }
                else
                {
                    object v = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.GeneralModelChangeEventType, new QualifiedName(Opc.Ua.BrowseNames.Changes));

                    //ChangeStructureDataTypeCollection changes = (ChangeStructureDataTypeCollection) monitoredItem.GetFieldValue(eventFields, ObjectTypes.GeneralModelChangeEventType, new QualifiedName(GeneralModelChangeEvent.Names.Changes));



                }

            }
            catch (Exception ex)
            {
                Utils.Trace(ex, "Unexpected error in AddressSpaceChange_Notification");
            }
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:49,代码来源:ComAeProxy.cs

示例3: MonitoredItem_Notification

        /// <summary>
        /// Processes a Publish response from the UA server.
        /// </summary>
        /// <param name="monitoredItem"></param>
        /// <param name="e"></param>
        void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                EventFieldList eventFields = e.NotificationValue as EventFieldList;

                if (eventFields == null)
                {
                    return;
                }
                if (monitoredItem != null)
                {
                    if (monitoredItem.ClientHandle != eventFields.ClientHandle)
                    {
                        return;
                    }
                }
                INode eventUA = monitoredItem.GetEventType(eventFields);
                EventCategory cat = FindEventCatInfo(eventUA.BrowseName.ToString());

                if (cat == null) return; // The event is not of a category that we recognize.
           
                if (cat.EventType == OpcRcw.Ae.Constants.CONDITION_EVENT)
                {
                    NodeId branchId = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.ConditionType, Opc.Ua.BrowseNames.BranchId) as NodeId;
                    if (!NodeId.IsNull(branchId)) return; // We don't support condition branches in the COM Proxy
                }

                EventNotification ev = new EventNotification();

                ev.EventId = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.EventId)) as byte[];
                ev.SourceID = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.SourceName)));
                ev.Time = System.Convert.ToDateTime(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Time)));
                ev.Message = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Message)));
                ev.EventType = cat.EventType;
                ev.EventCategory = cat.CategoryID;
                ev.Severity = System.Convert.ToInt32(monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, new QualifiedName(Opc.Ua.BrowseNames.Severity)));

                List<EventAttribute> Attrs = GetEventAttributes(cat.CategoryID);
                UniqueList<string> strEventNodeIds = new UniqueList<string>();
                foreach (EventAttribute attr in Attrs)
                    if (attr.strEventNodeId != "")
                        strEventNodeIds.AddUnique(attr.strEventNodeId);

                ev.EventAttributes = new Dictionary<int, object>();
                foreach (EventAttribute attr in m_configFile.Attributes)
                {
                    foreach (string strEventNodeId in strEventNodeIds)
                    {
                        if (attr.strEventNodeId == strEventNodeId)
                        {
                            object value = monitoredItem.GetFieldValue(eventFields, (NodeId)attr.strEventNodeId, new QualifiedName(attr.BrowseName, attr.BrowseNameNSIndex));
                            if (value == null)
                            {
                                ev.EventAttributes.Add(attr.AttributeID, "");
                            }
                            else if ((value.GetType() != null) & (short)ComUtils.GetVarType(value) != 0)
                            {
                                ev.EventAttributes.Add(attr.AttributeID, value);
                            }
                            else
                            {
                                // any value with a UA type that does not have a corresponding COM type will be returned as a string 
                                ev.EventAttributes.Add(attr.AttributeID, value.ToString());
                            }
                        }
                    }
                }

                //Condition-Related Event properties
                ev.ConditionName = "";
                ev.SubConditionName = "";
                ev.ChangeMask = 0;
                ev.NewState = OpcRcw.Ae.Constants.CONDITION_ENABLED | OpcRcw.Ae.Constants.CONDITION_ACKED;
                ev.Quality = OpcRcw.Da.Qualities.OPC_QUALITY_GOOD;
                ev.AckRequired = false;
                ev.ActiveTime = DateTime.Now;
                ev.Cookie = 0;

                if (ev.EventType == OpcRcw.Ae.Constants.CONDITION_EVENT)
                    SetConditionEventFields(monitoredItem, eventFields, ev, cat);

                //Tracking Events and for Condition-Related Events which are acknowledgment notifications
                if (cat.EventType == OpcRcw.Ae.Constants.TRACKING_EVENT)
                    ev.ActorID = System.Convert.ToString(monitoredItem.GetFieldValue(eventFields, (NodeId)eventUA.NodeId, new QualifiedName(Opc.Ua.BrowseNames.ClientUserId)));

                IncomingEventHandler eventHandler = new IncomingEventHandler();
                
                //extract the area associated with this event.
                AreaNode areaNode;
                string[] areas = null;
                if (m_notifiers.TryGetValue(monitoredItem.ClientHandle, out areaNode))
                {
                    areas = new string[] { areaNode.AreaName };
                }
//.........这里部分代码省略.........
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:101,代码来源:ComAeProxy.cs

示例4: SetConditionEventFields

        /// <summary>
        /// Additional new event processing when the received event maps to a (COM AE) condition event type.  We need to extract
        /// the condition name, subcondition name, changeMask, newState, Quality, AckRequired, ActiveTime and cookie.
        /// </summary>
        /// <param name="monitoredItem"></param>
        /// <param name="eventFields"></param>
        /// <param name="ev"></param>
        /// <param name="cat"></param>
        void SetConditionEventFields(MonitoredItem monitoredItem, EventFieldList eventFields, EventNotification ev, EventCategory cat)
        {
            LocalizedText localText;
            String ConditionName;
            StatusCode? Status;
            DateTime? TimeOfLastTransition;

            try
            {
                NodeId eventType = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.EventType) as NodeId;

                // UA events are categorized into three subsets.  The first of these subsets consists of types and subtypes of ConditionType
                // which yields the event condition name, quality and enable/disable status.
                if (m_session.TypeTree.IsTypeOf(eventType, Opc.Ua.ObjectTypes.ConditionType))
                {
                    ConditionName = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.ConditionType, Opc.Ua.BrowseNames.ConditionName) as String;
                    if (ConditionName != null)
                        ev.ConditionName = ConditionName;
                    else
                        ev.ConditionName = cat.BrowseName;

                    // Set the subcondition name as conditionname for now.  If the event of of type AlarmconditionType and a subcondition (UA substate)
                    // exists then this field will be set accordingly.
                    ev.SubConditionName = ev.ConditionName;

                    bool? enabled = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.ConditionType,
                        "/EnabledState/Id", Attributes.Value) as bool?;

                    Status = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.ConditionType,
                        "/Quality", Attributes.Value) as StatusCode?;

                    ev.Quality = MapStatusToQuality(Status);

                    if (enabled == true)
                        ev.NewState |= OpcRcw.Ae.Constants.CONDITION_ENABLED;
                    else
                        ev.NewState &= ~OpcRcw.Ae.Constants.CONDITION_ENABLED;
                }

                // The second of the three UA event subsets consists of types and subtypes of AcknowledgeableconditionType.
                // This categorization yields events which support acknowledgement in addition to enable/disable state
                if (m_session.TypeTree.IsTypeOf(eventType, Opc.Ua.ObjectTypes.AcknowledgeableConditionType))
                {
                    bool? acked = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.AcknowledgeableConditionType,
                        "/AckedState/Id", Attributes.Value) as bool?;

                    // Extract the "ConditionId" (nodeId of the condition instance)
                    ev.ConditionId = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.AcknowledgeableConditionType,
                        "", Attributes.NodeId) as NodeId;

                    ev.AcknowledgeMethod = Opc.Ua.Methods.AcknowledgeableConditionType_Acknowledge;
                    
                    if (acked == true)
                    {
                        ev.NewState |= OpcRcw.Ae.Constants.CONDITION_ACKED;
                        ev.AckRequired = false;
                    }
                    else
                    {
                        ev.NewState &= ~OpcRcw.Ae.Constants.CONDITION_ACKED;
                        ev.AckRequired = true;
                    }

                }

                // the third of the three UA event subsets consists of types and subtypes of AlarmConditionType.  This
                // categorization yields events which support the notion of Active/Inactive and also may support substates
                // (subconditions).
                if (m_session.TypeTree.IsTypeOf(eventType, Opc.Ua.ObjectTypes.AlarmConditionType))
                {
                    bool? active = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.AlarmConditionType,
                        "/ActiveState/Id", Attributes.Value) as bool?;

                    TimeOfLastTransition = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.AlarmConditionType,
                        "/ActiveState/TransitionTime", Attributes.Value) as DateTime?;

                    if (active == true)
                    {
                        ev.NewState |= OpcRcw.Ae.Constants.CONDITION_ACTIVE;
                        ev.ActiveTime = TimeOfLastTransition ?? DateTime.MinValue;
                    }

                    // Active subconditon. 
                    localText = monitoredItem.GetFieldValue(eventFields, Opc.Ua.ObjectTypes.AlarmConditionType,
                        "/ActiveState/EffectiveDisplayName", Attributes.Value) as LocalizedText;
                    if (localText != null && localText.ToString() != "")
                        ev.SubConditionName = localText.ToString();
                }
                else // If this is not an AlarmConditionType (thus no UA active/inactive states apply) default to Active
                    ev.NewState |= OpcRcw.Ae.Constants.CONDITION_ACTIVE;
            }
            catch (Exception e)
//.........这里部分代码省略.........
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:101,代码来源:ComAeProxy.cs

示例5: ItemNotificationHandler

    /// <summary>
    /// 
    /// </summary>
    /// <param name="monitoredItem"></param>
    /// <param name="e"></param>
    protected virtual void ItemNotificationHandler(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
    {
      try
      {
        if (monitoredItem != null)
        {
          Opc.Ua.MonitoredItemNotification change = e.NotificationValue as Opc.Ua.MonitoredItemNotification;
          if (change != null)
          {
            DataValue dv = change.Value;
            if (dv != null)
            {
              ListViewItem[] lvis = ItemsLV.Items.Find(monitoredItem.ClientHandle.ToString(), false);
              if (lvis.Length > 0)
              {
                DiagnosticListViewItem dlvi = lvis[0].Tag as DiagnosticListViewItem;
                dlvi.UpdateInListView(lvis[0], dv, m_Session);
              }
            }
            else
            {
              Utils.Trace("dv is null: {0}", MethodBase.GetCurrentMethod());
            }
          }
          else
          {
            EventFieldList eventFields = e.NotificationValue as EventFieldList;
            if (eventFields != null)
            {

              // get the event fields.
              NodeId eventType      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.EventType) as NodeId;
              string sourceName     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceName) as string;
              DateTime? time        = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Time) as DateTime?;
              ushort? severity      = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Severity) as ushort?;
              LocalizedText message = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.Message) as LocalizedText;
              NodeId sourceNode     = monitoredItem.GetFieldValue(eventFields, ObjectTypes.BaseEventType, BrowseNames.SourceNode) as NodeId;

              if (eventType == new NodeId(ObjectTypes.AuditAddNodesEventType))
              {
              }
              else
              {
              }
            }
            else
            {
              Utils.Trace("eventFields is null " + MethodBase.GetCurrentMethod());
            }
          }
        }
      }
      catch (Exception exception)
      {
        GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
      }
    }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:62,代码来源:DiagnosticCtrl.cs


注:本文中的Opc.Ua.Client.MonitoredItem.GetFieldValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。