Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlockState"/> class.
        /// </summary>
        /// <param name="nodeManager">The context.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="block">The block.</param>
        public BlockState(
            HistoricalAccessServerNodeManager nodeManager,
            NodeId nodeId,
            UnderlyingSystemBlock block) : base(null)
        {
            m_blockId     = block.Id;
            m_nodeManager = nodeManager;

            this.SymbolicName  = block.Name;
            this.NodeId        = nodeId;
            this.BrowseName    = new QualifiedName(block.Name, nodeId.NamespaceIndex);
            this.DisplayName   = new LocalizedText(block.Name);
            this.Description   = null;
            this.WriteMask     = 0;
            this.UserWriteMask = 0;
            this.EventNotifier = EventNotifiers.None;

            UnderlyingSystem system = nodeManager.SystemContext.SystemHandle as UnderlyingSystem;

            if (system != null)
            {
                IList <UnderlyingSystemTag> tags = block.GetTags();

                for (int ii = 0; ii < tags.Count; ii++)
                {
                    BaseVariableState variable = CreateVariable(nodeManager.SystemContext, tags[ii]);
                    AddChild(variable);
                    variable.OnSimpleWriteValue = OnWriteTagValue;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Used to receive notifications when the value attribute is read or written.
        /// </summary>
        public ServiceResult OnWriteTagValue(
            ISystemContext context,
            NodeState node,
            ref object value)
        {
            UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

            if (system == null)
            {
                return(StatusCodes.BadCommunicationError);
            }

            UnderlyingSystemBlock block = system.FindBlock(m_blockId);

            if (block == null)
            {
                return(StatusCodes.BadNodeIdUnknown);
            }

            uint error = block.WriteTagValue(node.SymbolicName, value);

            if (error != 0)
            {
                // the simulator uses UA status codes so there is no need for a mapping table.
                return(error);
            }

            return(ServiceResult.Good);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlockState"/> class.
        /// </summary>
        /// <param name="nodeManager">The context.</param>
        /// <param name="nodeId">The node id.</param>
        /// <param name="block">The block.</param>
        public BlockState(
            HistoricalAccessServerNodeManager nodeManager, 
            NodeId nodeId, 
            UnderlyingSystemBlock block) : base(null)
        {
            m_blockId = block.Id;
            m_nodeManager = nodeManager;

            this.SymbolicName = block.Name;
            this.NodeId = nodeId;
            this.BrowseName = new QualifiedName(block.Name, nodeId.NamespaceIndex);
            this.DisplayName = new LocalizedText(block.Name);
            this.Description = null;
            this.WriteMask = 0;
            this.UserWriteMask = 0;
            this.EventNotifier = EventNotifiers.None;

            UnderlyingSystem system = nodeManager.SystemContext.SystemHandle as UnderlyingSystem;

            if (system != null)
            {
                IList<UnderlyingSystemTag> tags = block.GetTags();

                for (int ii = 0; ii < tags.Count; ii++)
                {
                    BaseVariableState variable = CreateVariable(nodeManager.SystemContext, tags[ii]);
                    AddChild(variable);
                    variable.OnSimpleWriteValue = OnWriteTagValue;
                }
            }
        }
Example #4
0
        /// <summary>
        /// Starts the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public void StartMonitoring(ServerSystemContext context)
        {
            if (m_monitoringCount == 0)
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system != null)
                {
                    UnderlyingSystemBlock block = system.FindBlock(m_blockId);

                    if (block != null)
                    {
                        block.StartMonitoring(OnTagsChanged);
                    }
                }
            }

            m_monitoringCount++;
        }
Example #5
0
        /// <summary>
        /// Stop the monitoring the block.
        /// </summary>
        /// <param name="context">The context.</param>
        public bool StopMonitoring(ServerSystemContext context)
        {
            m_monitoringCount--;

            if (m_monitoringCount == 0)
            {
                UnderlyingSystem system = context.SystemHandle as UnderlyingSystem;

                if (system != null)
                {
                    UnderlyingSystemBlock block = system.FindBlock(m_blockId);

                    if (block != null)
                    {
                        block.StopMonitoring();
                    }
                }
            }

            return(m_monitoringCount != 0);
        }
Example #6
0
        /// <summary>
        /// Returns the next child.
        /// </summary>
        private IReference NextChild()
        {
            UnderlyingSystem system = (UnderlyingSystem)this.SystemContext.SystemHandle;

            NodeId targetId = null;

            // check if a specific browse name is requested.
            if (!QualifiedName.IsNull(base.BrowseName))
            {
                // check if match found previously.
                if (m_position == Int32.MaxValue)
                {
                    return(null);
                }

                // browse name must be qualified by the correct namespace.
                if (m_source.BrowseName.NamespaceIndex != base.BrowseName.NamespaceIndex)
                {
                    return(null);
                }

                // look for matching segment.
                if (m_stage == Stage.Segments && m_segments != null)
                {
                    for (int ii = 0; ii < m_segments.Count; ii++)
                    {
                        if (base.BrowseName.Name == m_segments[ii].Name)
                        {
                            targetId = ModelUtils.ConstructIdForSegment(m_segments[ii].Id, m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                // look for matching block.
                if (m_stage == Stage.Blocks && m_blocks != null)
                {
                    for (int ii = 0; ii < m_blocks.Count; ii++)
                    {
                        UnderlyingSystemBlock block = system.FindBlock(m_blocks[ii]);

                        if (block != null && base.BrowseName.Name == block.Name)
                        {
                            targetId = ModelUtils.ConstructIdForBlock(m_blocks[ii], m_source.NodeId.NamespaceIndex);
                            break;
                        }
                    }
                }

                m_position = Int32.MaxValue;
            }

            // return the child at the next position.
            else
            {
                // look for next segment.
                if (m_stage == Stage.Segments && m_segments != null)
                {
                    if (m_position >= m_segments.Count)
                    {
                        return(null);
                    }

                    targetId = ModelUtils.ConstructIdForSegment(m_segments[m_position++].Id, m_source.NodeId.NamespaceIndex);
                }

                // look for next block.
                else if (m_stage == Stage.Blocks && m_blocks != null)
                {
                    if (m_position >= m_blocks.Count)
                    {
                        return(null);
                    }

                    targetId = ModelUtils.ConstructIdForBlock(m_blocks[m_position++], m_source.NodeId.NamespaceIndex);
                }
            }

            // create reference.
            if (targetId != null)
            {
                return(new NodeStateReference(ReferenceTypeIds.Organizes, false, targetId));
            }

            return(null);
        }