private ServiceResult OnWriteDataItem(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            DataItemState variable = node as DataItemState;

            // verify data type.
            Opc.Ua.TypeInfo typeInfo = Opc.Ua.TypeInfo.IsInstanceOfDataType(
                value,
                variable.DataType,
                variable.ValueRank,
                context.NamespaceUris,
                context.TypeTable);

            if (typeInfo == null || typeInfo == Opc.Ua.TypeInfo.Unknown)
            {
                return(StatusCodes.BadTypeMismatch);
            }

            if (typeInfo.BuiltInType != BuiltInType.DateTime)
            {
                double number = Convert.ToDouble(value);
                number = Math.Round(number, (int)variable.ValuePrecision.Value);
                value  = Opc.Ua.TypeInfo.Cast(number, typeInfo.BuiltInType);
            }

            return(ServiceResult.Good);
        }
示例#2
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;

            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);
        }
示例#3
0
        /// <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)
            {
                IList <IReference> references = null;

                if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
                {
                    externalReferences[ObjectIds.ObjectsFolder] = references = new List <IReference>();
                }

                FolderState root = CreateFolder(null, "OpcPublisher", "OpcPublisher");
                root.AddReference(ReferenceTypes.Organizes, true, ObjectIds.ObjectsFolder);
                references.Add(new NodeStateReference(ReferenceTypes.Organizes, false, root.NodeId));
                root.EventNotifier = EventNotifiers.SubscribeToEvents;
                AddRootNotifier(root);

                List <BaseDataVariableState> variables = new List <BaseDataVariableState>();

                try
                {
                    #region DataAccess_DataItem
                    FolderState dataFolder = CreateFolder(root, "Data", "Data");

                    const string  connectionStringItemName = "ConnectionString";
                    DataItemState item = CreateDataItemVariable(dataFolder, connectionStringItemName, connectionStringItemName, BuiltInType.String, ValueRanks.Scalar, AccessLevels.CurrentWrite);
                    item.Value = String.Empty;
                    #endregion

                    #region Methods
                    FolderState methodsFolder = CreateFolder(root, "Methods", "Methods");

                    #region PublishNode Method
                    MethodState publishNodeMethod = CreateMethod(methodsFolder, "PublishNode", "PublishNode");
                    SetPublishNodeMethodProperties(ref publishNodeMethod);
                    #endregion

                    #region UnpublishNode Method
                    MethodState unpublishNodeMethod = CreateMethod(methodsFolder, "UnpublishNode", "UnpublishNode");
                    SetUnpublishNodeMethodProperties(ref unpublishNodeMethod);
                    #endregion

                    #region GetListOfPublishedNodes Method
                    MethodState getListOfPublishedNodesMethod = CreateMethod(methodsFolder, "GetListOfPublishedNodes", "GetListOfPublishedNodes");
                    SetGetListOfPublishedNodesMethodProperties(ref getListOfPublishedNodesMethod);
                    #endregion

                    #endregion Methods
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Error creating the address space.");
                }

                AddPredefinedNode(SystemContext, root);
            }
        }
示例#4
0
        public int SecItemUpdateState(int id, DataItemState state)
        {
            if (this._conString == null)
            {
                throw new MissingFieldException("SQLiteConnectionString");
            }

            using (var db = new SQLiteConnection(this._conString)) {
                var querySecItem = db.Table <SecItem>().Where(
                    secItem => secItem.Id == id);

                foreach (var secItem in querySecItem)
                {
                    secItem.State   = (int)state;
                    secItem.Updated = DateTime.UtcNow;

                    return(db.Update(secItem));
                }
            }

            return(0);
        }
示例#5
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case FileSystem.BrowseNames.GasFlow:
                {
                    if (createOrReplace)
                    {
                        if (GasFlow == null)
                        {
                            if (replacement == null)
                            {
                                GasFlow = new DataItemState<double>(this);
                            }
                            else
                            {
                                GasFlow = (DataItemState<double>)replacement;
                            }
                        }
                    }

                    instance = GasFlow;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }
示例#6
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return null;
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
                case FileSystem.BrowseNames.Temperature:
                {
                    if (createOrReplace)
                    {
                        if (Temperature == null)
                        {
                            if (replacement == null)
                            {
                                Temperature = new AnalogItemState<double>(this);
                            }
                            else
                            {
                                Temperature = (AnalogItemState<double>)replacement;
                            }
                        }
                    }

                    instance = Temperature;
                    break;
                }

                case FileSystem.BrowseNames.TemperatureSetPoint:
                {
                    if (createOrReplace)
                    {
                        if (TemperatureSetPoint == null)
                        {
                            if (replacement == null)
                            {
                                TemperatureSetPoint = new AnalogItemState<double>(this);
                            }
                            else
                            {
                                TemperatureSetPoint = (AnalogItemState<double>)replacement;
                            }
                        }
                    }

                    instance = TemperatureSetPoint;
                    break;
                }

                case FileSystem.BrowseNames.State:
                {
                    if (createOrReplace)
                    {
                        if (State == null)
                        {
                            if (replacement == null)
                            {
                                State = new BaseDataVariableState<int>(this);
                            }
                            else
                            {
                                State = (BaseDataVariableState<int>)replacement;
                            }
                        }
                    }

                    instance = State;
                    break;
                }

                case FileSystem.BrowseNames.PowerConsumption:
                {
                    if (createOrReplace)
                    {
                        if (PowerConsumption == null)
                        {
                            if (replacement == null)
                            {
                                PowerConsumption = new DataItemState<double>(this);
                            }
                            else
                            {
                                PowerConsumption = (DataItemState<double>)replacement;
                            }
                        }
                    }

                    instance = PowerConsumption;
                    break;
                }

                case FileSystem.BrowseNames.Start:
                {
                    if (createOrReplace)
                    {
                        if (Start == null)
                        {
                            if (replacement == null)
                            {
                                Start = new MethodState(this);
                            }
                            else
                            {
                                Start = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Start;
                    break;
                }

                case FileSystem.BrowseNames.Stop:
                {
                    if (createOrReplace)
                    {
                        if (Stop == null)
                        {
                            if (replacement == null)
                            {
                                Stop = new MethodState(this);
                            }
                            else
                            {
                                Stop = (MethodState)replacement;
                            }
                        }
                    }

                    instance = Stop;
                    break;
                }
            }

            if (instance != null)
            {
                return instance;
            }

            return base.FindChild(context, browseName, createOrReplace, replacement);
        }
示例#7
0
        /// <summary>
        /// Creates a variable from a tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <returns>The variable that represents the tag.</returns>
        private BaseVariableState CreateVariable(ISystemContext context, UnderlyingSystemTag tag)
        {
            // create the variable type based on the tag type.
            BaseDataVariableState variable = null;

            switch (tag.TagType)
            {
            case UnderlyingSystemTagType.Analog:
            {
                AnalogItemState node = new AnalogItemState(this);

                if (tag.EngineeringUnits != null)
                {
                    node.EngineeringUnits = new PropertyState <EUInformation>(node);
                }

                if (tag.EuRange.Length >= 4)
                {
                    node.InstrumentRange = new PropertyState <Range>(node);
                }

                variable = node;
                break;
            }

            case UnderlyingSystemTagType.Digital:
            {
                TwoStateDiscreteState node = new TwoStateDiscreteState(this);
                variable = node;
                break;
            }

            case UnderlyingSystemTagType.Enumerated:
            {
                MultiStateDiscreteState node = new MultiStateDiscreteState(this);

                if (tag.Labels != null)
                {
                    node.EnumStrings = new PropertyState <LocalizedText[]>(node);
                }

                variable = node;
                break;
            }

            default:
            {
                DataItemState node = new DataItemState(this);
                variable = node;
                break;
            }
            }

            // set the symbolic name and reference types.
            variable.SymbolicName    = tag.Name;
            variable.ReferenceTypeId = ReferenceTypeIds.HasComponent;

            // initialize the variable from the type model.
            variable.Create(
                context,
                null,
                new QualifiedName(tag.Name, this.BrowseName.NamespaceIndex),
                null,
                true);

            // update the variable values.
            UpdateVariable(context, tag, variable);

            return(variable);
        }
示例#8
0
        /// <summary>
        /// Finds the child with the specified browse name.
        /// </summary>
        /// <param name="context">The system context.</param>
        /// <param name="browseName">The browse name.</param>
        /// <param name="createOrReplace">A flag that specifies the action: to create or to replace.</param>
        /// <param name="replacement">The replacement.</param>
        /// <returns>The instance state found; or NULL otherwise.</returns>
        protected override BaseInstanceState FindChild(
            ISystemContext context,
            QualifiedName browseName,
            bool createOrReplace,
            BaseInstanceState replacement)
        {
            if (QualifiedName.IsNull(browseName))
            {
                return(null);
            }

            BaseInstanceState instance = null;

            switch (browseName.Name)
            {
            case ITG3200.BrowseNames.GyroX:
            {
                if (createOrReplace)
                {
                    if (GyroX == null)
                    {
                        if (replacement == null)
                        {
                            GyroX = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            GyroX = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = GyroX;
                break;
            }

            case ITG3200.BrowseNames.GyroY:
            {
                if (createOrReplace)
                {
                    if (GyroY == null)
                    {
                        if (replacement == null)
                        {
                            GyroY = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            GyroY = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = GyroY;
                break;
            }

            case ITG3200.BrowseNames.GyroZ:
            {
                if (createOrReplace)
                {
                    if (GyroZ == null)
                    {
                        if (replacement == null)
                        {
                            GyroZ = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            GyroZ = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = GyroZ;
                break;
            }

            case ITG3200.BrowseNames.Temperature:
            {
                if (createOrReplace)
                {
                    if (Temperature == null)
                    {
                        if (replacement == null)
                        {
                            Temperature = new AnalogItemState <double>(this);
                        }
                        else
                        {
                            Temperature = (AnalogItemState <double>)replacement;
                        }
                    }
                }

                instance = Temperature;
                break;
            }

            case ITG3200.BrowseNames.Online:
            {
                if (createOrReplace)
                {
                    if (Online == null)
                    {
                        if (replacement == null)
                        {
                            Online = new DataItemState <bool>(this);
                        }
                        else
                        {
                            Online = (DataItemState <bool>)replacement;
                        }
                    }
                }

                instance = Online;
                break;
            }
            }

            if (instance != null)
            {
                return(instance);
            }

            return(base.FindChild(context, browseName, createOrReplace, replacement));
        }
示例#9
0
        /// <summary>
        /// Creates a variable from a tag.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="tag">The tag.</param>
        /// <returns>The variable that represents the tag.</returns>
        private BaseVariableState CreateVariable(ISystemContext context, UnderlyingSystemTag tag)
        {
            // create the variable type based on the tag type.
            BaseDataVariableState variable = null;

            switch (tag.TagType)
            {
                case UnderlyingSystemTagType.Analog:
                {
                    AnalogItemState node = new AnalogItemState(this);

                    if (tag.EngineeringUnits != null)
                    {
                        node.EngineeringUnits = new PropertyState<EUInformation>(node);
                    }

                    if (tag.EuRange.Length >= 4)
                    {
                        node.InstrumentRange = new PropertyState<Range>(node);
                    }

                    variable = node;
                    break;
                }

                case UnderlyingSystemTagType.Digital:
                {
                    TwoStateDiscreteState node = new TwoStateDiscreteState(this);
                    variable = node;
                    break;
                }

                case UnderlyingSystemTagType.Enumerated:
                {
                    MultiStateDiscreteState node = new MultiStateDiscreteState(this);

                    if (tag.Labels != null)
                    {
                        node.EnumStrings = new PropertyState<LocalizedText[]>(node);
                    }

                    variable = node;
                    break;
                }

                default:
                {
                    DataItemState node = new DataItemState(this);
                    variable = node;
                    break;
                }
            }

            // set the symbolic name and reference types.
            variable.SymbolicName = tag.Name;
            variable.ReferenceTypeId = ReferenceTypeIds.HasComponent;

            // initialize the variable from the type model.
            variable.Create(
                context,
                null,
                new QualifiedName(tag.Name, this.BrowseName.NamespaceIndex),
                null,
                true);

            // update the variable values.
            UpdateVariable(context, tag, variable);
            
            return variable;
        }
示例#10
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;
        }