Пример #1
0
        /// <summary>
        /// Gets the annotations property node id.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <returns></returns>
        public NodeId GetAnnotationsPropertyNodeId(Session session, HdaItemHandle itemHandle)
        {
            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

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

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // check if annotations are supported.
            ReadValueId valueToRead = GetReadValueId(supportedAttributes, ComHdaProxy.INTERNAL_ATTRIBUTE_ANNOTATION);

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

            // return node id.
            return(valueToRead.NodeId);
        }
Пример #2
0
        /// <summary>
        /// Gets the type of the remote data.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <returns></returns>
        public TypeInfo GetRemoteDataType(HdaItemHandle handle)
        {
            InternalHandle handle2 = handle as InternalHandle;

            if (handle2 != null)
            {
                return(handle2.Item.RemoteType);
            }

            return(TypeInfo.Scalars.Variant);
        }
Пример #3
0
        /// <summary>
        /// Reads the node ids used to fetch the history of the specified attributes.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <param name="nodeIds">The node ids.</param>
        /// <returns></returns>
        public int[] GetAttributeHistoryNodeIds(Session session, HdaItemHandle itemHandle, uint[] attributeIds, out NodeId[] nodeIds)
        {
            nodeIds = new NodeId[attributeIds.Length];
            int[] results = new int[attributeIds.Length];

            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

            if (handle == null)
            {
                for (int ii = 0; ii < results.Length; ii++)
                {
                    results[ii] = ResultIds.E_INVALIDHANDLE;
                }

                return(results);
            }

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // build list of values to read.
            ReadValueIdCollection valuesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < attributeIds.Length; ii++)
            {
                ReadValueId valueToRead = GetReadValueId(supportedAttributes, attributeIds[ii]);

                if (valueToRead == null)
                {
                    results[ii] = ResultIds.E_INVALIDATTRID;
                    continue;
                }

                if (valueToRead.AttributeId == Attributes.Value)
                {
                    nodeIds[ii] = valueToRead.NodeId;
                    results[ii] = ResultIds.S_OK;
                }
                else
                {
                    results[ii] = ResultIds.S_NODATA;
                }
            }

            return(results);
        }
Пример #4
0
        /// <summary>
        /// Gets the item handles.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemIds">The item ids.</param>
        /// <param name="clientHandles">The client handles.</param>
        /// <param name="validateOnly">if set to <c>true</c> handles are not created and item ids are only validated.</param>
        /// <returns>The handles containing any error information.</returns>
        public HdaItemHandle[] GetItemHandles(Session session, string[] itemIds, int[] clientHandles, bool validateOnly)
        {
            HdaItemHandle[]       handles     = new HdaItemHandle[itemIds.Length];
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < itemIds.Length; ii++)
            {
                InternalHandle handle = new InternalHandle();
                handles[ii] = handle;

                if (clientHandles != null)
                {
                    handle.ClientHandle = clientHandles[ii];
                }

                string itemId = itemIds[ii];

                if (String.IsNullOrEmpty(itemId))
                {
                    handle.Error = ResultIds.E_INVALIDITEMID;
                    continue;
                }

                // check if item has already been assigned.
                Item item = null;

                if (!validateOnly)
                {
                    lock (m_lock)
                    {
                        if (m_items.TryGetValue(itemId, out item))
                        {
                            handle.NodeId       = item.NodeId;
                            handle.ServerHandle = ++m_lastServerHandle;
                            handle.Item         = item;
                            item.Refs++;
                            m_handles[handle.ServerHandle] = handle;
                            Utils.Trace("Created Handle: {0} {1}", handle.ServerHandle, handle.NodeId);
                            continue;
                        }
                    }
                }

                // create a new item.
                handle.Item  = item = new Item();
                item.ItemId  = itemId;
                handle.Error = ResultIds.S_OK; // assume valid for no - set to an error when detected.

                handle.NodeId = item.NodeId = m_mapper.GetRemoteNodeId(itemId);

                nodesToRead.Add(Construct(handle, Attributes.UserAccessLevel));
                nodesToRead.Add(Construct(handle, Attributes.DisplayName));
                nodesToRead.Add(Construct(handle, Attributes.Description));
                nodesToRead.Add(Construct(handle, Attributes.DataType));
                nodesToRead.Add(Construct(handle, Attributes.ValueRank));
                nodesToRead.Add(Construct(handle, Attributes.Historizing));
            }

            // check if nothing to do.
            if (nodesToRead.Count == 0)
            {
                return(handles);
            }

            DataValueCollection      values          = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            // read values from the UA server.
            session.Read(
                null,
                0,
                TimestampsToReturn.Neither,
                nodesToRead,
                out values,
                out diagnosticInfos);

            // validate response from the UA server.
            ClientBase.ValidateResponse(values, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            // assign a local handle to all valid items.
            NodeIdCollection      nodesToRegister = new NodeIdCollection();
            List <InternalHandle> items           = new List <InternalHandle>();

            for (int ii = 0; ii < nodesToRead.Count; ii++)
            {
                InternalHandle handle = (InternalHandle)nodesToRead[ii].Handle;
                DataValue      value  = values[ii];
                Item           item   = handle.Item;

                // check status codes.
                if (StatusCode.IsBad(value.StatusCode))
                {
                    // description is an optional attribute.
                    if (nodesToRead[ii].AttributeId != Attributes.Description)
                    {
                        handle.Error = ResultIds.E_UNKNOWNITEMID;
                    }

                    continue;
                }

                // check access level.
                if (nodesToRead[ii].AttributeId == Attributes.UserAccessLevel)
                {
                    byte accessLevel = value.GetValue <byte>(AccessLevels.None);

                    if ((accessLevel & AccessLevels.HistoryRead) == 0)
                    {
                        handle.Error = ResultIds.E_UNKNOWNITEMID;
                        continue;
                    }
                }

                // save attribute.
                switch (nodesToRead[ii].AttributeId)
                {
                case Attributes.DisplayName: { item.DisplayName = value.GetValue <LocalizedText>(null); break; }

                case Attributes.Description: { item.Description = value.GetValue <LocalizedText>(null); break; }

                case Attributes.DataType: { item.DataType = value.GetValue <NodeId>(null); break; }

                case Attributes.ValueRank: { item.ValueRank = value.GetValue <int>(ValueRanks.Scalar); break; }

                case Attributes.Historizing: { item.Historizing = value.GetValue <bool>(false); break; }
                }

                // should have all item metadata when processing the historizing attribute result.
                if (nodesToRead[ii].AttributeId == Attributes.Historizing)
                {
                    // check for a fatal error with one or more mandatory attributes.
                    if (handle.Error != ResultIds.S_OK)
                    {
                        continue;
                    }

                    BuiltInType builtInType = DataTypes.GetBuiltInType(item.DataType, session.TypeTree);
                    item.RemoteType = new TypeInfo(builtInType, item.ValueRank);

                    if (!validateOnly)
                    {
                        nodesToRegister.Add(item.NodeId);
                        items.Add(handle);

                        lock (m_lock)
                        {
                            m_items[handle.Item.ItemId] = handle.Item;
                            handle.ServerHandle         = ++m_lastServerHandle;
                            handle.NodeId = handle.Item.NodeId;
                            handle.Item.Refs++;
                            m_handles[handle.ServerHandle] = handle;
                            Utils.Trace("Created Handle: {0} {1}", handle.ServerHandle, handle.NodeId);
                        }
                    }
                }
            }

            return(handles);
        }
Пример #5
0
        /// <summary>
        /// Reads the current values for the specified attributes.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <returns></returns>
        public DaValue[] ReadCurrentValues(Session session, HdaItemHandle itemHandle, uint[] attributeIds)
        {
            DaValue[] results = new DaValue[attributeIds.Length];

            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

            if (handle == null)
            {
                for (int ii = 0; ii < results.Length; ii++)
                {
                    results[ii]       = new DaValue();
                    results[ii].Error = ResultIds.E_INVALIDHANDLE;
                }

                return(results);
            }

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // build list of values to read.
            ReadValueIdCollection valuesToRead = new ReadValueIdCollection();
            List <int>            indexes      = new List <int>();

            for (int ii = 0; ii < attributeIds.Length; ii++)
            {
                ReadValueId valueToRead = GetReadValueId(supportedAttributes, attributeIds[ii]);

                if (valueToRead == null)
                {
                    results[ii]       = new DaValue();
                    results[ii].Error = ResultIds.E_INVALIDATTRID;
                    continue;
                }

                valuesToRead.Add(valueToRead);
                indexes.Add(ii);

                // need to fetch the value rank as well.
                if (attributeIds[ii] == Constants.OPCHDA_DATA_TYPE)
                {
                    valuesToRead.Add(GetReadValueId(supportedAttributes, ComHdaProxy.INTERNAL_ATTRIBUTE_VALUE_RANK));
                    indexes.Add(-1);
                }
            }

            // nothing to do.
            if (valuesToRead.Count == 0)
            {
                return(results);
            }

            // read values from the UA server.
            DataValueCollection      values          = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            session.Read(
                null,
                0,
                TimestampsToReturn.Neither,
                valuesToRead,
                out values,
                out diagnosticInfos);

            // validate response from the UA server.
            ClientBase.ValidateResponse(values, valuesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, valuesToRead);

            // assign a local handle to all valid items.
            for (int ii = 0; ii < valuesToRead.Count; ii++)
            {
                int  index       = indexes[ii];
                uint attributeId = (uint)valuesToRead[ii].Handle;

                // check for values which are combined with other values to create the value (e.g. ValueRank).
                if (index == -1)
                {
                    continue;
                }

                results[index] = GetAttributeValue(session, attributeId, values, ii);

                // only support current value for now.
                if (results[index].Error == ResultIds.S_OK)
                {
                    results[index].Error = ResultIds.S_CURRENTVALUE;
                }
            }

            return(results);
        }
Пример #6
0
        /// <summary>
        /// Gets the item handles.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemIds">The item ids.</param>
        /// <param name="clientHandles">The client handles.</param>
        /// <param name="validateOnly">if set to <c>true</c> handles are not created and item ids are only validated.</param>
        /// <returns>The handles containing any error information.</returns>
        public HdaItemHandle[] GetItemHandles(Session session, string[] itemIds, int[] clientHandles, bool validateOnly)
        {
            HdaItemHandle[] handles = new HdaItemHandle[itemIds.Length];
            ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < itemIds.Length; ii++)
            {
                InternalHandle handle = new InternalHandle();
                handles[ii] = handle;

                if (clientHandles != null)
                {
                    handle.ClientHandle = clientHandles[ii];
                }

                string itemId = itemIds[ii];

                if (String.IsNullOrEmpty(itemId))
                {
                    handle.Error = ResultIds.E_INVALIDITEMID;
                    continue;
                }

                // check if item has already been assigned.
                Item item = null;

                if (!validateOnly)
                {
                    lock (m_lock)
                    {
                        if (m_items.TryGetValue(itemId, out item))
                        {
                            handle.NodeId = item.NodeId;
                            handle.ServerHandle = ++m_lastServerHandle;
                            handle.Item = item;
                            item.Refs++;
                            m_handles[handle.ServerHandle] = handle;
                            Utils.Trace("Created Handle: {0} {1}", handle.ServerHandle, handle.NodeId);
                            continue;
                        }
                    }
                }

                // create a new item.
                handle.Item = item = new Item();
                item.ItemId = itemId;                
                handle.Error = ResultIds.S_OK; // assume valid for no - set to an error when detected.

                handle.NodeId = item.NodeId = m_mapper.GetRemoteNodeId(itemId);

                nodesToRead.Add(Construct(handle, Attributes.UserAccessLevel));
                nodesToRead.Add(Construct(handle, Attributes.DisplayName));
                nodesToRead.Add(Construct(handle, Attributes.Description));
                nodesToRead.Add(Construct(handle, Attributes.DataType));
                nodesToRead.Add(Construct(handle, Attributes.ValueRank));
                nodesToRead.Add(Construct(handle, Attributes.Historizing));
            }

            // check if nothing to do.
            if (nodesToRead.Count == 0)
            {
                return handles;
            }

            DataValueCollection values = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            // read values from the UA server.
            session.Read(
                null,
                0,
                TimestampsToReturn.Neither,
                nodesToRead,
                out values,
                out diagnosticInfos);

            // validate response from the UA server.
            ClientBase.ValidateResponse(values, nodesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

            // assign a local handle to all valid items.
            NodeIdCollection nodesToRegister = new NodeIdCollection();
            List<InternalHandle> items = new List<InternalHandle>();

            for (int ii = 0; ii < nodesToRead.Count; ii++)
            {
                InternalHandle handle = (InternalHandle)nodesToRead[ii].Handle;
                DataValue value = values[ii];
                Item item = handle.Item;
                
                // check status codes.
                if (StatusCode.IsBad(value.StatusCode))
                {
                    // description is an optional attribute.
                    if (nodesToRead[ii].AttributeId != Attributes.Description)
                    {
                        handle.Error = ResultIds.E_UNKNOWNITEMID;
                    }

                    continue;
                }

                // check access level.
                if (nodesToRead[ii].AttributeId == Attributes.UserAccessLevel)
                {
                    byte accessLevel = value.GetValue<byte>(AccessLevels.None);

                    if ((accessLevel & AccessLevels.HistoryRead) == 0)
                    {
                        handle.Error = ResultIds.E_UNKNOWNITEMID;
                        continue;
                    }
                }
                
                // save attribute.
                switch (nodesToRead[ii].AttributeId)
                {
                    case Attributes.DisplayName: { item.DisplayName = value.GetValue<LocalizedText>(null); break; }
                    case Attributes.Description: { item.Description = value.GetValue<LocalizedText>(null); break; }
                    case Attributes.DataType: { item.DataType = value.GetValue<NodeId>(null); break; }
                    case Attributes.ValueRank: { item.ValueRank = value.GetValue<int>(ValueRanks.Scalar); break; }
                    case Attributes.Historizing: { item.Historizing = value.GetValue<bool>(false); break; }
                }

                // should have all item metadata when processing the historizing attribute result.
                if (nodesToRead[ii].AttributeId == Attributes.Historizing)
                {
                    // check for a fatal error with one or more mandatory attributes.
                    if (handle.Error != ResultIds.S_OK)
                    {
                        continue;
                    }

                    BuiltInType builtInType = DataTypes.GetBuiltInType(item.DataType, session.TypeTree);
                    item.RemoteType = new TypeInfo(builtInType, item.ValueRank);

                    if (!validateOnly)
                    {
                        nodesToRegister.Add(item.NodeId);
                        items.Add(handle);

                        lock (m_lock)
                        {
                            m_items[handle.Item.ItemId] = handle.Item;
                            handle.ServerHandle = ++m_lastServerHandle;
                            handle.NodeId = handle.Item.NodeId;
                            handle.Item.Refs++;
                            m_handles[handle.ServerHandle] = handle;
                            Utils.Trace("Created Handle: {0} {1}", handle.ServerHandle, handle.NodeId);
                        }
                    }
                }
            }

            return handles;
        }
Пример #7
0
        /// <summary>
        /// Gets the annotations property node id.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <returns></returns>
        public NodeId GetAnnotationsPropertyNodeId(Session session, HdaItemHandle itemHandle)
        {
            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

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

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // check if annotations are supported.
            ReadValueId valueToRead = GetReadValueId(supportedAttributes, ComHdaProxy.INTERNAL_ATTRIBUTE_ANNOTATION);

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

            // return node id.
            return valueToRead.NodeId;
        }
Пример #8
0
        /// <summary>
        /// Reads the node ids used to fetch the history of the specified attributes.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <param name="nodeIds">The node ids.</param>
        /// <returns></returns>
        public int[] GetAttributeHistoryNodeIds(Session session, HdaItemHandle itemHandle, uint[] attributeIds, out NodeId[] nodeIds)
        {
            nodeIds = new NodeId[attributeIds.Length];
            int[] results = new int[attributeIds.Length];

            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

            if (handle == null)
            {
                for (int ii = 0; ii < results.Length; ii++)
                {
                    results[ii] = ResultIds.E_INVALIDHANDLE;
                }

                return results;
            }

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // build list of values to read.
            ReadValueIdCollection valuesToRead = new ReadValueIdCollection();

            for (int ii = 0; ii < attributeIds.Length; ii++)
            {
                ReadValueId valueToRead = GetReadValueId(supportedAttributes, attributeIds[ii]);

                if (valueToRead == null)
                {
                    results[ii] = ResultIds.E_INVALIDATTRID;
                    continue;
                }

                if (valueToRead.AttributeId == Attributes.Value)
                {
                    nodeIds[ii] = valueToRead.NodeId;
                    results[ii] = ResultIds.S_OK;
                }
                else
                {
                    results[ii] = ResultIds.S_NODATA;
                }
            }

            return results;
        }
Пример #9
0
        /// <summary>
        /// Reads the current values for the specified attributes.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="itemHandle">The item handle.</param>
        /// <param name="attributeIds">The attribute ids.</param>
        /// <returns></returns>
        public DaValue[] ReadCurrentValues(Session session, HdaItemHandle itemHandle, uint[] attributeIds)
        {
            DaValue[] results = new DaValue[attributeIds.Length];

            // check handle.
            InternalHandle handle = itemHandle as InternalHandle;

            if (handle == null)
            {
                for (int ii = 0; ii < results.Length; ii++)
                {
                    results[ii] = new DaValue();
                    results[ii].Error = ResultIds.E_INVALIDHANDLE;
                }

                return results;
            }

            // look up the supported attributes for an item.
            ReadValueIdCollection supportedAttributes = handle.Item.SupportedAttributes;

            if (supportedAttributes == null)
            {
                handle.Item.SupportedAttributes = supportedAttributes = GetAvailableAttributes(session, handle.NodeId);
            }

            // build list of values to read.
            ReadValueIdCollection valuesToRead = new ReadValueIdCollection();
            List<int> indexes = new List<int>();

            for (int ii = 0; ii < attributeIds.Length; ii++)
            {
                ReadValueId valueToRead = GetReadValueId(supportedAttributes, attributeIds[ii]);

                if (valueToRead == null)
                {
                    results[ii] = new DaValue();
                    results[ii].Error = ResultIds.E_INVALIDATTRID;
                    continue;
                }

                valuesToRead.Add(valueToRead);
                indexes.Add(ii);

                // need to fetch the value rank as well.
                if (attributeIds[ii] == Constants.OPCHDA_DATA_TYPE)
                {
                    valuesToRead.Add(GetReadValueId(supportedAttributes, ComHdaProxy.INTERNAL_ATTRIBUTE_VALUE_RANK));
                    indexes.Add(-1);
                }
            }

            // nothing to do.
            if (valuesToRead.Count == 0)
            {
                return results;
            }

            // read values from the UA server.
            DataValueCollection values = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            session.Read(
                null,
                0,
                TimestampsToReturn.Neither,
                valuesToRead,
                out values,
                out diagnosticInfos);

            // validate response from the UA server.
            ClientBase.ValidateResponse(values, valuesToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, valuesToRead);

            // assign a local handle to all valid items.
            for (int ii = 0; ii < valuesToRead.Count; ii++)
            {
                int index = indexes[ii];
                uint attributeId = (uint)valuesToRead[ii].Handle;

                // check for values which are combined with other values to create the value (e.g. ValueRank).
                if (index == -1)
                {
                    continue;
                }

                results[index] = GetAttributeValue(session, attributeId, values, ii);

                // only support current value for now.
                if (results[index].Error == ResultIds.S_OK)
                {
                    results[index].Error = ResultIds.S_CURRENTVALUE;
                }
            }

            return results;
        }
Пример #10
0
        /// <summary>
        /// Gets the type of the remote data.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <returns></returns>
        public TypeInfo GetRemoteDataType(HdaItemHandle handle)
        {
            InternalHandle handle2 = handle as InternalHandle;

            if (handle2 != null)
            {
                return handle2.Item.RemoteType;
            }

            return TypeInfo.Scalars.Variant;
        }