Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private BaseDataVariableState CreateVariable(NodeState parent, string path,
                                                     string name, string displayName, NodeId dataType, bool isArray, object defaultValue)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent)
            {
                SymbolicName     = name,
                ReferenceTypeId  = ReferenceTypes.Organizes,
                TypeDefinitionId = VariableTypeIds.BaseDataVariableType,
                NodeId           = new NodeId(path, NamespaceIndex),
                BrowseName       = new QualifiedName(path, NamespaceIndex),
                DisplayName      = new LocalizedText(displayName),
                WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description,
                UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description,
                DataType         = dataType,
                ValueRank        = isArray ? ValueRanks.OneDimension : ValueRanks.Scalar,
                AccessLevel      = AccessLevels.CurrentReadOrWrite,
                UserAccessLevel  = AccessLevels.CurrentReadOrWrite,
                Historizing      = false,
                Value            = defaultValue,
                StatusCode       = StatusCodes.Bad,
                Timestamp        = DateTime.UtcNow
            };

            if (isArray)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }

            parent?.AddChild(variable);
            return(variable);
        }
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateDataItemVariable(NodeState parent, string path, string name, BuiltInType dataType, int valueRank, byte accessLevel)
        {
            DataItemState variable = new DataItemState(parent);

            variable.ValuePrecision = new PropertyState <double>(variable);
            variable.Definition     = new PropertyState <string>(variable);

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName    = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.NodeId          = new NodeId(path, NamespaceIndex);
            variable.BrowseName      = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName     = new LocalizedText("en", name);
            variable.WriteMask       = AttributeWriteMask.None;
            variable.UserWriteMask   = AttributeWriteMask.None;
            variable.DataType        = (uint)dataType;
            variable.ValueRank       = valueRank;
            variable.AccessLevel     = accessLevel;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = Opc.Ua.TypeInfo.GetDefaultValue((uint)dataType, valueRank, Server.TypeTree);
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;

            if (valueRank == ValueRanks.OneDimension)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0, 0
                });
            }

            variable.ValuePrecision.Value           = 2;
            variable.ValuePrecision.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.ValuePrecision.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Definition.Value           = String.Empty;
            variable.Definition.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.Definition.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Ejemplo n.º 3
0
        private WeatherMapVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank)
        {
            WeatherMapVariableState variable = new WeatherMapVariableState(parent);

            //variable.CityName.Value = "i";

            variable.SymbolicName     = name;
            variable.ReferenceTypeId  = ReferenceTypes.Organizes;
            variable.TypeDefinitionId = new NodeId(VariableTypeIds.WeatherMapVariableType.Identifier, VariableTypeIds.WeatherMapVariableType.NamespaceIndex);
            variable.NodeId           = new NodeId(path, NamespaceIndex);
            variable.BrowseName       = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName      = new LocalizedText("en", name);
            variable.WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.Description      = new String("Information about weather for" + variable.SymbolicName.ToString());
            //variable.ClearChangeMasks(SystemContext, true);
            variable.DataType        = dataType;
            variable.ValueRank       = valueRank;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentRead;
            variable.Historizing     = true;


            variable.Value = GetNewValue(variable.SymbolicName.ToString());
            if (variable.Value != null)
            {
                variable.StatusCode = StatusCodes.Good;
            }
            else
            {
                variable.StatusCode = StatusCodes.Bad;
            }
            variable.Timestamp = DateTime.UtcNow;

            if (valueRank == ValueRanks.OneDimension)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0, 0
                });
            }

            if (parent != null)
            {
                parent.AddChild(variable);
            }



            return(variable);
        }
Ejemplo n.º 4
0
        //// Objects
        //

        /// <summary>
        /// Helper to create an Object-Node. Note: __NO__ NodeId is created by the default! Must be done by outer
        /// functionality!!
        /// </summary>
        /// <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="referenceTypeFromParentId"></param>
        /// <param name="typeDefinitionId">Type of the Object</param>
        /// <param name="modellingRule">Modeling Rule, if not None</param>
        /// <param name="extraName"></param>
        /// <returns>The node</returns>
        public BaseObjectState CreateAddObject(
            NodeState parent, AasUaBaseEntity.CreateMode mode,
            string browseDisplayName,
            NodeId referenceTypeFromParentId            = null,
            NodeId typeDefinitionId                     = null,
            AasUaNodeHelper.ModellingRule modellingRule = AasUaNodeHelper.ModellingRule.None,
            string extraName = null)
        {
            var x = AasUaNodeHelper.CreateObject(parent, browseDisplayName, typeDefinitionId: typeDefinitionId,
                                                 modellingRule: modellingRule, extraName: extraName);

            x.NodeId = nodeMgr.NewFromParent(nodeMgr.SystemContext, mode, x, parent);
            nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
            if (parent != null)
            {
                parent.AddChild(x);
            }

            if (referenceTypeFromParentId != null)
            {
                if (parent != null)
                {
                    if (!parent.ReferenceExists(referenceTypeFromParentId, false, x.NodeId))
                    {
                        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);
                    }
                }

                //// nodeMgr.AddReference(parentNodeId, new AasReference(referenceTypeId, false, x.NodeId));
            }

            //// if (typeDefinitionId != null)
            //// {
            ////     x.TypeDefinitionId = typeDefinitionId;
            ////     x.AddReference(ReferenceTypeIds.HasTypeDefinition, false, typeDefinitionId);
            ////     // nodeMgr.AddReference(x.NodeId, new AasReference(ReferenceTypeIds.HasTypeDefinition, false,
            ////     // typeDefinitionId));
            //// }

            return(x);
        }
Ejemplo n.º 5
0
        //// Folders
        //

        public FolderState CreateAddFolder(NodeState parent, string browseDisplayName)
        {
            var x = new FolderState(parent);

            x.BrowseName       = browseDisplayName;
            x.DisplayName      = browseDisplayName;
            x.NodeId           = nodeMgr.New(nodeMgr.SystemContext, x);
            x.TypeDefinitionId = ObjectTypeIds.FolderType;
            nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
            if (parent != null)
            {
                parent.AddChild(x);
            }
            return(x);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateMultiStateDiscreteItemVariable(NodeState parent, string path, string name,
                                                                   params string[] values)
        {
            MultiStateDiscreteState variable = new MultiStateDiscreteState(parent);

            variable.NodeId        = new NodeId(path, NamespaceIndex);
            variable.BrowseName    = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName   = new LocalizedText("en", name);
            variable.WriteMask     = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName    = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType        = DataTypeIds.UInt32;
            variable.ValueRank       = ValueRanks.Scalar;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = (uint)0;
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;
            variable.OnWriteValue    = OnWriteDiscrete;

            LocalizedText[] strings = new LocalizedText[values.Length];

            for (int ii = 0; ii < strings.Length; ii++)
            {
                strings[ii] = values[ii];
            }

            variable.EnumStrings.Value           = strings;
            variable.EnumStrings.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.EnumStrings.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
        public void addNode(BaseInstanceState node, NodeId parentId)
        {
            NodeState parent = Find(parentId);

            if (Find(node.NodeId) != null)
            {
                node.NodeId = getFreeNodeId(node.NodeId.NamespaceIndex, node.NodeId.Identifier.GetType() == typeof(int)?(uint)node.NodeId.Identifier:10000);
            }
            parent.AddChild(node);
            AddPredefinedNode(SystemContext, parent);
            parent.AddReference(ReferenceTypes.HasComponent, true, node.NodeId);
            IDictionary <NodeId, List <IReference> > refs = new Dictionary <NodeId, List <IReference> >();
            //IReference iref = parent.ref;
            //refs.Add(parent.NodeId, parent.GetReferences(SystemContext));
            //AddReferences();
        }
Ejemplo n.º 8
0
        public CodeGenVariableTypeBase CreateProperty(Dictionary <CodeGenNodeID, CodeGenNodeID> childrenIDMap,
                                                      NodeState parent,
                                                      string fileNoExtension,
                                                      string name,
                                                      string typeId, ushort typeNamespaceIndex, IdType typeNodeIdType,
                                                      string nodeId, ushort namespaceIndex, IdType nodeIdType,
                                                      string parentNodeId, ushort parentNamespaceIndex, IdType parentNodeIdType,
                                                      int valueRank)
        {
            PropertyState property = new PropertyState(parent);

            property.SymbolicName     = name;
            property.ReferenceTypeId  = ReferenceTypes.HasProperty;
            property.TypeDefinitionId = VariableTypeIds.PropertyType;
            property.NodeId           = Helper.CreateID(childrenIDMap, this, nodeId, namespaceIndex, nodeIdType);
            property.ValueRank        = valueRank;
            property.ArrayDimensions  = null;

            //TODO: More code for different types
            if (valueRank == ValueRanks.OneDimension)
            {
                property.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                property.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0, 0
                });
            }

            if (parent != null)
            {
                parent.AddChild(property);
            }

            CodeGenVariableTypeBase newNode = CodeGenNodeFactory.CreateVariable(name, fileNoExtension,
                                                                                typeId, typeNamespaceIndex, typeNodeIdType,
                                                                                nodeId, namespaceIndex, nodeIdType,
                                                                                parentNodeId, parentNamespaceIndex, parentNodeIdType);

            newNode.SetNode(property);
            newNode.IsProperty(true);
            newNode.Initialize(childrenIDMap, this);
            return(newNode);
        }
Ejemplo n.º 9
0
        public CodeGenVariableTypeBase CreateVariable(Dictionary <CodeGenNodeID, CodeGenNodeID> childrenIDMap,
                                                      NodeState parent,
                                                      string fileNoExtension,
                                                      string name,
                                                      string typeId, ushort typeNamespaceIndex, IdType typeNodeIdType,
                                                      string nodeId, ushort namespaceIndex, IdType nodeIdType,
                                                      string parentNodeId, ushort parentNamespaceIndex, IdType parentNodeIdType,
                                                      int valueRank)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent);

            variable.SymbolicName     = name;
            variable.TypeDefinitionId = Helper.CreateID(typeId, typeNamespaceIndex, typeNodeIdType);
            variable.NodeId           = Helper.CreateID(childrenIDMap, this, nodeId, namespaceIndex, nodeIdType);
            //variable.BrowseName       = new QualifiedName(name, NamespaceIndex);
            variable.ValueRank       = valueRank;
            variable.ArrayDimensions = null;

            //TODO: More code for different types
            if (valueRank == ValueRanks.OneDimension)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0, 0
                });
            }

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            CodeGenVariableTypeBase newNode = CodeGenNodeFactory.CreateVariable(name, fileNoExtension,
                                                                                typeId, typeNamespaceIndex, typeNodeIdType,
                                                                                nodeId, namespaceIndex, nodeIdType,
                                                                                parentNodeId, parentNamespaceIndex, parentNodeIdType);

            newNode.SetNode(variable);
            newNode.Initialize(childrenIDMap, this);
            return(newNode);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateTwoStateDiscreteItemVariable(NodeState parent, string path, string name,
                                                                 string trueState, string falseState)
        {
            TwoStateDiscreteState variable = new TwoStateDiscreteState(parent);

            variable.NodeId        = new NodeId(path, NamespaceIndex);
            variable.BrowseName    = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName   = new LocalizedText("en", name);
            variable.WriteMask     = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName    = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType        = DataTypeIds.Boolean;
            variable.ValueRank       = ValueRanks.Scalar;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = (bool)GetNewValue(variable);
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;

            variable.TrueState.Value           = trueState;
            variable.TrueState.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.TrueState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            variable.FalseState.Value           = falseState;
            variable.FalseState.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.FalseState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private BaseDataVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType,
                                                     int valueRank)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent);

            variable.SymbolicName     = name;
            variable.ReferenceTypeId  = ReferenceTypes.Organizes;
            variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
            variable.NodeId           = new NodeId(path, NamespaceIndex);
            variable.BrowseName       = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName      = new LocalizedText("en", name);
            variable.WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.DataType         = dataType;
            variable.ValueRank        = valueRank;
            variable.AccessLevel      = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel  = AccessLevels.CurrentReadOrWrite;
            variable.Historizing      = false;
            variable.Value            = GetNewValue(variable);
            variable.StatusCode       = StatusCodes.Good;
            variable.Timestamp        = DateTime.UtcNow;

            if (valueRank == ValueRanks.OneDimension)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0,
                    0
                });
            }

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Create a mechanism to create a Variable
        /// </summary>
        public static BaseDataVariableState CreateVariable(NodeState parent, ushort nameSpaceIndex, string path, string name, uint dataTypeIdentifier)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent);

            variable.SymbolicName     = name;
            variable.ReferenceTypeId  = ReferenceTypes.Organizes;
            variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
            variable.NodeId           = new NodeId(path, nameSpaceIndex);
            variable.BrowseName       = new QualifiedName(name, nameSpaceIndex);
            variable.DisplayName      = new LocalizedText("en", name);
            variable.WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            switch (dataTypeIdentifier)
            {
            case Opc.Ua.DataTypes.Boolean:
                variable.DataType = DataTypeIds.Boolean;
                variable.Value    = false;
                break;

            case Opc.Ua.DataTypes.Int32:
                variable.DataType = DataTypeIds.Int32;
                variable.Value    = AlarmDefines.NORMAL_START_VALUE;
                break;

            case Opc.Ua.DataTypes.Double:
                variable.DataType = DataTypeIds.Double;
                variable.Value    = (double)AlarmDefines.NORMAL_START_VALUE;
                break;
            }
            variable.ValueRank       = ValueRanks.Scalar;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
        /// <summary>
        /// Creates a new method using type Numeric for the NodeId.
        /// </summary>
        private MethodState CreateMethod(NodeState parent, uint id, string name)
        {
            MethodState method = new MethodState(parent)
            {
                SymbolicName    = name,
                ReferenceTypeId = ReferenceTypeIds.HasComponent,
                NodeId          = new NodeId(id, NamespaceIndex),
                BrowseName      = new QualifiedName(name, NamespaceIndex),
                DisplayName     = new LocalizedText("en", name),
                WriteMask       = AttributeWriteMask.None,
                UserWriteMask   = AttributeWriteMask.None,
                Executable      = true,
                UserExecutable  = true
            };

            parent?.AddChild(method);

            return(method);
        }
Ejemplo n.º 14
0
        //// Folders
        //

        public FolderState CreateAddFolder(AasUaBaseEntity.CreateMode mode,
                                           NodeState parent, string browseDisplayName,
                                           NodeId extraParentNodeId = null,
                                           bool doNotAddToParent    = false)
        {
            var x = new FolderState(parent);

            x.BrowseName       = browseDisplayName;
            x.DisplayName      = browseDisplayName;
            x.NodeId           = nodeMgr.New(nodeMgr.SystemContext, mode, x);
            x.TypeDefinitionId = ObjectTypeIds.FolderType;
            nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, x);
            if (parent != null && !doNotAddToParent)
            {
                parent.AddChild(x);
            }

            return(x);
        }
        /// <summary>
        /// Creates a new folder.
        /// </summary>
        private FolderState CreateFolder(NodeState parent, string path, string name)
        {
            FolderState folder = new FolderState(parent)
            {
                SymbolicName     = name,
                ReferenceTypeId  = ReferenceTypes.Organizes,
                TypeDefinitionId = ObjectTypeIds.FolderType,
                NodeId           = new NodeId(path, NamespaceIndex),
                BrowseName       = new QualifiedName(path, NamespaceIndex),
                DisplayName      = new LocalizedText("en", name),
                WriteMask        = AttributeWriteMask.None,
                UserWriteMask    = AttributeWriteMask.None,
                EventNotifier    = EventNotifiers.None
            };

            parent?.AddChild(folder);

            return(folder);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a mechanism to create a method
        /// </summary>
        public static MethodState CreateMethod(NodeState parent, ushort nameSpaceIndex, string path, string name)
        {
            MethodState method = new MethodState(parent);

            method.SymbolicName    = name;
            method.ReferenceTypeId = ReferenceTypeIds.HasComponent;
            method.NodeId          = new NodeId(path, nameSpaceIndex);
            method.BrowseName      = new QualifiedName(path, nameSpaceIndex);
            method.DisplayName     = new LocalizedText("en", name);
            method.WriteMask       = AttributeWriteMask.None;
            method.UserWriteMask   = AttributeWriteMask.None;
            method.Executable      = true;
            method.UserExecutable  = true;

            if (parent != null)
            {
                parent.AddChild(method);
            }

            return(method);
        }
Ejemplo n.º 17
0
        internal BaseObjectState CreateObject(NodeState parent, string path, string name, ushort namespaceIndex)
        {
            BaseObjectState folder = new BaseObjectState(parent);

            folder.SymbolicName     = name;
            folder.ReferenceTypeId  = ReferenceTypes.Organizes;
            folder.TypeDefinitionId = ObjectTypeIds.BaseObjectType;
            folder.NodeId           = new NodeId(path, namespaceIndex);
            folder.BrowseName       = new QualifiedName(name, namespaceIndex);
            folder.DisplayName      = folder.BrowseName.Name;
            folder.WriteMask        = AttributeWriteMask.None;
            folder.UserWriteMask    = AttributeWriteMask.None;
            folder.EventNotifier    = EventNotifiers.None;

            if (parent != null)
            {
                parent.AddChild(folder);
            }

            return(folder);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Create a mechanism to create a folder
        /// </summary>
        public static FolderState CreateFolder(NodeState parent, ushort nameSpaceIndex, string path, string name)
        {
            FolderState folder = new FolderState(parent);

            folder.SymbolicName     = name;
            folder.ReferenceTypeId  = ReferenceTypes.Organizes;
            folder.TypeDefinitionId = ObjectTypeIds.FolderType;
            folder.NodeId           = new NodeId(path, nameSpaceIndex);
            folder.BrowseName       = new QualifiedName(path, nameSpaceIndex);
            folder.DisplayName      = new LocalizedText("en", name);
            folder.WriteMask        = AttributeWriteMask.None;
            folder.UserWriteMask    = AttributeWriteMask.None;
            folder.EventNotifier    = EventNotifiers.None;

            if (parent != null)
            {
                parent.AddChild(folder);
            }

            return(folder);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 创建一个值节点,类型需要在创建的时候指定
        /// </summary>
        protected BaseDataVariableState CreateBaseVariable(NodeState parent, string name, string description,
                                                           NodeId dataType, int valueRank, object defaultValue)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent);

            variable.SymbolicName     = name;
            variable.ReferenceTypeId  = ReferenceTypes.Organizes;
            variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
            if (parent == null)
            {
                variable.NodeId = new NodeId(name, NamespaceIndex);
            }
            else
            {
                variable.NodeId = new NodeId(parent.NodeId.ToString() + "/" + name);
            }

            variable.Description     = description;
            variable.BrowseName      = new QualifiedName(name, NamespaceIndex);
            variable.DisplayName     = new LocalizedText(name);
            variable.WriteMask       = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.UserWriteMask   = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.DataType        = dataType;
            variable.ValueRank       = valueRank;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = defaultValue;
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.Now;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
        /// <summary>
        /// Creates a new method.
        /// </summary>
        private MethodState CreateMethod(NodeState parent, string path, string name, string description)
        {
            MethodState method = new MethodState(parent)
            {
                SymbolicName    = name,
                ReferenceTypeId = ReferenceTypeIds.HasComponent,
                NodeId          = new NodeId(path, NamespaceIndex),
                BrowseName      = new QualifiedName(path, NamespaceIndex),
                DisplayName     = new LocalizedText("en", name),
                WriteMask       = AttributeWriteMask.None,
                UserWriteMask   = AttributeWriteMask.None,
                Executable      = true,
                UserExecutable  = true,
                Description     = new LocalizedText(description)
            };

            if (parent != null)
            {
                parent.AddChild(method);
            }

            return(method);
        }
Ejemplo n.º 21
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);
        }
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.
        /// </remarks>
        public override void CreateAddressSpace(IDictionary <NodeId, IList <IReference> > externalReferences)
        {
            lock (Lock)
            {
                //Load DI nodeset
                LoadPredefinedNodes(SystemContext, externalReferences);

                //Add my variables to Address Space, under the DeviceSet object -----------------------
                //-------------------------------------------------------------------------------------

                //get the DeviceSet object of the Address Space
                NodeState DeviceSetobj = (NodeState)FindPredefinedNode(
                    ExpandedNodeId.ToNodeId(ObjectIds.DeviceSet, Server.NamespaceUris), typeof(NodeState));

                //-------------------------------------------------------------------------------------
                //create myDevice1 as a simple folder with a variable
                FolderState mydev1 = CreateFolder(DeviceSetobj, "myDevice1", "myDevice1");

                //create myDevice1/myVar1
                BaseDataVariableState myvar1 = CreateVariable(mydev1, "myVar1", "myVar1", Opc.Ua.DataTypeIds.Double, ValueRanks.Scalar);

                //create myDevice1/Actual_State
                BaseDataVariableState Actual_State = CreateVariable(mydev1, "Actual_State", "Actual_State", Opc.Ua.DataTypeIds.Double, ValueRanks.Scalar);

                //create myDevice1/Sensors_Data
                Sensors_Data = CreateVariable(mydev1, "Sensors_Data", "Sensors_Data", Opc.Ua.DataTypeIds.Double, ValueRanks.OneDimension);

                //create myDevice1/myVar2
                myvar2 = CreateVariable(mydev1, "myVar2", "myVar2", Opc.Ua.DataTypeIds.Int16, ValueRanks.Scalar);

                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                // Poject

                //create myDevice1/Start_Piece
                Start_Piece = CreateVariable(mydev1, "Start_Piece", "Start_Piece", Opc.Ua.DataTypeIds.Boolean, ValueRanks.Scalar);

                // create myDevice1/Mould_1
                Mould_1 = CreateVariable(mydev1, "Mould_1", "Mould_1", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                // create myDevice1/Mould_1_SN
                Mould_1_SN = CreateVariable(mydev1, "Mould_1_SN", "Mould_1_SN", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                // create myDevice1/Mould_2
                Mould_2 = CreateVariable(mydev1, "Mould_2", "Mould_2", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                // create myDevice1/Mould_2_SN
                Mould_2_SN = CreateVariable(mydev1, "Mould_2_SN", "Mould_2_SN", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                // create myDevice1/Piece_SN
                Piece_SN = CreateVariable(mydev1, "Piece_SN", "Piece_SN", Opc.Ua.DataTypeIds.Int32, ValueRanks.Scalar);

                // create myDevice1/Piece_SN
                Machine_SN = CreateVariable(mydev1, "Machine_SN", "Machine_SN", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                //create myDevice1/Change_Mould
                Change_Mould = CreateVariable(mydev1, "Change_Mould", "Change_Mould", Opc.Ua.DataTypeIds.Boolean, ValueRanks.Scalar);

                //create myDevice1/Mould_Changed
                Mould_Changed = CreateVariable(mydev1, "Mould_Changed", "Mould_Changed", Opc.Ua.DataTypeIds.Boolean, ValueRanks.Scalar);

                // create myDevice1/Actual_Mould
                Actual_Mould = CreateVariable(mydev1, "Actual_Mould", "Actual_Mould", Opc.Ua.DataTypeIds.Int32, ValueRanks.Scalar);

                // create myDevice1/Mould_tobeused
                Mould_tobeused = CreateVariable(mydev1, "Mould_tobeused", "Mould_tobeused", Opc.Ua.DataTypeIds.String, ValueRanks.Scalar);

                // create myDevice1/Operator_ID
                Operator_ID = CreateVariable(mydev1, "Operator_ID", "Operator_ID", Opc.Ua.DataTypeIds.Int32, ValueRanks.Scalar);

                // create myDevice1/Robot_Finished
                Robot_Finished = CreateVariable(mydev1, "Robot_Finished", "Robot_Finished", Opc.Ua.DataTypeIds.Boolean, ValueRanks.Scalar);

                //initialize var
                myvar1.Value         = (double)0.0;
                myvar2.Value         = (short)0;
                Actual_State.Value   = (double)0.0;
                Start_Piece.Value    = (bool)false;
                Mould_1.Value        = (string)"Mould 1";
                Mould_2.Value        = (string)"Mould 2";
                Mould_1_SN.Value     = (string)"1";
                Mould_2_SN.Value     = (string)"2";
                Piece_SN.Value       = (int)1;
                Machine_SN.Value     = (string)"1";
                Change_Mould.Value   = (bool)false;
                Robot_Finished.Value = (bool)true;
                Actual_Mould.Value   = (int)0;
                //Sensors_Data.Value = (int[])null;
                Mould_tobeused.Value = Mould_1_SN.Value;
                Mould_Changed.Value  = (bool)false;

                //store variable in my variable list for latter access (not necessary if variable is declare as a field of the class)
                m_dynamicNodes.Add(myvar1);
                m_dynamicNodes.Add(Actual_State);
                //add to Address Space
                AddPredefinedNode(SystemContext, mydev1);

                //-------------------------------------------------------------------------------------

                //Create a new object using the type "Device" defined by the DI specification
                //The class DeviceState is defined in the code generated by ModelCompiler
                myTemperatureSensor = new DeviceState(null);
                myTemperatureSensor.Create(SystemContext,
                                           null,
                                           new QualifiedName("myTemperatureSensor", m_namespaceIndex),
                                           null,
                                           true);

                //Object is created under DeviceSet
                DeviceSetobj.AddChild(myTemperatureSensor);

                //create a variable to hold the value of the temperature, of the type AnalogItem, under myTemperatureSensor
                TemperatureValue = new AnalogItemState(null);
                TemperatureValue.Create(SystemContext,
                                        null,
                                        new QualifiedName("Temperature", m_namespaceIndex),
                                        null,
                                        true);

                //Object is created under myTemperatureSensor
                myTemperatureSensor.AddChild(TemperatureValue);

                //initialize var
                TemperatureValue.Value = (double)0.0;

                //the type "Device" has a set of predefined info variables
                myTemperatureSensor.SerialNumber.Value = "AABB112233";
                myTemperatureSensor.Manufacturer.Value = "ACME";
                myTemperatureSensor.Model.Value        = new LocalizedText("PT", "MODEL 1.0");

                //add to Address Space
                AddPredefinedNode(SystemContext, myTemperatureSensor);


                //-------------------------------------------------------------------------------------
                //-------------------------------------------------------------------------------------

                //initialize Modbus client
                Modbus_client = new ModbusClient(Modbus_IP, Modbus_port);
                Modbus_client.ConnectionTimeout = 5000;

                // start periodic method to update my Address Space variables
                m_doprocessingTimer = new Timer(myDoProcessing, null, m_doprocessingInterval, m_doprocessingInterval);
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateDataItemVariable(NodeState parent, string path, string name, BuiltInType dataType, int valueRank)
        {
            DataItemState variable = new DataItemState(parent);
            variable.ValuePrecision = new PropertyState<double>(variable);
            variable.Definition = new PropertyState<string>(variable);

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;
            variable.DataType = (uint)dataType;
            variable.ValueRank = valueRank;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = Opc.Ua.TypeInfo.GetDefaultValue((uint)dataType, valueRank, Server.TypeTree);
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;

            variable.ValuePrecision.Value = 2;
            variable.ValuePrecision.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.ValuePrecision.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Definition.Value = String.Empty;
            variable.Definition.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Definition.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateMultiStateValueDiscreteItemVariable(NodeState parent, string path, string name, NodeId nodeId, params string[] enumNames)
        {
            MultiStateValueDiscreteState variable = new MultiStateValueDiscreteState(parent);

            variable.NodeId        = new NodeId(path, NamespaceIndex);
            variable.BrowseName    = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName   = new LocalizedText("en", name);
            variable.WriteMask     = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName    = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType        = (nodeId == null) ? DataTypeIds.UInt32 : nodeId;
            variable.ValueRank       = ValueRanks.Scalar;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;
            variable.Value           = (uint)0;
            variable.StatusCode      = StatusCodes.Good;
            variable.Timestamp       = DateTime.UtcNow;
            variable.OnWriteValue    = OnWriteValueDiscrete;

            // there are two enumerations for this type:
            // EnumStrings = the string representations for enumerated values
            // ValueAsText = the actual enumerated value

            // set the enumerated strings
            LocalizedText[] strings = new LocalizedText[enumNames.Length];
            for (int ii = 0; ii < strings.Length; ii++)
            {
                strings[ii] = enumNames[ii];
            }

            // set the enumerated values
            EnumValueType[] values = new EnumValueType[enumNames.Length];
            for (int ii = 0; ii < values.Length; ii++)
            {
                values[ii]             = new EnumValueType();
                values[ii].Value       = ii;
                values[ii].Description = strings[ii];
                values[ii].DisplayName = strings[ii];
            }
            variable.EnumValues.Value           = values;
            variable.EnumValues.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.EnumValues.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.ValueAsText.Value          = variable.EnumValues.Value[0].DisplayName;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Ejemplo n.º 25
0
        /// Creates a new variable.
        /// </summary>


        /// <summary>
        /// Creates a new variable.
        /// </summary>
        ///
        private BaseVariableState CreateVariableChild(NodeState parent, string path, string name, NodeId typeDefinitionId, NodeId dataType, int valueRank, AnalogData valueAnalog, String cityName)
        {
            if (cityName == null)
            {
                AnalogVariableState variable = new AnalogVariableState(parent);


                variable.SymbolicName     = name;
                variable.ReferenceTypeId  = ReferenceTypes.Organizes;
                variable.TypeDefinitionId = typeDefinitionId;
                variable.NodeId           = new NodeId(path, NamespaceIndex);
                variable.BrowseName       = new QualifiedName(path, NamespaceIndex);
                variable.DisplayName      = new LocalizedText("en", name);
                variable.WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
                variable.UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
                variable.Description      = new String("Information about weather for" + variable.SymbolicName.ToString());

                variable.DataType        = dataType;
                variable.ValueRank       = valueRank;
                variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
                variable.UserAccessLevel = AccessLevels.CurrentRead;
                variable.Historizing     = true;

                variable.Value = valueAnalog;


                if (variable.Value != null)
                {
                    variable.StatusCode = StatusCodes.Good;
                }
                else
                {
                    variable.StatusCode = StatusCodes.Bad;
                }
                variable.Timestamp = DateTime.UtcNow;

                if (valueRank == ValueRanks.OneDimension)
                {
                    variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                        0
                    });
                }
                else if (valueRank == ValueRanks.TwoDimensions)
                {
                    variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                        0, 0
                    });
                }

                if (parent != null)
                {
                    parent.AddChild(variable);
                }


                return(variable);
            }
            else
            {
                BaseVariableState variable = new BaseDataVariableState <String>(parent);

                variable.SymbolicName     = name;
                variable.ReferenceTypeId  = ReferenceTypes.Organizes;
                variable.TypeDefinitionId = Opc.Ua.VariableTypeIds.BaseVariableType;;
                variable.NodeId           = new NodeId(path, NamespaceIndex);
                variable.BrowseName       = new QualifiedName(path, NamespaceIndex);
                variable.DisplayName      = new LocalizedText("en", name);
                variable.WriteMask        = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
                variable.UserWriteMask    = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
                variable.Description      = new String("Information about weather for" + variable.SymbolicName.ToString());

                variable.DataType        = dataType;
                variable.ValueRank       = valueRank;
                variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
                variable.UserAccessLevel = AccessLevels.CurrentRead;
                variable.Historizing     = true;
                Console.WriteLine(cityName);
                variable.Value = cityName.ToString();


                if (variable.Value != null)
                {
                    variable.StatusCode = StatusCodes.Good;
                }
                else
                {
                    variable.StatusCode = StatusCodes.Bad;
                }
                variable.Timestamp = DateTime.UtcNow;

                if (valueRank == ValueRanks.OneDimension)
                {
                    variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                        0
                    });
                }
                else if (valueRank == ValueRanks.TwoDimensions)
                {
                    variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                        0, 0
                    });
                }

                if (parent != null)
                {
                    parent.AddChild(variable);
                }


                return(variable);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates a new object.
        /// </summary>
        private BaseObjectState CreateObject(NodeState parent, string path, string name)
        {
            BaseObjectState folder = new BaseObjectState(parent);

            folder.SymbolicName = name;
            folder.ReferenceTypeId = ReferenceTypes.Organizes;
            folder.TypeDefinitionId = ObjectTypeIds.BaseObjectType;
            folder.NodeId = new NodeId(path, NamespaceIndex);
            folder.BrowseName = new QualifiedName(name, NamespaceIndex);
            folder.DisplayName = folder.BrowseName.Name;
            folder.WriteMask = AttributeWriteMask.None;
            folder.UserWriteMask = AttributeWriteMask.None;
            folder.EventNotifier = EventNotifiers.None;

            if (parent != null)
            {
                parent.AddChild(folder);
            }

            return folder;
        }
Ejemplo n.º 27
0
        private AnalogItemState CreateAnalogItemVariable(NodeState parent, string path, string name, NodeId dataType)
        {
            int valueRank = ValueRanks.Scalar;
            var variable  = new AnalogItemState(parent);

            variable.BrowseName       = new QualifiedName(path, NamespaceIndex);
            variable.EngineeringUnits = new PropertyState <EUInformation>(variable);

            variable.InstrumentRange = new PropertyState <Opc.Ua.Range>(variable);

            variable.Create(
                SystemContext,
                new NodeId(path, NamespaceIndex),
                variable.BrowseName,
                null,
                true);

            variable.NodeId          = new NodeId(path, NamespaceIndex);
            variable.SymbolicName    = name;
            variable.DisplayName     = name;
            variable.WriteMask       = AttributeWriteMask.None;
            variable.UserWriteMask   = AttributeWriteMask.None;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType        = dataType;
            variable.ValueRank       = valueRank;
            variable.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing     = false;

            variable.OnReadUserRolePermissions = OnReadUserRolePermissions;

            if (valueRank == ValueRanks.OneDimension)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0
                });
            }
            else if (valueRank == ValueRanks.TwoDimensions)
            {
                variable.ArrayDimensions = new ReadOnlyList <uint>(new List <uint> {
                    0, 0
                });
            }

            BuiltInType builtInType = Opc.Ua.TypeInfo.GetBuiltInType(dataType, Server.TypeTree);

            // Using anything but 120,-10 fails a few tests
            variable.InstrumentRange.Value = GetAnalogRange(builtInType);;

            variable.EURange.Value = new Opc.Ua.Range(100, 0);
            variable.Value         = Opc.Ua.TypeInfo.GetDefaultValue(dataType, valueRank, Server.TypeTree);

            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp  = DateTime.UtcNow;
            // The latest UNECE version (Rev 11, published in 2015) is available here:
            // http://www.opcfoundation.org/UA/EngineeringUnits/UNECE/rec20_latest_08052015.zip
            variable.EngineeringUnits.Value = new EUInformation("mV", "millivolt", "http://www.opcfoundation.org/UA/units/un/cefact");
            // The mapping of the UNECE codes to OPC UA(EUInformation.unitId) is available here:
            // http://www.opcfoundation.org/UA/EngineeringUnits/UNECE/UNECE_to_OPCUA.csv
            variable.EngineeringUnits.Value.UnitId = 12890; // "2Z"
            variable.OnWriteValue                     = OnWriteAnalog;
            variable.EURange.OnWriteValue             = OnWriteAnalogRange;
            variable.EURange.AccessLevel              = AccessLevels.CurrentReadOrWrite;
            variable.EURange.UserAccessLevel          = AccessLevels.CurrentReadOrWrite;
            variable.EngineeringUnits.AccessLevel     = AccessLevels.CurrentReadOrWrite;
            variable.EngineeringUnits.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.InstrumentRange.OnWriteValue     = OnWriteAnalogRange;
            variable.InstrumentRange.AccessLevel      = AccessLevels.CurrentReadOrWrite;
            variable.InstrumentRange.UserAccessLevel  = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return(variable);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Creates a new method.
        /// </summary>
        private MethodState CreateMethod(NodeState parent, string path, string name)
        {
            MethodState method = new MethodState(parent);

            method.SymbolicName = name;
            method.ReferenceTypeId = ReferenceTypeIds.HasComponent;
            method.NodeId = new NodeId(path, NamespaceIndex);
            method.BrowseName = new QualifiedName(path, NamespaceIndex);
            method.DisplayName = new LocalizedText("en", name);
            method.WriteMask = AttributeWriteMask.None;
            method.UserWriteMask = AttributeWriteMask.None;
            method.Executable = true;
            method.UserExecutable = true;

            if (parent != null)
            {
                parent.AddChild(method);
            }

            return method;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private BaseDataVariableState CreateVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank)
        {
            BaseDataVariableState variable = new BaseDataVariableState(parent);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
            variable.DataType = dataType;
            variable.ValueRank = valueRank;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = GetNewValue(variable);
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateMultiStateValueDiscreteItemVariable(NodeState parent, string path, string name, params string[] enumNames)
        {
            MultiStateValueDiscreteState variable = new MultiStateValueDiscreteState(parent);

            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType = DataTypeIds.UInt32;
            variable.ValueRank = ValueRanks.Scalar;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = (uint)0;
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;
            // variable.OnWriteValue = OnWriteDiscrete;

            // there are two enumerations for this type:
            // EnumStrings = the string representations for enumerated values
            // EnumValues  = the actual enumerated value

            // set the enumerated strings
            LocalizedText[] strings = new LocalizedText[enumNames.Length];
            for (int ii = 0; ii < strings.Length; ii++)
            {
                strings[ii] = enumNames[ii];
            }

            //variable.EnumStrings = new PropertyState<LocalizedText[]>( variable );
            //variable.EnumStrings.Value = strings;
            //variable.EnumStrings.AccessLevel = AccessLevels.CurrentReadOrWrite;
            //variable.EnumStrings.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            // set the enumerated values
            EnumValueType[] values = new EnumValueType[enumNames.Length];
            for (int ii = 0; ii < values.Length; ii++)
            {
                values[ii] = new EnumValueType();
                values[ii].Value = ii;
                values[ii].Description = strings[ii];
                values[ii].DisplayName = strings[ii];
            }
            variable.EnumValues.Value = values;
            variable.EnumValues.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.EnumValues.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.ValueAsText.Value = strings[0];

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 31
0
        public MethodState CreateAddMethodState(
            NodeState parent, AasUaBaseEntity.CreateMode mode,
            string browseDisplayName,
            Argument[] inputArgs       = null, Argument[] outputArgs = null, NodeId referenceTypeFromParentId = null,
            NodeId methodDeclarationId = null, GenericMethodCalledEventHandler onCalled = null)
        {
            // method node
            var m = new MethodState(parent);

            m.BrowseName  = "" + browseDisplayName;
            m.DisplayName = "" + browseDisplayName;
            m.Description = new LocalizedText("en", browseDisplayName);
            m.NodeId      = nodeMgr.New(nodeMgr.SystemContext, mode, m);
            if (methodDeclarationId != null)
            {
                m.MethodDeclarationId = methodDeclarationId;
            }

            m.Executable     = true;
            m.UserExecutable = true;

            nodeMgr.AddPredefinedNode(nodeMgr.SystemContext, m);
            if (parent != null)
            {
                parent.AddChild(m);
            }

            if (referenceTypeFromParentId != null)
            {
                if (parent != null)
                {
                    parent.AddReference(referenceTypeFromParentId, false, m.NodeId);
                    if (referenceTypeFromParentId == ReferenceTypeIds.HasComponent)
                    {
                        m.AddReference(referenceTypeFromParentId, true, parent.NodeId);
                    }
                    if (referenceTypeFromParentId == ReferenceTypeIds.HasProperty)
                    {
                        m.AddReference(referenceTypeFromParentId, true, parent.NodeId);
                    }
                }
            }

            // can have inputs, outputs
            for (int i = 0; i < 2; i++)
            {
                // pretty argument list
                var arguments = (i == 0) ? inputArgs : outputArgs;
                if (arguments == null || arguments.Length < 1)
                {
                    continue;
                }

                // make a property for this
                var prop = CreateAddPropertyState <Argument[]>(
                    m, mode,
                    (i == 0) ? "InputArguments" : "OutputArguments",
                    DataTypeIds.Argument,
                    arguments,
                    ReferenceTypeIds.HasProperty,
                    typeDefinitionId: VariableTypeIds.PropertyType,
                    valueRank: 1);

                // explicitely add arguments ass well?
                if (i == 0)
                {
                    m.InputArguments = prop;
                }

                if (i == 1)
                {
                    m.OutputArguments = prop;
                }
            }

            // event handler
            if (onCalled != null)
            {
                m.OnCallMethod = onCalled;
            }


            return(m);
        }
Ejemplo n.º 32
0
        private DataItemState CreateAnalogItemVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank, object initialValues, Range customRange)
        {
            AnalogItemState variable = new AnalogItemState(parent);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.EngineeringUnits = new PropertyState<EUInformation>(variable);
            variable.InstrumentRange = new PropertyState<Range>(variable);

            variable.Create(
                SystemContext,
                new NodeId(path, NamespaceIndex),
                variable.BrowseName,
                null,
                true);

            variable.NodeId = new NodeId(path, NamespaceIndex);            
            variable.SymbolicName = name;
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;            
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType = dataType;
            variable.ValueRank = valueRank;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            

            if (customRange != null)
            {
                variable.EURange.Value = customRange;
            }
            else
            {
                variable.EURange.Value = new Range(100, 0);
            }

            variable.InstrumentRange.Value = new Range(120, -10);
            if (initialValues == null)
            {
                variable.Value = Opc.Ua.TypeInfo.GetDefaultValue(dataType, valueRank, Server.TypeTree);
            }
            else
            {
                variable.Value = initialValues;
            }

            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;
            variable.EngineeringUnits.Value = new EUInformation("liters", Namespaces.ReferenceApplications);
            variable.OnWriteValue = OnWriteAnalog;
            variable.EURange.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.EURange.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.EngineeringUnits.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.EngineeringUnits.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.InstrumentRange.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.InstrumentRange.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateTwoStateDiscreteItemVariable(NodeState parent, string path, string name, string trueState, string falseState)
        {
            TwoStateDiscreteState variable = new TwoStateDiscreteState(parent);

            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType = DataTypeIds.Boolean;
            variable.ValueRank = ValueRanks.Scalar;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = (bool)GetNewValue(variable);
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;

            variable.TrueState.Value = trueState;
            variable.TrueState.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.TrueState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            variable.FalseState.Value = falseState;
            variable.FalseState.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.FalseState.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Creates a new variable.
        /// </summary>
        private DataItemState CreateMultiStateDiscreteItemVariable(NodeState parent, string path, string name, params string[] values)
        {
            MultiStateDiscreteState variable = new MultiStateDiscreteState(parent);

            variable.NodeId = new NodeId(path, NamespaceIndex);
            variable.BrowseName = new QualifiedName(path, NamespaceIndex);
            variable.DisplayName = new LocalizedText("en", name);
            variable.WriteMask = AttributeWriteMask.None;
            variable.UserWriteMask = AttributeWriteMask.None;

            variable.Create(
                SystemContext,
                null,
                variable.BrowseName,
                null,
                true);

            variable.SymbolicName = name;
            variable.ReferenceTypeId = ReferenceTypes.Organizes;
            variable.DataType = DataTypeIds.UInt32;
            variable.ValueRank = ValueRanks.Scalar;
            variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.Historizing = false;
            variable.Value = (uint)0;
            variable.StatusCode = StatusCodes.Good;
            variable.Timestamp = DateTime.UtcNow;
            // variable.OnWriteValue = OnWriteDiscrete;

            LocalizedText[] strings = new LocalizedText[values.Length];

            for (int ii = 0; ii < strings.Length; ii++)
            {
                strings[ii] = values[ii];
            }

            variable.EnumStrings.Value = strings;
            variable.EnumStrings.AccessLevel = AccessLevels.CurrentReadOrWrite;
            variable.EnumStrings.UserAccessLevel = AccessLevels.CurrentReadOrWrite;

            if (parent != null)
            {
                parent.AddChild(variable);
            }

            return variable;
        }
Ejemplo n.º 35
0
        /// <summary>
        /// Creates items from embedded resources.
        /// </summary>
        private void CreateFolderFromResources(NodeState root, string folderName)
        {
            FolderState dataFolder = new FolderState(root);
            dataFolder.ReferenceTypeId = ReferenceTypeIds.Organizes;
            dataFolder.TypeDefinitionId = ObjectTypeIds.FolderType;
            dataFolder.NodeId = new NodeId(folderName, NamespaceIndex);
            dataFolder.BrowseName = new QualifiedName(folderName, NamespaceIndex);
            dataFolder.DisplayName = dataFolder.BrowseName.Name;
            dataFolder.WriteMask = AttributeWriteMask.None;
            dataFolder.UserWriteMask = AttributeWriteMask.None;
            dataFolder.EventNotifier = EventNotifiers.None;
            root.AddChild(dataFolder);
            AddPredefinedNode(SystemContext, root);

            foreach (string resourcePath in Assembly.GetExecutingAssembly().GetManifestResourceNames())
            {
                if (!resourcePath.StartsWith("Quickstarts.HistoricalAccessServer.Data." + folderName))
                {
                    continue;
                }

                ArchiveItem item = new ArchiveItem(resourcePath, Assembly.GetExecutingAssembly(), resourcePath);
                ArchiveItemState node = new ArchiveItemState(SystemContext, item, NamespaceIndex);
                node.ReloadFromSource(SystemContext);

                dataFolder.AddReference(ReferenceTypeIds.Organizes, false, node.NodeId);
                node.AddReference(ReferenceTypeIds.Organizes, true, dataFolder.NodeId);

                AddPredefinedNode(SystemContext, node);
            }
        }