/// <summary>
        /// Initializes the node manager.
        /// </summary>
        public TestDataNodeManager(Opc.Ua.Server.IServerInternal server, ApplicationConfiguration configuration)
        :
            base(server, configuration)
        {
            // update the namespaces.
            List<string> namespaceUris = new List<string>();

            namespaceUris.Add(Namespaces.TestData);
            namespaceUris.Add(Namespaces.TestData + "/Instance");

            NamespaceUris = namespaceUris;

            // get the configuration for the node manager.
            m_configuration = configuration.ParseExtension<TestDataNodeManagerConfiguration>();

            // use suitable defaults if no configuration exists.
            if (m_configuration == null)
            {
                m_configuration = new TestDataNodeManagerConfiguration();
            }

            m_lastUsedId = m_configuration.NextUnusedId-1;

            // create the object used to access the test system.
            m_system = new TestDataSystem(this, server.NamespaceUris, server.ServerUris);

            // update the default context.
            SystemContext.SystemHandle = m_system;
        }
예제 #2
0
        /// <summary>
        /// Handles the generate values method.
        /// </summary>
        protected override ServiceResult OnGenerateValues(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            uint count)
        {
            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system == null)
            {
                return(StatusCodes.BadOutOfService);
            }

            GenerateValue(system, SByteValue);
            GenerateValue(system, ByteValue);
            GenerateValue(system, Int16Value);
            GenerateValue(system, UInt16Value);
            GenerateValue(system, Int32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, Int64Value);
            GenerateValue(system, UInt64Value);
            GenerateValue(system, FloatValue);
            GenerateValue(system, DoubleValue);
            GenerateValue(system, NumberValue);
            GenerateValue(system, IntegerValue);
            GenerateValue(system, UIntegerValue);

            return(base.OnGenerateValues(context, method, objectId, count));
        }
예제 #3
0
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public TestDataNodeManager(IServerInternal server, ApplicationConfiguration configuration)
            :
            base(server, configuration)
        {
            // update the namespaces.
            var namespaceUris = new List <string> {
                Namespaces.TestData,
                Namespaces.TestData + "/Instance"
            };

            NamespaceUris = namespaceUris;

            // get the configuration for the node manager.
            _configuration = configuration.ParseExtension <TestDataNodeManagerConfiguration>();

            // use suitable defaults if no configuration exists.
            if (_configuration == null)
            {
                _configuration = new TestDataNodeManagerConfiguration();
            }

            _lastUsedId = _configuration.NextUnusedId - 1;

            // create the object used to access the test system.
            _system = new TestDataSystem(this, server.NamespaceUris, server.ServerUris);

            // update the default context.
            SystemContext.SystemHandle = _system;
        }
예제 #4
0
        /// <summary>
        /// Initializes the node manager.
        /// </summary>
        public TestDataNodeManager(Opc.Ua.Server.IServerInternal server, ApplicationConfiguration configuration)
            :
            base(server, configuration)
        {
            // update the namespaces.
            List <string> namespaceUris = new List <string>();

            namespaceUris.Add(Namespaces.TestData);
            namespaceUris.Add(Namespaces.TestData + "Instance");

            NamespaceUris = namespaceUris;

            Server.Factory.AddEncodeableTypes(typeof(TestDataNodeManager).Assembly.GetExportedTypes().Where(t => t.FullName.StartsWith(typeof(TestDataNodeManager).Namespace)));

            // get the configuration for the node manager.
            m_configuration = configuration.ParseExtension <TestDataNodeManagerConfiguration>();

            // use suitable defaults if no configuration exists.
            if (m_configuration == null)
            {
                m_configuration = new TestDataNodeManagerConfiguration();
            }

            m_lastUsedId = m_configuration.NextUnusedId - 1;

            // create the object used to access the test system.
            m_system = new TestDataSystem(this, server.NamespaceUris, server.ServerUris);

            // update the default context.
            SystemContext.SystemHandle = m_system;
        }
예제 #5
0
        /// <summary>
        /// Generates a new value each time the value is read.
        /// </summary>
        private ServiceResult DoDeviceRead(
            ISystemContext context,
            NodeState node,
            NumericRange indexRange,
            QualifiedName dataEncoding,
            ref object value,
            ref StatusCode statusCode,
            ref DateTime timestamp)
        {
            BaseVariableState variable = node as BaseVariableState;

            if (variable == null)
            {
                return(ServiceResult.Good);
            }

            if (!SimulationActive.Value)
            {
                return(ServiceResult.Good);
            }

            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system == null)
            {
                return(StatusCodes.BadOutOfService);
            }

            try
            {
                value = system.ReadValue(variable);

                statusCode = StatusCodes.Good;
                timestamp  = DateTime.UtcNow;

                ServiceResult error = BaseVariableState.ApplyIndexRangeAndDataEncoding(
                    context,
                    indexRange,
                    dataEncoding,
                    ref value);

                if (ServiceResult.IsBad(error))
                {
                    statusCode = error.StatusCode;
                }

                return(ServiceResult.Good);
            }
            catch (Exception e)
            {
                return(new ServiceResult(e));
            }
        }
예제 #6
0
        /// <summary>
        /// Reads the value for the MonitoredNodeCount.
        /// </summary>
        protected virtual ServiceResult OnReadMonitoredNodeCount(
            ISystemContext context,
            NodeState node,
            ref object value)
        {
            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system == null)
            {
                return(StatusCodes.BadOutOfService);
            }

            value = system.MonitoredNodeCount;
            return(ServiceResult.Good);
        }
예제 #7
0
        /// <summary>
        /// Handles the generate values method.
        /// </summary>
        protected override ServiceResult OnGenerateValues(
            ISystemContext context,
            MethodState method,
            NodeId objectId,
            uint count)
        {
            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system == null)
            {
                return(StatusCodes.BadOutOfService);
            }

            GenerateValue(system, BooleanValue);
            GenerateValue(system, SByteValue);
            GenerateValue(system, ByteValue);
            GenerateValue(system, Int16Value);
            GenerateValue(system, UInt16Value);
            GenerateValue(system, Int32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, UInt32Value);
            GenerateValue(system, Int64Value);
            GenerateValue(system, UInt64Value);
            GenerateValue(system, FloatValue);
            GenerateValue(system, DoubleValue);
            GenerateValue(system, StringValue);
            GenerateValue(system, DateTimeValue);
            GenerateValue(system, GuidValue);
            GenerateValue(system, ByteStringValue);
            GenerateValue(system, XmlElementValue);
            GenerateValue(system, NodeIdValue);
            GenerateValue(system, ExpandedNodeIdValue);
            GenerateValue(system, QualifiedNameValue);
            GenerateValue(system, LocalizedTextValue);
            GenerateValue(system, StatusCodeValue);
            GenerateValue(system, VariantValue);
            GenerateValue(system, EnumerationValue);
            GenerateValue(system, StructureValue);
            GenerateValue(system, NumberValue);
            GenerateValue(system, IntegerValue);
            GenerateValue(system, UIntegerValue);

            return(base.OnGenerateValues(context, method, objectId, count));
        }
예제 #8
0
        /// <summary>
        /// Initialzies the variable as a counter.
        /// </summary>
        protected void InitializeVariable(ISystemContext context, BaseVariableState variable, uint numericId)
        {
            variable.NumericId = numericId;

            // provide an implementation that produces a random value on each read.
            if (SimulationActive.Value)
            {
                variable.OnReadValue = DoDeviceRead;
            }

            // set a valid initial value.
            TestDataSystem system = context.SystemHandle as TestDataSystem;

            if (system != null)
            {
                GenerateValue(system, variable);
            }

            // allow writes if the simulation is not active.
            if (!SimulationActive.Value)
            {
                variable.AccessLevel = variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
            }

            // set the EU range.
            BaseVariableState euRange = variable.FindChild(context, Opc.Ua.BrowseNames.EURange) as BaseVariableState;

            if (euRange != null)
            {
                if (context.TypeTable.IsTypeOf(variable.DataType, Opc.Ua.DataTypeIds.UInteger))
                {
                    euRange.Value = new Range(250, 50);
                }
                else
                {
                    euRange.Value = new Range(100, -100);
                }
            }

            variable.OnSimpleWriteValue = OnWriteAnalogValue;
        }
 /// <summary>
 /// Generates a new value for the variable.
 /// </summary>
 protected void GenerateValue(TestDataSystem system, BaseVariableState variable)
 {
     variable.Value      = system.ReadValue(variable);
     variable.Timestamp  = DateTime.UtcNow;
     variable.StatusCode = StatusCodes.Good;
 }
예제 #10
0
 /// <summary>
 /// Generates a new value for the variable.
 /// </summary>
 protected void GenerateValue(TestDataSystem system, BaseVariableState variable)
 {
     variable.Value = system.ReadValue(variable);
     variable.Timestamp = DateTime.UtcNow;
     variable.StatusCode = StatusCodes.Good;
 }