Exemplo n.º 1
0
        /// <summary>
        /// Updates specified trend with values in the controls.
        /// </summary>
        public void Update(TsCHdaTrend trend)
        {
            trend.Name             = NameTB.Text;
            trend.Aggregate        = TsCHdaAggregateID.NoAggregate;
            trend.StartTime        = StartTimeCTRL.Get();
            trend.EndTime          = EndTimeCTRL.Get();
            trend.MaxValues        = (int)MaxValuesCTRL.Value;
            trend.IncludeBounds    = IncludeBoundsCB.Checked;
            trend.ResampleInterval = ResampleIntervalCTRL.Value;
            trend.UpdateInterval   = UpdateIntervalCTRL.Value;
            trend.PlaybackInterval = PlaybackIntervalCTRL.Value;
            trend.PlaybackDuration = PlaybackDurationCTRL.Value;
            trend.Timestamps       = TimestampsCTRL.GetTimes();

            if (!StartTimeSpecifiedCB.Checked)
            {
                trend.StartTime = null;
            }

            if (!EndTimeSpecifiedCB.Checked)
            {
                trend.EndTime = null;
            }

            if (AggregateSpecifiedCB.Checked)
            {
                TsCHdaAggregate aggregate = (TsCHdaAggregate)AggregateCB.SelectedItem;

                if (aggregate != null)
                {
                    trend.Aggregate = aggregate.Id;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates specified trend with values in the controls.
        /// </summary>
        public void Update(TsCHdaTrend trend)
        {
            trend.Name             = nameTb_.Text;
            trend.Aggregate        = TsCHdaAggregateID.NoAggregate;
            trend.StartTime        = startTimeCtrl_.Get();
            trend.EndTime          = endTimeCtrl_.Get();
            trend.MaxValues        = (int)maxValuesCtrl_.Value;
            trend.IncludeBounds    = includeBoundsCb_.Checked;
            trend.ResampleInterval = resampleIntervalCtrl_.Value;
            trend.UpdateInterval   = updateIntervalCtrl_.Value;
            trend.PlaybackInterval = playbackIntervalCtrl_.Value;
            trend.PlaybackDuration = playbackDurationCtrl_.Value;
            trend.Timestamps       = timestampsCtrl_.GetTimes();

            if (!startTimeSpecifiedCb_.Checked)
            {
                trend.StartTime = null;
            }

            if (!endTimeSpecifiedCb_.Checked)
            {
                trend.EndTime = null;
            }

            if (aggregateSpecifiedCb_.Checked)
            {
                TsCHdaAggregate aggregate = (TsCHdaAggregate)aggregateCb_.SelectedItem;

                if (aggregate != null)
                {
                    trend.Aggregate = aggregate.Id;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Prompts the user to select trend items and specify trend properties.
        /// </summary>
        public TsCHdaResultCollection[] ShowDialog(TsCHdaTrend trend, RequestType type, bool synchronous)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            m_server      = trend.Server;
            m_trend       = trend;
            m_type        = type;
            m_synchronous = synchronous;
            m_singleItem  = false;
            m_results     = null;

            BrowseCTRL.Browse(m_server, null);
            TrendItemsCTRL.Initialize(trend, false, null);
            TrendCTRL.Initialize(m_trend, type);
            ItemsCTRL.Initialize(null);
            ResultsCTRL.Initialize(m_server, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // return item values.
            return(m_results);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Prompts the user to specify values to insert for an item.
        /// </summary>
        public bool ShowDialog(TsCHdaServer server, OpcItem item, bool synchronous)
        {
            if (server == null) throw new ArgumentNullException("server");

            mServer_      = server;
            mSynchronous_ = synchronous;
            mItem_        = item;
            mValues_      = null;
            mResults_     = null;

            // create new trend.
            mTrend_ = new TsCHdaTrend(mServer_);

            // set reasonable defaults.
            mTrend_.StartTime = new TsCHdaTime("YEAR");
            mTrend_.EndTime   = new TsCHdaTime("YEAR+1H");

            browseCtrl_.Browse(mServer_, null);
            valuesCtrl_.Initialize(mServer_, null);
            resultsCtrl_.Initialize(mServer_, mValues_, mResults_);
            asyncResultsCtrl_.Initialize(mServer_, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            mTrend_.ClearItems();

            // return dialog result.
            return result;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Prompts the user to select trend items and specify trend properties.
        /// </summary>
        public TsCHdaItemValueCollection[] ShowDialog(TsCHdaTrend trend, RequestType type, bool synchronous)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            mServer_      = trend.Server;
            mTrend_       = trend;
            mType_        = type;
            mSynchronous_ = synchronous;
            mSingleItem_  = false;
            mResults_     = null;

            browseCtrl_.Browse(mServer_, null);
            trendItemsCtrl_.Initialize(trend, false, null);
            trendCtrl_.Initialize(mTrend_, type);
            itemsCtrl_.Initialize(null);
            resultsCtrl_.Initialize(mServer_, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // return item values.
            return(mResults_);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads the dataset containing the test descriptions.
        /// </summary>
        private TestData[] LoadDataSet()
        {
            try
            {
                // create the dataset.
                mDataset_ = new DataSet();

                // load the test case descriptions.
                mDataset_.ReadXml(mFilePath_);

                // select only the desired test cases.
                mDataset_.TestCases.DefaultView.Sort = "Name";

                // execute the test cases.
                ArrayList tests = new ArrayList(mDataset_.TestCases.DefaultView.Count);

                foreach (DataRowView row in mDataset_.TestCases.DefaultView)
                {
                    DataSet.TestCase testcase = (DataSet.TestCase)row.Row;

                    // create trend.
                    TsCHdaTrend trend = new TsCHdaTrend(mServer_);

                    trend.Name             = testcase.Name;
                    trend.Aggregate        = testcase.AggregateId;
                    trend.MaxValues        = testcase.MaxValues;
                    trend.IncludeBounds    = testcase.IncludeBounds;
                    trend.ResampleInterval = testcase.ResampleInterval;

                    if (testcase.StartTime != Decimal.MinValue)
                    {
                        trend.StartTime = new TsCHdaTime(Basetime.AddSeconds((double)testcase.StartTime));
                    }

                    if (testcase.EndTime != Decimal.MinValue)
                    {
                        trend.EndTime = new TsCHdaTime(Basetime.AddSeconds((double)testcase.EndTime));
                    }

                    TestData test = new TestData();

                    test.TestCase = testcase;
                    test.Trend    = trend;
                    test.Expected = GetExpectedResults(testcase);

                    // add to list.
                    tests.Add(test);
                }

                // return set of trends.
                return((TestData[])tests.ToArray(typeof(TestData)));
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes the control with the specified trend.
        /// </summary>
        public void Initialize(TsCHdaTrend trend, RequestType type)
        {
            // set controls to default values.
            NameTB.Text = "";
            AggregateSpecifiedCB.Checked = false;
            StartTimeCTRL.Set(new TsCHdaTime("YEAR"));
            StartTimeSpecifiedCB.Checked = true;
            EndTimeCTRL.Set(new TsCHdaTime("YEAR+1H"));
            EndTimeSpecifiedCB.Checked = true;
            MaxValuesCTRL.Value        = 0;
            IncludeBoundsCB.Checked    = false;
            ResampleIntervalCTRL.Value = 0;
            UpdateIntervalCTRL.Value   = 0;
            PlaybackIntervalCTRL.Value = 0;
            PlaybackDurationCTRL.Value = 0;

            AggregateCB.Items.Clear();

            // update controls with trend properties.
            if (trend != null)
            {
                foreach (TsCHdaAggregate aggregate in trend.Server.Aggregates)
                {
                    AggregateCB.Items.Add(aggregate);

                    if (aggregate.Id == trend.Aggregate)
                    {
                        AggregateCB.SelectedItem = aggregate;
                    }
                }

                NameTB.Text = trend.Name;
                AggregateSpecifiedCB.Checked = trend.Aggregate != TsCHdaAggregateID.NoAggregate;
                StartTimeCTRL.Set(trend.StartTime);
                StartTimeSpecifiedCB.Checked = trend.StartTime != null;
                EndTimeCTRL.Set(trend.EndTime);
                EndTimeSpecifiedCB.Checked = trend.EndTime != null;
                MaxValuesCTRL.Value        = trend.MaxValues;
                IncludeBoundsCB.Checked    = trend.IncludeBounds;
                ResampleIntervalCTRL.Value = trend.ResampleInterval;
                UpdateIntervalCTRL.Value   = trend.UpdateInterval;
                PlaybackIntervalCTRL.Value = trend.PlaybackInterval;
                PlaybackDurationCTRL.Value = trend.PlaybackDuration;

                TimestampsCTRL.Initialize(trend.Server, trend.Timestamps);
            }

            // update control visibility.
            RequestType = type;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes the control with the specified trend.
        /// </summary>
        public void Initialize(TsCHdaTrend trend, RequestType type)
        {
            // set controls to default values.
            nameTb_.Text = "";
            aggregateSpecifiedCb_.Checked = false;
            startTimeCtrl_.Set(new TsCHdaTime("YEAR"));
            startTimeSpecifiedCb_.Checked = true;
            endTimeCtrl_.Set(new TsCHdaTime("YEAR+1H"));
            endTimeSpecifiedCb_.Checked = true;
            maxValuesCtrl_.Value        = 0;
            includeBoundsCb_.Checked    = false;
            resampleIntervalCtrl_.Value = 0;
            updateIntervalCtrl_.Value   = 0;
            playbackIntervalCtrl_.Value = 0;
            playbackDurationCtrl_.Value = 0;

            aggregateCb_.Items.Clear();

            // update controls with trend properties.
            if (trend != null)
            {
                foreach (TsCHdaAggregate aggregate in trend.Server.Aggregates)
                {
                    aggregateCb_.Items.Add(aggregate);

                    if (aggregate.Id == trend.Aggregate)
                    {
                        aggregateCb_.SelectedItem = aggregate;
                    }
                }

                nameTb_.Text = trend.Name;
                aggregateSpecifiedCb_.Checked = trend.Aggregate != TsCHdaAggregateID.NoAggregate;
                startTimeCtrl_.Set(trend.StartTime);
                startTimeSpecifiedCb_.Checked = trend.StartTime != null;
                endTimeCtrl_.Set(trend.EndTime);
                endTimeSpecifiedCb_.Checked = trend.EndTime != null;
                maxValuesCtrl_.Value        = trend.MaxValues;
                includeBoundsCb_.Checked    = trend.IncludeBounds;
                resampleIntervalCtrl_.Value = trend.ResampleInterval;
                updateIntervalCtrl_.Value   = trend.UpdateInterval;
                playbackIntervalCtrl_.Value = trend.PlaybackInterval;
                playbackDurationCtrl_.Value = trend.PlaybackDuration;

                timestampsCtrl_.Initialize(trend.Server, trend.Timestamps);
            }

            // update control visibility.
            RequestType = type;
        }
        /// <summary>
        /// Prompts the user to select items and specify trend properties.
        /// </summary>
        public TsCHdaTrend ShowDialog(TsCHdaServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_  = server;
            mResults_ = null;

            // create new trend.
            TsCHdaTrend trend = new TsCHdaTrend(mServer_);

            // set reasonable defaults.
            trend.StartTime = new TsCHdaTime("YEAR");
            trend.EndTime   = new TsCHdaTime("YEAR+1H");

            browseCtrl_.Browse(mServer_, null);
            trendCtrl_.Initialize(trend, RequestType.None);
            itemsCtrl_.Initialize(mServer_, (OpcItem[])null);
            resultsCtrl_.Initialize(mServer_, mResults_);

            // update dialog state.
            SetState(false);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create or update the trend.
            trendCtrl_.Update(trend);

            // add new items.
            if (mResults_ != null)
            {
                foreach (OpcItemResult item in mResults_)
                {
                    if (item.Result.Succeeded())
                    {
                        trend.Items.Add(new TsCHdaItem(item));
                    }
                }
            }

            // return new trend.
            return(trend);
        }
        /// <summary>
        /// Prompts the user to select attributes to read for an item.
        /// </summary>
        public TsCHdaItemAttributeCollection ShowDialog(
            TsCHdaServer server,
            OpcItem item,
            TsCHdaTime startTime,
            TsCHdaTime endTime,
            bool synchronous)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_      = server;
            mItem_        = item;
            mFixedItem_   = item != null;
            mSynchronous_ = synchronous;
            mResults_     = null;

            // create new trend.
            mTrend_ = new TsCHdaTrend(mServer_);

            // set reasonable defaults.
            mTrend_.StartTime = startTime;
            mTrend_.EndTime   = endTime;

            browseCtrl_.Browse(mServer_, null);
            trendCtrl_.Initialize(mTrend_, RequestType.ReadAttributes);
            attributesCtrl_.Initialize(mServer_, null);
            resultsCtrl_.Initialize(mServer_, mResults_);
            asyncResultsCtrl_.Initialize(mServer_, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            mTrend_.ClearItems();

            // return item values.
            return((result)?mResults_:null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Prompts the user to select attributes to read for an item.
        /// </summary>
        public TsCHdaItemAttributeCollection ShowDialog(
            TsCHdaServer server,
            OpcItem item,
            TsCHdaTime startTime,
            TsCHdaTime endTime,
            bool synchronous)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server      = server;
            m_item        = item;
            m_fixedItem   = item != null;
            m_synchronous = synchronous;
            m_results     = null;

            // create new trend.
            m_trend = new TsCHdaTrend(m_server);

            // set reasonable defaults.
            m_trend.StartTime = startTime;
            m_trend.EndTime   = endTime;

            BrowseCTRL.Browse(m_server, null);
            TrendCTRL.Initialize(m_trend, RequestType.ReadAttributes);
            AttributesCTRL.Initialize(m_server, null);
            ResultsCTRL.Initialize(m_server, m_results);
            AsyncResultsCTRL.Initialize(m_server, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            m_trend.ClearItems();

            // return item values.
            return((result)?m_results:null);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Prompts the user to edit the properties of a trend.
        /// </summary>
        public TsCHdaItem[] ShowDialog(TsCHdaTrend trend, ArrayList excludeList)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            // initialize the controls.
            itemsCtrl_.Initialize(trend, false, excludeList);

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // return selected items.
            return(itemsCtrl_.GetItems(true));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Prompts the user to select items and specify trend properties.
        /// </summary>
        public OpcItem[] ShowDialog(TsCHdaTrend trend)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            m_server  = trend.Server;
            m_results = null;

            BrowseCTRL.Browse(m_server, null);
            TrendCTRL.Initialize(trend, RequestType.None);
            ItemsCTRL.Initialize(m_server, (OpcItem[])null);
            ResultsCTRL.Initialize(m_server, m_results);

            // update dialog state.
            SetState(false);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create or update the trend.
            TrendCTRL.Update(trend);

            // add new items.
            if (m_results != null)
            {
                foreach (OpcItemResult item in m_results)
                {
                    if (item.Result.Succeeded())
                    {
                        trend.Items.Add(new TsCHdaItem(item));
                    }
                }
            }

            // return new items
            return(m_results);
        }
        /// <summary>
        /// Prompts the user to select items and specify trend properties.
        /// </summary>
        public OpcItem[] ShowDialog(TsCHdaTrend trend)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            mServer_  = trend.Server;
            mResults_ = null;

            browseCtrl_.Browse(mServer_, null);
            trendCtrl_.Initialize(trend, RequestType.None);
            itemsCtrl_.Initialize(mServer_, (OpcItem[])null);
            resultsCtrl_.Initialize(mServer_, mResults_);

            // update dialog state.
            SetState(false);

            // show dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            // create or update the trend.
            trendCtrl_.Update(trend);

            // add new items.
            if (mResults_ != null)
            {
                foreach (OpcItemResult item in mResults_)
                {
                    if (item.Result.Succeeded())
                    {
                        trend.Items.Add(new TsCHdaItem(item));
                    }
                }
            }

            // return new items
            return(mResults_);
        }
        /// <summary>
        /// Displays data for the current selection in the right pane.
        /// </summary>
        private void TrendsCTRL_TrendSelected(TsCHdaTrend trend, TsCHdaItem item)
        {
            if (trend != null && trend.Items.Count > 0)
            {
                if (item == null)
                {
                    item = trend.Items[0];
                }

                if (item.ClientHandle != null)
                {
                    valuesCtrl_.Initialize(server_, (TsCHdaItemValueCollection)cache_[item.ClientHandle]);
                    selectedItem_ = item.ClientHandle;
                    return;
                }
            }

            valuesCtrl_.Initialize(server_, null);
            selectedItem_ = null;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Displays data for the current selection in the right pane.
        /// </summary>
        private void TrendsCTRL_TrendSelected(TsCHdaTrend trend, TsCHdaItem item)
        {
            if (trend != null && trend.Items.Count > 0)
            {
                if (item == null)
                {
                    item = trend.Items[0];
                }

                if (item.ClientHandle != null)
                {
                    ValuesCTRL.Initialize(m_server, (TsCHdaItemValueCollection)m_cache[item.ClientHandle]);
                    m_selectedItem = item.ClientHandle;
                    return;
                }
            }

            ValuesCTRL.Initialize(m_server, null);
            m_selectedItem = null;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Prompts the user to edit the properties of a trend.
        /// </summary>
        public bool ShowDialog(TsCHdaTrend trend)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            // initialize the controls.
            TrendCTRL.Initialize(trend, RequestType.None);

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            // update the trend.
            TrendCTRL.Update(trend);

            return(true);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Prompts the user to select an item and specify trend properties.
        /// </summary>
        public TsCHdaResultCollection[] ShowDialog(TsCHdaServer server, RequestType type, bool synchronous)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server      = server;
            m_type        = type;
            m_synchronous = synchronous;
            m_singleItem  = true;
            m_results     = null;

            // create new trend.
            m_trend = new TsCHdaTrend(m_server);

            // set reasonable defaults.
            m_trend.StartTime = new TsCHdaTime("YEAR");
            m_trend.EndTime   = new TsCHdaTime("YEAR+1H");

            BrowseCTRL.Browse(m_server, null);
            TrendItemsCTRL.Initialize(m_trend, false, null);
            TrendCTRL.Initialize(m_trend, type);
            ItemsCTRL.Initialize(null);
            ResultsCTRL.Initialize(m_server, null);
            AsyncResultsCTRL.Initialize(m_server, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            m_trend.ClearItems();

            // return item values.
            return(m_results);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Prompts the user to select an item and specify trend properties.
        /// </summary>
        public TsCHdaItemValueCollection ShowDialog(TsCHdaServer server, RequestType type, bool synchronous)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            mServer_      = server;
            mType_        = type;
            mSynchronous_ = synchronous;
            mSingleItem_  = true;
            mResults_     = null;

            // create new trend.
            mTrend_ = new TsCHdaTrend(mServer_);

            // set reasonable defaults.
            mTrend_.StartTime = new TsCHdaTime("YEAR");
            mTrend_.EndTime   = new TsCHdaTime("YEAR+1H");

            browseCtrl_.Browse(mServer_, null);
            trendItemsCtrl_.Initialize(mTrend_, false, null);
            trendCtrl_.Initialize(mTrend_, type);
            itemsCtrl_.Initialize(null);
            resultsCtrl_.Initialize(mServer_, null);
            asyncResultsCtrl_.Initialize(mServer_, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            mTrend_.ClearItems();

            // return item values.
            return((result)?mResults_[0]:null);
        }
        /// <summary>
        /// Prompts the user to specify values to insert for an item.
        /// </summary>
        public bool ShowDialog(TsCHdaServer server, OpcItem item, bool replace, bool synchronous)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            m_server      = server;
            m_replace     = replace;
            m_synchronous = synchronous;
            m_item        = item;
            m_values      = null;
            m_results     = null;

            // create new trend.
            m_trend = new TsCHdaTrend(m_server);

            // set reasonable defaults.
            m_trend.StartTime = new TsCHdaTime("YEAR");
            m_trend.EndTime   = new TsCHdaTime("YEAR+1H");

            BrowseCTRL.Browse(m_server, null);
            ValuesCTRL.Initialize(m_server, null);
            ResultsCTRL.Initialize(m_server, m_values, m_results);
            AsyncResultsCTRL.Initialize(m_server, null);

            // update dialog state.
            SetState();

            // show dialog.
            bool result = (ShowDialog() == DialogResult.OK);

            // release item handles.
            m_trend.ClearItems();

            // return dialog result.
            return(result);
        }
        /// <summary>
        /// Initializes the control with the set of items in a trend.
        /// </summary>
        public void Initialize(TsCHdaTrend trend, bool update, ArrayList excludeList)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            m_trend = trend;

            ItemsLV.Items.Clear();

            // add trend items.
            foreach (TsCHdaItem item in trend.Items)
            {
                // ignore items in the exclude list.
                if (excludeList != null)
                {
                    if (excludeList.Contains(item))
                    {
                        continue;
                    }
                }

                // create empty item value collections for each item.
                if (update)
                {
                    AddListItem(new TsCHdaItemValueCollection(item));
                }
                else
                {
                    AddListItem(item);
                }
            }

            // adjust the list view columns to fit the data.
            AdjustColumns();
        }
        /// <summary>
        /// Prompts the user to edit the properties of a trend.
        /// </summary>
        public bool ShowDialog(TsCHdaTrend trend, RequestType type)
        {
            if (trend == null)
            {
                throw new ArgumentNullException("trend");
            }

            // initialize the controls.
            TrendCTRL.Initialize(trend, type);

            // adjust dialog height.
            Height -= (ButtonsPN.Top - MainPN.Height);

            // show the dialog.
            if (ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            // update the trend.
            TrendCTRL.Update(trend);

            return(true);
        }
        public void Run()
        {
            try
            {
                const string serverUrl = "opchda://localhost/OPCSample.OpcHdaServer";

                Console.WriteLine();
                Console.WriteLine("Simple OPC HDA Client based on the OPC DA/AE/HDA Solution .NET");
                Console.WriteLine("--------------------------------------------------------------");
                Console.Write("   Press <Enter> to connect to "); Console.WriteLine(serverUrl);
                Console.ReadLine();
                Console.WriteLine("   Please wait...");

                TsCHdaServer myHdaServer = new TsCHdaServer();

                myHdaServer.Connect(serverUrl);

                Console.WriteLine("   Connected, press <Enter> to add a trend.");
                Console.ReadLine();

                // Add a trend and set the properties for reading
                TsCHdaTrend trend = new TsCHdaTrend(myHdaServer)
                {
                    StartTime = new TsCHdaTime(new DateTime(2004, 01, 01, 00, 00, 00)), EndTime = new TsCHdaTime(new DateTime(2004, 01, 01, 06, 00, 00)), IncludeBounds = true, MaxValues = 1000
                };

                OpcItem itemId = new OpcItem("Static Data/Ramp [15 min]");

                trend.Timestamps.Add(new DateTime(2016, 01, 01, 00, 00, 00));

                trend.ReadRaw(new OpcItem[] { trend.AddItem(itemId) }, null, OnReadComplete, out _);

                // read the historic data of the specified item
                TsCHdaItemValueCollection[] items = trend.ReadRaw(new[] { trend.AddItem(itemId) });
                foreach (TsCHdaItemValueCollection item in items)
                {
                    Console.WriteLine($"{item.ItemName}");

                    foreach (TsCHdaItemValue val in item)
                    {
                        if ((val.Quality.GetCode() & (int)TsDaQualityMasks.QualityMask) != (int)TsDaQualityBits.Good)
                        {
                            Console.WriteLine($"      {val.Timestamp}, {val.Quality}");
                        }
                        else
                        {
                            Console.WriteLine($"      {val.Timestamp}, {val.Value}");
                        }
                    }
                }

                trend.Timestamps.Add(new DateTime(2016, 01, 01, 00, 00, 00));
                items = trend.ReadAtTime(new[] { trend.AddItem(itemId) });
                foreach (TsCHdaItemValueCollection item in items)
                {
                    Console.WriteLine($"{item.ItemName}");


                    foreach (TsCHdaItemValue val in item)
                    {
                        if ((val.Quality.GetCode() & (int)TsDaQualityMasks.QualityMask) != (int)TsDaQualityBits.Good)
                        {
                            Console.WriteLine($"      {val.Timestamp}, {val.Quality}");
                        }
                        else
                        {
                            Console.WriteLine($"      {val.Timestamp}, {val.Value}");
                        }
                    }
                }
                Console.WriteLine("   Historical Data Trend read, press <Enter> to disconnect from the server.");
                myHdaServer.Disconnect();
                myHdaServer.Dispose();
                Console.ReadLine();
                Console.WriteLine("   Disconnected from the server.");
                Console.WriteLine();
            }
            catch (OpcResultException e)
            {
                Console.WriteLine("   " + e.Message);
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("   " + e.Message);
                Console.ReadLine();
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Updates the cached values for the items.
        /// </summary>
        private void TrendsCTRL_TrendChanged(TsCHdaTrend trend, TsCHdaItemValueCollection[] values, bool replace)
        {
            // add new values to cache.
            if (values != null && values.Length > 0)
            {
                foreach (TsCHdaItemValueCollection value in values)
                {
                    // ignore results without a client handle.
                    if (value.ClientHandle == null)
                    {
                        continue;
                    }

                    // check if results for the item already exist.
                    TsCHdaItemValueCollection existingValues = (TsCHdaItemValueCollection)m_cache[value.ClientHandle];

                    if (!replace && existingValues != null)
                    {
                        existingValues.AddRange(value);
                    }

                    // replace existing or insert new results for the item.
                    else
                    {
                        m_cache[value.ClientHandle] = value;
                    }
                }

                // update values display if nothing is selected.
                if (m_selectedItem == null)
                {
                    m_selectedItem = values[0].ClientHandle;
                    ValuesCTRL.Initialize(m_server, (TsCHdaItemValueCollection)m_cache[m_selectedItem]);
                }

                // onluy update values display if current selection changed.
                else
                {
                    foreach (OpcItem item in values)
                    {
                        if (m_selectedItem.Equals(item.ClientHandle))
                        {
                            ValuesCTRL.Initialize(m_server, (TsCHdaItemValueCollection)m_cache[m_selectedItem]);
                        }
                    }
                }
            }

            // clear items from the cache.
            else if (replace)
            {
                foreach (TsCHdaItem item in trend.Items)
                {
                    if (item.ClientHandle != null)
                    {
                        if (item.ClientHandle.Equals(m_selectedItem))
                        {
                            ValuesCTRL.Initialize(m_server, null);
                            m_selectedItem = null;
                        }

                        m_cache.Remove(item.ClientHandle);
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////
        #region OPC Sample Functionality

        void DoOPCCalls()
        {
            try
            {
                const string serverUrl = "opchda://localhost/OPCSample.OpcHdaServer";

                Console.WriteLine();
                Console.WriteLine("Simple OPC HDA Client based on the OPC DA/AE/HDA Client SDK .NET");
                Console.WriteLine("----------------------------------------------------------------");
                Console.Write("   Press <Enter> to connect to "); Console.WriteLine(serverUrl);
                Console.ReadLine();
                Console.WriteLine("   Please wait...");

                //OpcBase.ValidateLicense("License Key");

                TsCHdaServer myHdaServer = new TsCHdaServer();

                myHdaServer.Connect(serverUrl);

                Console.WriteLine("   Connected, press <Enter> to add a trend.");
                Console.ReadLine();

                // Add a trend and set the properties for reading
                TsCHdaTrend trend = new TsCHdaTrend(myHdaServer)
                {
                    StartTime = new TsCHdaTime(new DateTime(2004, 01, 01, 00, 00, 00)), EndTime = new TsCHdaTime(new DateTime(2004, 01, 01, 06, 00, 00)), IncludeBounds = true, MaxValues = 1000
                };

                OpcItem itemID = new OpcItem("Static Data/Ramp [15 min]");

                trend.Timestamps.Add(new DateTime(2016, 01, 01, 00, 00, 00));
                OpcItemResult[] results = null;
                IOpcRequest     request = null;

                results = trend.ReadRaw(new TsCHdaItem[] { trend.AddItem(itemID) }, null, new TsCHdaReadValuesCompleteEventHandler(OnReadComplete), out request);

                // read the historic data of the specified item
                TsCHdaItemValueCollection[] items = trend.ReadRaw(new TsCHdaItem[] { trend.AddItem(itemID) });
                foreach (TsCHdaItemValueCollection item in items)
                {
                    Console.WriteLine(String.Format("{0}", item.ItemName));

                    foreach (TsCHdaItemValue val in item)
                    {
                        if (((int)val.Quality.GetCode() & (int)TsDaQualityMasks.QualityMask) != (int)TsDaQualityBits.Good)
                        {
                            Console.WriteLine(string.Format("      {0}, {1}", val.Timestamp, val.Quality));
                        }
                        else
                        {
                            Console.WriteLine(string.Format("      {0}, {1}", val.Timestamp, val.Value.ToString()));
                        }
                    }
                }

                trend.Timestamps.Add(new DateTime(2016, 01, 01, 00, 00, 00));
                items = trend.ReadAtTime(new TsCHdaItem[] { trend.AddItem(itemID) });
                foreach (TsCHdaItemValueCollection item in items)
                {
                    Console.WriteLine(String.Format("{0}", item.ItemName));


                    foreach (TsCHdaItemValue val in item)
                    {
                        if (((int)val.Quality.GetCode() & (int)TsDaQualityMasks.QualityMask) != (int)TsDaQualityBits.Good)
                        {
                            Console.WriteLine(string.Format("      {0}, {1}", val.Timestamp, val.Quality));
                        }
                        else
                        {
                            Console.WriteLine(string.Format("      {0}, {1}", val.Timestamp, val.Value.ToString()));
                        }
                    }
                }
                Console.WriteLine("   Historical Data Trend read, press <Enter> to disconnect from the server.");
                myHdaServer.Disconnect();
                myHdaServer.Dispose();
                Console.ReadLine();
                Console.WriteLine("   Disconnected from the server.");
                Console.WriteLine();
            }
            catch (OpcResultException e)
            {
                Console.WriteLine("   " + e.Message);
                Console.ReadLine();
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine("   " + e.Message);
                Console.ReadLine();
                return;
            }
        }