Quickstarts.DataAccessServer.UnderlyingSystemBlock.DoSimulation C# (CSharp) Method

DoSimulation() public method

Simulates a block by updating the state of the tags belonging to the condition.
public DoSimulation ( long counter, int index, Opc generator ) : void
counter long The number of simulation cycles that have elapsed.
index int The index of the block within the system.
generator Opc An object which generates random data.
return void
        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);
            }
        }
        #endregion