コード例 #1
0
ファイル: HdaModelUtils.cs プロジェクト: fr830/OPCUA.NET
        /// <summary>
        /// Gets the item annotations node.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        /// <returns></returns>
        public static PropertyState GetItemAnnotationsNode(string itemId, ushort namespaceIndex)
        {
            if (itemId == null)
            {
                return(null);
            }

            PropertyState component = new PropertyState(null);

            component.NodeId                  = HdaParsedNodeId.Construct(HdaModelUtils.HdaItemAnnotations, itemId, null, namespaceIndex);
            component.SymbolicName            = Opc.Ua.BrowseNames.Annotations;
            component.BrowseName              = new QualifiedName(component.SymbolicName);
            component.DisplayName             = component.BrowseName.Name;
            component.DataType                = DataTypeIds.Annotation;
            component.ValueRank               = ValueRanks.Scalar;
            component.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate;
            component.Historizing             = false;
            component.AccessLevel             = AccessLevels.HistoryRead;
            component.UserAccessLevel         = AccessLevels.HistoryRead;
            component.ReferenceTypeId         = Opc.Ua.ReferenceTypeIds.HasProperty;
            component.TypeDefinitionId        = Opc.Ua.VariableTypeIds.PropertyType;

            component.AddReference(ReferenceTypeIds.HasProperty, true, HdaModelUtils.ConstructIdForHdaItem(itemId, namespaceIndex));

            return(component);
        }
コード例 #2
0
        //// Properties
        //

        /// <summary>
        /// Helper to create an PropertyState-Node for a certain type and add it to the information model.
        /// Note: __NO__ NodeId is created by the default! Must be done by outer functionality!!
        /// </summary>
        /// <typeparam name="T">C# type of the proprty</typeparam>
        /// <param name="parent">Parent node</param>
        /// <param name="mode">Type or instance</param>
        /// <param name="browseDisplayName">Name displayed in the node tree</param>
        /// <param name="dataTypeId">Data type, such as String.. Given by DataTypeIds...</param>
        /// <param name="value">Value of the type T or Null</param>
        /// <param name="referenceTypeFromParentId"></param>
        /// <param name="typeDefinitionId">Type definition; independent from DataType!</param>
        /// <param name="valueRank">-1 or e.g. 1 for array</param>
        /// <param name="defaultSettings">Apply default settings for a normal Property</param>
        /// <param name="modellingRule">Modeling Rule, if not None</param>
        /// <returns>NodeState</returns>
        public PropertyState <T> CreateAddPropertyState <T>(
            NodeState parent, AasUaBaseEntity.CreateMode mode,
            string browseDisplayName,
            NodeId dataTypeId, T value,
            NodeId referenceTypeFromParentId = null,
            NodeId typeDefinitionId          = null,
            int valueRank        = -2,
            bool defaultSettings = false,
            AasUaNodeHelper.ModellingRule modellingRule = AasUaNodeHelper.ModellingRule.None)
        {
            // apply cumulative settings
            if (defaultSettings)
            {
                referenceTypeFromParentId = ReferenceTypeIds.HasProperty;
                typeDefinitionId          = VariableTypeIds.PropertyType;
                if (valueRank == -2)
                {
                    valueRank = -1;
                }
            }

            // make Property
            var x = new PropertyState <T>(parent);

            x.BrowseName  = "" + browseDisplayName;
            x.DisplayName = "" + browseDisplayName;
            x.Description = new LocalizedText("en", browseDisplayName);
            x.DataType    = dataTypeId;
            if (valueRank > -2)
            {
                x.ValueRank = valueRank;
            }
            // ReSharper disable once RedundantCast
            x.Value = (T)value;
            AasUaNodeHelper.CheckSetModellingRule(modellingRule, x);
            x.NodeId = nodeMgr.New(nodeMgr.SystemContext, mode, x);

            // add Node
            nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
            if (parent != null)
            {
                parent.AddChild(x);
            }

            // set relations
            if (referenceTypeFromParentId != null)
            {
                if (parent != null)
                {
                    parent.AddReference(referenceTypeFromParentId, false, x.NodeId);
                    if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent)
                    {
                        x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
                    }
                    if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty)
                    {
                        x.AddReference(referenceTypeFromParentId, true, parent.NodeId);
                    }
                }
            }
            if (typeDefinitionId != null)
            {
                x.TypeDefinitionId = typeDefinitionId;
            }

            x.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            x.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            return(x);
        }
コード例 #3
0
        /// <summary>
        /// Gets the item annotations node.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="namespaceIndex">Index of the namespace.</param>
        /// <returns></returns>
        public static PropertyState GetItemAnnotationsNode(string itemId, ushort namespaceIndex)
        {
            if (itemId == null)
            {
                return null;
            }

            PropertyState component = new PropertyState(null);

            component.NodeId = HdaParsedNodeId.Construct(HdaModelUtils.HdaItemAnnotations, itemId, null, namespaceIndex);
            component.SymbolicName = Opc.Ua.BrowseNames.Annotations;
            component.BrowseName = new QualifiedName(component.SymbolicName);
            component.DisplayName = component.BrowseName.Name;
            component.DataType = DataTypeIds.Annotation;
            component.ValueRank = ValueRanks.Scalar;
            component.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate;
            component.Historizing = false;
            component.AccessLevel = AccessLevels.HistoryRead;
            component.UserAccessLevel = AccessLevels.HistoryRead;
            component.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasProperty;
            component.TypeDefinitionId = Opc.Ua.VariableTypeIds.PropertyType;

            component.AddReference(ReferenceTypeIds.HasProperty, true, HdaModelUtils.ConstructIdForHdaItem(itemId, namespaceIndex));

            return component;
        }