Beispiel #1
0
        /// <summary>
        /// Adds a read request for the specified property.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <returns>The new request.</returns>
        private ReadRequest Add(string itemId, DaProperty property)
        {
            if (m_index == null)
            {
                m_index = new Dictionary <string, ReadRequest>();
            }

            if (!String.IsNullOrEmpty(property.ItemId))
            {
                return(Add(property.ItemId));
            }

            return(Add(itemId, property.PropertyId));
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DaPropertyState"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        public DaPropertyState(
            ISystemContext context,
            string itemId,
            DaProperty property,
            ushort namespaceIndex)
            :
            base(null)
        {
            this.TypeDefinitionId = Opc.Ua.VariableTypeIds.DataItemType;
            this.Description      = null;
            this.WriteMask        = 0;
            this.UserWriteMask    = 0;

            if (property != null)
            {
                Initialize(context, itemId, property, namespaceIndex);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes the node from the element.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="property">The property.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        public void Initialize(ISystemContext context, string itemId, DaProperty property, ushort namespaceIndex)
        {
            m_itemId   = itemId;
            m_property = property;

            if (property == null)
            {
                return;
            }

            this.NodeId           = ModelUtils.ConstructIdForDaElement(m_itemId, property.PropertyId, namespaceIndex);
            this.BrowseName       = new QualifiedName(property.Name, namespaceIndex);
            this.DisplayName      = new LocalizedText(property.Name);
            this.TypeDefinitionId = Opc.Ua.VariableTypeIds.PropertyType;
            this.Value            = null;
            this.StatusCode       = StatusCodes.BadWaitingForInitialData;
            this.Timestamp        = DateTime.UtcNow;

            bool isArray = false;

            this.DataType        = ComUtils.GetDataTypeId(property.DataType, out isArray);
            this.ValueRank       = (isArray)?ValueRanks.OneOrMoreDimensions:ValueRanks.Scalar;
            this.ArrayDimensions = null;

            // assume that properties with item ids are writeable. the server may still reject the write.
            if (String.IsNullOrEmpty(property.ItemId))
            {
                this.AccessLevel = AccessLevels.CurrentRead;
            }
            else
            {
                this.AccessLevel = AccessLevels.CurrentReadOrWrite;
            }

            this.UserAccessLevel         = this.AccessLevel;
            this.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate;
            this.Historizing             = false;

            // add a reference to the parent node.
            NodeId parentNodeId = ModelUtils.ConstructIdForDaElement(itemId, -1, namespaceIndex);

            this.AddReference(ReferenceTypeIds.HasProperty, true, parentNodeId);
        }
Beispiel #4
0
 /// <summary>
 /// Constructs a property node for a DA property.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="parentId">The parent id.</param>
 /// <param name="property">The property.</param>
 /// <param name="namespaceIndex">Index of the namespace.</param>
 /// <returns>The property node.</returns>
 public static PropertyState ConstructProperty(ISystemContext context, string parentId, DaProperty property, ushort namespaceIndex)
 {
     return(new DaPropertyState(context, parentId, property, namespaceIndex));
 }
Beispiel #5
0
        /// <summary>
        /// Read the available non-built in properties from the server.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="updateCache">if set to <c>true</c> the cache is updated.</param>
        /// <returns>The array of properties.</returns>
        public DaProperty[] ReadAvailableProperties(string itemId, bool updateCache)
        {
            string methodName = "IOPCItemProperties.QueryAvailableProperties";

            // query for available properties.
            int count = 0;

            IntPtr pPropertyIds  = IntPtr.Zero;
            IntPtr pDescriptions = IntPtr.Zero;
            IntPtr pDataTypes    = IntPtr.Zero;

            try
            {
                IOPCItemProperties server = BeginComCall <IOPCItemProperties>(methodName, true);

                server.QueryAvailableProperties(
                    itemId,
                    out count,
                    out pPropertyIds,
                    out pDescriptions,
                    out pDataTypes);
            }
            catch (Exception e)
            {
                if (ComUtils.IsUnknownError(e, ResultIds.E_FAIL, ResultIds.E_UNKNOWNITEMID, ResultIds.E_INVALIDITEMID))
                {
                    ComUtils.TraceComError(e, methodName);
                }

                return(null);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            int[]    propertyIds  = ComUtils.GetInt32s(ref pPropertyIds, count, true);
            string[] descriptions = ComUtils.GetUnicodeStrings(ref pDescriptions, count, true);
            short[]  datatype     = ComUtils.GetInt16s(ref pDataTypes, count, true);

            List <DaProperty> properties = new List <DaProperty>();

            for (int ii = 0; ii < count; ii++)
            {
                // do not return any of the built in properties.
                if (propertyIds[ii] <= PropertyIds.TimeZone)
                {
                    continue;
                }

                DaProperty property = new DaProperty();

                property.PropertyId = propertyIds[ii];
                property.Name       = descriptions[ii];
                property.DataType   = datatype[ii];

                properties.Add(property);
            }

            // fetch the item ids.
            if (properties.Count > 0)
            {
                DaProperty[] array = properties.ToArray();

                GetPropertyItemIds(itemId, array);

                // update the cache.
                if (updateCache)
                {
                    lock (m_cache)
                    {
                        DaElement element = null;

                        if (m_cache.TryGetValue(itemId, out element))
                        {
                            element.Properties = array;
                        }
                    }
                }

                return(array);
            }

            return(null);
        }