Beispiel #1
0
        /// <summary>
        /// Updates the status node.
        /// </summary>
        protected override bool UpdateStatus()
        {
            // get the status from the server.
            ComDaClient     client = DefaultClient;
            OPCSERVERSTATUS?status = client.GetStatus();

            // check the client has been abandoned.
            if (!Object.ReferenceEquals(client, DefaultClient))
            {
                return(false);
            }

            // update the server status.
            lock (StatusNodeLock)
            {
                if (status != null)
                {
                    StatusNode.SetStatusCode(DefaultSystemContext, StatusCodes.Good, DateTime.UtcNow);

                    StatusNode.ServerState.Value     = Utils.Format("{0}", status.Value.dwServerState);
                    StatusNode.CurrentTime.Value     = ComUtils.GetDateTime(status.Value.ftCurrentTime);
                    StatusNode.LastUpdateTime.Value  = ComUtils.GetDateTime(status.Value.ftLastUpdateTime);
                    StatusNode.StartTime.Value       = ComUtils.GetDateTime(status.Value.ftStartTime);
                    StatusNode.VendorInfo.Value      = status.Value.szVendorInfo;
                    StatusNode.SoftwareVersion.Value = Utils.Format("{0}.{1}.{2}", status.Value.wMajorVersion, status.Value.wMinorVersion, status.Value.wBuildNumber);
                }
                else
                {
                    StatusNode.SetStatusCode(DefaultSystemContext, StatusCodes.BadOutOfService, DateTime.UtcNow);
                }

                StatusNode.ClearChangeMasks(DefaultSystemContext, true);
                return(status != null);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Da20ElementBrowser"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="itemId">The item id.</param>
 public Da20ElementBrowser(
     ComDaClient client,
     string itemId)
 {
     m_client   = client;
     m_itemId   = itemId;
     m_branches = false;
 }
Beispiel #3
0
        /// <summary>
        /// Creates an empty group.
        /// </summary>
        /// <param name="server">The server that the group belongs to.</param>
        /// <param name="callbacksRequired">if set to <c>true</c> if the group will received callbacks.</param>
        public ComDaGroup(ComDaClient server, bool callbacksRequired)
        {
            m_server       = server;
            m_clientHandle = Utils.IncrementIdentifier(ref m_groupCounter);
            m_serverHandle = 0;
            m_items        = new List <GroupItem>();

            if (callbacksRequired)
            {
                m_monitoredItems = new Dictionary <int, DataChangeInfo>();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates an empty group.
        /// </summary>
        /// <param name="server">The server that the group belongs to.</param>
        /// <param name="callbacksRequired">if set to <c>true</c> if the group will received callbacks.</param>
        public ComDaGroup(ComDaClient server, bool callbacksRequired)
        {
            m_server = server;
            m_clientHandle = Utils.IncrementIdentifier(ref m_groupCounter);
            m_serverHandle = 0;
            m_items = new List<GroupItem>();

            if (callbacksRequired)
            {
                m_monitoredItems = new Dictionary<int, DataChangeInfo>();
            }            
        }
Beispiel #5
0
        /// <summary>
        /// Returns the next reference.
        /// </summary>
        /// <returns>The next reference that meets the browse criteria.</returns>
        public override IReference Next()
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext);

            lock (DataLock)
            {
                IReference reference = null;

                // enumerate pre-defined references.
                // always call first to ensure any pushed-back references are returned first.
                reference = base.Next();

                if (reference != null)
                {
                    return(reference);
                }

                // don't start browsing huge number of references when only internal references are requested.
                if (InternalOnly)
                {
                    return(null);
                }

                // fetch references from the server.
                do
                {
                    // fetch next reference.
                    reference = NextChild();

                    if (reference != null)
                    {
                        return(reference);
                    }

                    // go to the next stage.
                    NextStage();
                }while (m_stage != Stage.Done);

                // all done.
                return(null);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext);

            // check if a specific browse name is requested.
            if (QualifiedName.IsNull(base.BrowseName))
            {
                return(NextChild(m_stage));
            }

            // keep fetching references until a matching browse name if found.
            NodeStateReference reference = null;

            do
            {
                reference = NextChild(m_stage);

                if (reference != null)
                {
                    // need to let the caller look up the browse name.
                    if (reference.Target == null)
                    {
                        return(reference);
                    }

                    // check for browse name match.
                    if (reference.Target.BrowseName == base.BrowseName)
                    {
                        return(reference);
                    }
                }
            }while (reference != null);

            // no match - need to go onto the next stage.
            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Initializes the next stage of browsing.
        /// </summary>
        private void NextStage()
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext);

            // determine which stage is next based on the reference types requested.
            for (Stage next = m_stage + 1; next <= Stage.Done; next++)
            {
                if (next == Stage.Children)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Properties)
                {
                    if (IsRequired(ReferenceTypeIds.HasProperty, false))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Parents)
                {
                    if (IsRequired(ReferenceTypeIds.Organizes, true))
                    {
                        m_stage = next;
                        break;
                    }
                }

                else if (next == Stage.Done)
                {
                    m_stage = next;
                    break;
                }
            }

            m_position = 0;

            // start enumerating branches.
            if (m_stage == Stage.Children)
            {
                m_browser = client.CreateBrowser(m_itemId);
                return;
            }

            // start enumerating properties.
            if (m_stage == Stage.Properties)
            {
                m_properties = client.ReadAvailableProperties(m_itemId, true);
                m_position   = 0;
                return;
            }

            // start enumerating parents.
            if (m_stage == Stage.Parents)
            {
                m_parentId = client.FindElementParentId(m_itemId);
                return;
            }

            // all done.
        }
Beispiel #8
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private NodeStateReference NextChild(Stage stage)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)SystemContext);

            DaElement element = null;

            if (stage == Stage.Children)
            {
                if (m_browser == null)
                {
                    return(null);
                }

                element = m_browser.Next();

                if (element == null)
                {
                    return(null);
                }

                // construct the node.
                NodeState node = ModelUtils.ConstructElement(SystemContext, element, m_namespaceIndex);

                // return the reference.
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, node));
            }

            if (stage == Stage.Properties)
            {
                if (m_properties == null)
                {
                    return(null);
                }

                for (int ii = m_position; ii < m_properties.Length; ii++)
                {
                    if (m_properties[ii].PropertyId <= PropertyIds.TimeZone)
                    {
                        continue;
                    }

                    m_position = ii + 1;

                    // construct the node.
                    NodeState node = ModelUtils.ConstructProperty(SystemContext, m_itemId, m_properties[ii], m_namespaceIndex);

                    // return the reference.
                    return(new NodeStateReference(ReferenceTypeIds.HasProperty, false, node));
                }

                // all done.
                return(null);
            }

            if (stage == Stage.Parents)
            {
                if (m_parentId != null)
                {
                    NodeId parentId = ModelUtils.ConstructIdForDaElement(m_parentId, -1, m_namespaceIndex);
                    m_parentId = null;
                    return(new NodeStateReference(ReferenceTypeIds.Organizes, true, parentId));
                }
            }

            return(null);
        }