コード例 #1
0
 public TestDataSystem(ITestDataSystemCallback callback, NamespaceTable namespaceUris, StringTable serverUris)
 {
     m_callback = callback;
     m_minimumSamplingInterval = Int32.MaxValue;
     m_monitoredNodes          = new Dictionary <uint, BaseVariableState>();
     m_generator = new Opc.Ua.Test.DataGenerator(null);
     m_generator.NamespaceUris = namespaceUris;
     m_generator.ServerUris    = serverUris;
     m_historyArchive          = new HistoryArchive();
 }
コード例 #2
0
 public TestDataSystem(ITestDataSystemCallback callback, NamespaceTable namespaceUris, StringTable serverUris)
 {
     m_callback = callback;
     m_minimumSamplingInterval = Int32.MaxValue;
     m_monitoredNodes = new Dictionary<uint,BaseVariableState>();
     m_generator = new Opc.Ua.Test.DataGenerator(null);
     m_generator.NamespaceUris = namespaceUris;
     m_generator.ServerUris = serverUris;
     m_historyArchive = new HistoryArchive();
 }
コード例 #3
0
        /// <summary>
        /// Starts a simulation which causes the tag states to change.
        /// </summary>
        /// <remarks>
        /// This simulation randomly activates the tags that belong to the blocks.
        /// Once an tag is active it has to be acknowledged and confirmed.
        /// Once an tag is confirmed it go to the inactive state.
        /// If the tag stays active the severity will be gradually increased.
        /// </remarks>
        public void StartSimulation()
        {
            lock (_lock) {
                if (_simulationTimer != null)
                {
                    _simulationTimer.Dispose();
                    _simulationTimer = null;
                }

                _generator       = new Opc.Ua.Test.DataGenerator(null);
                _simulationTimer = new Timer(DoSimulation, null, 1000, 1000);
            }
        }
コード例 #4
0
        /// <summary>
        /// Simulates a block by updating the state of the tags belonging to the condition.
        /// </summary>
        /// <param name="counter">The number of simulation cycles that have elapsed.</param>
        /// <param name="index">The index of the block within the system.</param>
        /// <param name="generator">An object which generates random data.</param>
        public void DoSimulation(long counter, int index, Opc.Ua.Test.DataGenerator generator)
        {
            try
            {
                TagsChangedEventHandler    onTagsChanged = null;
                List <UnderlyingSystemTag> snapshots     = new List <UnderlyingSystemTag>();

                // update the tags.
                lock (m_tags)
                {
                    onTagsChanged = OnTagsChanged;

                    // do nothing if not monitored.
                    if (onTagsChanged == null)
                    {
                        return;
                    }

                    for (int ii = 0; ii < m_tags.Count; ii++)
                    {
                        UnderlyingSystemTag tag = m_tags[ii];
                        UpdateTagValue(tag, generator);

                        DataValue value = new DataValue();

                        value.Value           = tag.Value;
                        value.StatusCode      = StatusCodes.Good;
                        value.SourceTimestamp = tag.Timestamp;

                        if (counter % (8 + (index % 4)) == 0)
                        {
                            UpdateTagMetadata(tag, generator);
                        }

                        snapshots.Add(tag.CreateSnapshot());
                    }
                }

                // report any tag changes after releasing the lock.
                if (onTagsChanged != null)
                {
                    onTagsChanged(snapshots);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error running simulation for block {0}", m_name);
            }
        }
コード例 #5
0
        /// <summary>
        /// Updates the metadata for a tag.
        /// </summary>
        private bool UpdateTagMetadata(
            UnderlyingSystemTag tag,
            Opc.Ua.Test.DataGenerator generator)
        {
            switch (tag.TagType)
            {
            case UnderlyingSystemTagType.Analog:
            {
                if (tag.EuRange != null)
                {
                    double[] range = new double[tag.EuRange.Length];

                    for (int ii = 0; ii < tag.EuRange.Length; ii++)
                    {
                        range[ii] = tag.EuRange[ii] + 1;
                    }

                    tag.EuRange = range;
                }

                break;
            }

            case UnderlyingSystemTagType.Digital:
            case UnderlyingSystemTagType.Enumerated:
            {
                if (tag.Labels != null)
                {
                    string[] labels = new string[tag.Labels.Length];

                    for (int ii = 0; ii < tag.Labels.Length; ii++)
                    {
                        labels[ii] = generator.GetRandomString();
                    }

                    tag.Labels = labels;
                }

                break;
            }

            default:
            {
                return(false);
            }
            }

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Handles a method call.
        /// </summary>
        private ServiceResult DoGenerateRandomValues(
            ISystemContext context,
            MethodState method,
            IList <object> inputArguments,
            IList <object> outputArguments)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient        client = system.SelectClient((ServerSystemContext)context, false);

            Opc.Ua.Test.DataGenerator generator = new Opc.Ua.Test.DataGenerator(null);

            IDaElementBrowser browser = client.CreateBrowser((string)method.Handle);

            // create write requests.
            WriteRequestCollection requests = new WriteRequestCollection();

            try
            {
                for (DaElement element = browser.Next(); element != null; element = browser.Next())
                {
                    if (element.ElementType == DaElementType.Branch)
                    {
                        continue;
                    }

                    // generate a random value of the correct data tyoe.
                    bool   isArray    = false;
                    NodeId dataTypeId = ComUtils.GetDataTypeId(element.DataType, out isArray);

                    object value = generator.GetRandom(
                        dataTypeId,
                        (isArray)?ValueRanks.OneDimension:ValueRanks.Scalar,
                        null,
                        context.TypeTable);

                    // create a request.
                    requests.Add(new Opc.Ua.Com.Client.WriteRequest(element.ItemId, new DataValue(new Variant(value)), 0));
                }
            }
            finally
            {
                browser.Dispose();
            }

            // write values.
            client.Write(requests);

            return(ServiceResult.Good);
        }
コード例 #7
0
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public WriteTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
     :
     base("Write", session, configuration, reportMessage, reportProgress, template)
 {
     m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
     m_generator.NamespaceUris        = Session.NamespaceUris;
     m_generator.ServerUris           = Session.ServerUris;
     m_generator.MaxArrayLength       = 3;
     m_generator.MaxStringLength      = 10;
     m_generator.MaxXmlElementCount   = 3;
     m_generator.MaxXmlAttributeCount = 3;
 }
コード例 #8
0
ファイル: CallTest.cs プロジェクト: yuriik83/UA-.NET
 /// <summary>
 /// Creates the test object.
 /// </summary>
 public CallTest(
     Session session,
     ServerTestConfiguration configuration,
     ReportMessageEventHandler reportMessage,
     ReportProgressEventHandler reportProgress,
     TestBase template)
 : 
     base("Call", session, configuration, reportMessage, reportProgress, template)
 {
     m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
     m_generator.NamespaceUris = Session.NamespaceUris;
     m_generator.ServerUris = Session.ServerUris;
     m_generator.MaxArrayLength = 3;
     m_generator.MaxStringLength = 10;
     m_generator.MaxXmlElementCount = 3;
     m_generator.MaxXmlAttributeCount = 3;
 }
コード例 #9
0
        private object GetNewValue(BaseVariableState variable)
        {
            if (m_generator == null)
            {
                m_generator = new Opc.Ua.Test.DataGenerator(null);
                m_generator.BoundaryValueFrequency = 0;
            }

            object value = null;

            while (value == null)
            {
                value = m_generator.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, Server.TypeTree);
            }

            return(value);
        }
        private object GetNewValue(BaseVariableState variable)
        {
            if (generator_ == null)
            {
                generator_ = new Opc.Ua.Test.DataGenerator(null)
                {
                    BoundaryValueFrequency = 0
                };
            }

            object value      = null;
            var    retryCount = 0;

            while (value == null && retryCount < 10)
            {
                value = generator_.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, opcServer_.NodeManager.ServerData.TypeTree);
                retryCount++;
            }
            return(value);
        }
コード例 #11
0
        //geting new value for the variable
        private object GetNewValue(BaseVariableState variable)
        {
            if (m_generator == null)
            {
                m_generator = new Opc.Ua.Test.DataGenerator(null)
                {
                    BoundaryValueFrequency = 0
                };
            }
            object value      = null;
            int    retryCount = 0;

            while (value == null && retryCount < 10)
            {
                value = m_generator.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, Server.TypeTree);
                retryCount++;
            }
            System.Console.WriteLine("into generationg new value   " + value);
            return(value);
        }
コード例 #12
0
ファイル: MonitoredItemTest.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Creates the test object.
        /// </summary>
        public MonitoredItemTest(
            Session session,
            ServerTestConfiguration configuration,
            ReportMessageEventHandler reportMessage,
            ReportProgressEventHandler reportProgress,
            TestBase template)
        : 
            base("MonitoredItem", session, configuration, reportMessage, reportProgress, template)
        {
            m_generator = new Opc.Ua.Test.DataGenerator(new Opc.Ua.Test.RandomSource(configuration.Seed));
            m_generator.NamespaceUris = Session.NamespaceUris;
            m_generator.ServerUris = Session.ServerUris;
            m_generator.MaxArrayLength = 3;
            m_generator.MaxStringLength = 10;
            m_generator.MaxXmlElementCount = 3;
            m_generator.MaxXmlAttributeCount = 3;
            m_comparer = new Opc.Ua.Test.DataComparer(Session.MessageContext);
            m_comparer.ThrowOnError = false;
            
            m_errorEvent = new ManualResetEvent(false);
            m_maximumTimingError = 300;

            m_variables = new List<TestVariable>();    
        }
コード例 #13
0
ファイル: DataFileReader.cs プロジェクト: yuriik83/UA-.NET
        /// <summary>
        /// Creates new data.
        /// </summary>
        public void CreateData(ArchiveItem item)
        {
            // get the data set to use.
            DataSet dataset = item.DataSet;

            if (dataset == null)
            {
                dataset = CreateDataSet();
            }

            // generate one hour worth of data by default.
            DateTime startTime = DateTime.UtcNow.AddHours(-1);
            startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0, DateTimeKind.Utc);

            // check for existing data.
            if (dataset.Tables[0].Rows.Count > 0)
            {
                int index = dataset.Tables[0].DefaultView.Count;
                DateTime endTime = (DateTime)dataset.Tables[0].DefaultView[index-1].Row[0];
                endTime = startTime.AddMilliseconds(item.SamplingInterval);
            }

            DateTime currentTime = startTime;
            Opc.Ua.Test.DataGenerator generator = new Opc.Ua.Test.DataGenerator(null);

            while (currentTime < DateTime.UtcNow)
            {
                DataValue dataValue = new DataValue();
                dataValue.SourceTimestamp = currentTime;
                dataValue.ServerTimestamp = currentTime.AddSeconds(generator.GetRandomByte());
                dataValue.StatusCode = StatusCodes.Good;

                // generate random value.
                if (item.ValueRank < 0)
                {
                    dataValue.Value = generator.GetRandom(item.DataType);
                }
                else
                {
                    dataValue.Value = generator.GetRandomArray(item.DataType, false, 10, false);
                }
                
                // add record to table.
                DataRow row = dataset.Tables[0].NewRow();

                row[0] = dataValue.SourceTimestamp;
                row[1] = dataValue.ServerTimestamp;
                row[2] = dataValue;
                row[3] = dataValue.WrappedValue.TypeInfo.BuiltInType;
                row[4] = dataValue.WrappedValue.TypeInfo.ValueRank;

                dataset.Tables[0].Rows.Add(row);

                // increment timestamp.
                currentTime = currentTime.AddMilliseconds(item.SamplingInterval);
            }

            dataset.AcceptChanges();
            item.DataSet = dataset;
        }
コード例 #14
0
        /// <summary>
        /// Handles a method call.
        /// </summary>
        private ServiceResult DoGenerateRandomValues(
            ISystemContext context,
            MethodState method,
            IList<object> inputArguments,
            IList<object> outputArguments)
        {
            ComDaClientManager system = (ComDaClientManager)this.SystemContext.SystemHandle;
            ComDaClient client = system.SelectClient((ServerSystemContext)context, false);

            Opc.Ua.Test.DataGenerator generator = new Opc.Ua.Test.DataGenerator(null);

            IDaElementBrowser browser = client.CreateBrowser((string)method.Handle);

            // create write requests.
            WriteRequestCollection requests = new WriteRequestCollection();

            try
            {
                for (DaElement element = browser.Next(); element != null; element = browser.Next())
                {
                    if (element.ElementType == DaElementType.Branch)
                    {
                        continue;
                    }

                    // generate a random value of the correct data tyoe.
                    bool isArray = false;
                    NodeId dataTypeId = ComUtils.GetDataTypeId(element.DataType, out isArray);
                    
                    object value = generator.GetRandom(
                        dataTypeId, 
                        (isArray)?ValueRanks.OneDimension:ValueRanks.Scalar, 
                        null, 
                        context.TypeTable);

                    // create a request.
                    requests.Add(new Opc.Ua.Com.Client.WriteRequest(element.ItemId, new DataValue(new Variant(value)), 0));
                }
            }
            finally
            {
                browser.Dispose();
            }

            // write values.
            client.Write(requests);

            return ServiceResult.Good;
        }
コード例 #15
0
        /// <summary>
        /// Creates new data.
        /// </summary>
        public void CreateData(ArchiveItem item)
        {
            // get the data set to use.
            var dataset = item.DataSet;

            if (dataset == null)
            {
                dataset = CreateDataSet();
            }

            // generate one hour worth of data by default.
            var startTime = DateTime.UtcNow.AddHours(-1);

            startTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0, DateTimeKind.Utc);

            // check for existing data.
            if (dataset.Tables[0].Rows.Count > 0)
            {
                var index   = dataset.Tables[0].DefaultView.Count;
                var endTime = (DateTime)dataset.Tables[0].DefaultView[index - 1].Row[0];
                endTime = startTime.AddMilliseconds(item.SamplingInterval);
            }

            var currentTime = startTime;
            var generator   = new Opc.Ua.Test.DataGenerator(null);

            while (currentTime < DateTime.UtcNow)
            {
                var dataValue = new DataValue {
                    SourceTimestamp = currentTime,
                    ServerTimestamp = currentTime.AddSeconds(generator.GetRandomByte()),
                    StatusCode      = StatusCodes.Good
                };

                // generate random value.
                if (item.ValueRank < 0)
                {
                    dataValue.Value = generator.GetRandom(item.DataType);
                }
                else
                {
                    dataValue.Value = generator.GetRandomArray(item.DataType, false, 10, false);
                }

                // add record to table.
                var row = dataset.Tables[0].NewRow();

                row[0] = dataValue.SourceTimestamp;
                row[1] = dataValue.ServerTimestamp;
                row[2] = dataValue;
                row[3] = dataValue.WrappedValue.TypeInfo.BuiltInType;
                row[4] = dataValue.WrappedValue.TypeInfo.ValueRank;

                dataset.Tables[0].Rows.Add(row);

                // increment timestamp.
                currentTime = currentTime.AddMilliseconds(item.SamplingInterval);
            }

            dataset.AcceptChanges();
            item.DataSet = dataset;
        }
コード例 #16
0
        private object GetNewValue(BaseVariableState variable)
        {
            if (m_generator == null)
            {
                m_generator = new Opc.Ua.Test.DataGenerator(null);
                m_generator.BoundaryValueFrequency = 0;
            }

            object value = null;

            while (value == null)
            {
                value = m_generator.GetRandom(variable.DataType, variable.ValueRank, new uint[] { 10 }, Server.TypeTree);
            }

            return value;
        }
コード例 #17
0
        /// <summary>
        /// Updates the value of an tag.
        /// </summary>
        private bool UpdateTagValue(
            UnderlyingSystemTag tag,
            Opc.Ua.Test.DataGenerator generator)
        {
            // don't update writeable tags.
            if (tag.IsWriteable)
            {
                return(false);
            }

            // check if a range applies to the value.
            var high = 0;
            var low  = 0;

            switch (tag.TagType)
            {
            case UnderlyingSystemTagType.Analog: {
                if (tag.EuRange != null && tag.EuRange.Length >= 2)
                {
                    high = (int)tag.EuRange[0];
                    low  = (int)tag.EuRange[1];
                }

                break;
            }

            case UnderlyingSystemTagType.Digital: {
                high = 1;
                low  = 0;
                break;
            }

            case UnderlyingSystemTagType.Enumerated: {
                if (tag.Labels != null && tag.Labels.Length > 0)
                {
                    high = tag.Labels.Length - 1;
                    low  = 0;
                }

                break;
            }
            }

            // select a value in the range.
            var value = -1;

            if (high > low)
            {
                value = (generator.GetRandomUInt16() % (high - low + 1)) + low;
            }

            // cast value to correct type or generate a random value.
            switch (tag.DataType)
            {
            case UnderlyingSystemDataType.Integer1: {
                if (value == -1)
                {
                    tag.Value = generator.GetRandomSByte();
                }
                else
                {
                    tag.Value = (sbyte)value;
                }

                break;
            }

            case UnderlyingSystemDataType.Integer2: {
                if (value == -1)
                {
                    tag.Value = generator.GetRandomInt16();
                }
                else
                {
                    tag.Value = (short)value;
                }

                break;
            }

            case UnderlyingSystemDataType.Integer4: {
                if (value == -1)
                {
                    tag.Value = generator.GetRandomInt32();
                }
                else
                {
                    tag.Value = value;
                }

                break;
            }

            case UnderlyingSystemDataType.Real4: {
                if (value == -1)
                {
                    tag.Value = generator.GetRandomFloat();
                }
                else
                {
                    tag.Value = (float)value;
                }

                break;
            }

            case UnderlyingSystemDataType.String: {
                tag.Value = generator.GetRandomString();
                break;
            }
            }

            tag.Timestamp = DateTime.UtcNow;
            return(true);
        }
コード例 #18
0
        /// <summary>
        /// Starts a simulation which causes the tag states to change.
        /// </summary>
        /// <remarks>
        /// This simulation randomly activates the tags that belong to the blocks.
        /// Once an tag is active it has to be acknowledged and confirmed.
        /// Once an tag is confirmed it go to the inactive state.
        /// If the tag stays active the severity will be gradually increased.
        /// </remarks>
        public void StartSimulation()
        {
            lock (m_lock)
            {
                if (m_simulationTimer != null)
                {
                    m_simulationTimer.Dispose();
                    m_simulationTimer = null;
                }

                m_generator = new Opc.Ua.Test.DataGenerator(null);
                m_simulationTimer = new Timer(DoSimulation, null, 1000, 1000);
            }
        }