예제 #1
0
        /// <summary>
        /// Create server handles for new items.
        /// </summary>
        private void DoRead()
        {
            // fetch the new trend parameters.
            trendCtrl_.Update(mTrend_);

            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            // read data.
            TsCHdaItemValueCollection[] results = mTrend_.Read(new TsCHdaItem[] { item });

            if (results == null || results.Length != 1)
            {
                ////throw new InvalidResponseException();
            }

            // save results.
            mValues_ = results;

            // display results.
            valuesCtrl_.Initialize(mServer_, mValues_[0]);
        }
        /// <summary>
        /// Create server handles for new items.
        /// </summary>
        private void DoRead()
        {
            // fetch the new trend parameters.
            TrendCTRL.Update(m_trend);

            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // read data.
            TsCHdaItemValueCollection[] results = m_trend.Read(new TsCHdaItem[] { item });

            if (results == null || results.Length != 1)
            {
                ////throw new InvalidResponseException();
            }

            // save results.
            m_values = results;

            // display results.
            ValuesCTRL.Initialize(m_server, m_values[0]);
        }
예제 #3
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // get request parameters from controls.
            TrendCTRL.Update(m_trend);

            if (m_synchronous)
            {
                // read data.
                TsCHdaAnnotationValueCollection[] results = m_trend.ReadAnnotations(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                ItemsCTRL.Initialize(results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin read data.
                OpcItemResult[] results = m_trend.ReadAnnotations(
                    new TsCHdaItem[] { item },
                    null,
                    new TsCHdaReadAnnotationsCompleteEventHandler(OnReadComplete),
                    out m_request);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, results);
                m_asyncSent = true;
            }
        }
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            // get request parameters from controls.
            trendCtrl_.Update(mTrend_);

            if (mSynchronous_)
            {
                // read data.
                TsCHdaAnnotationValueCollection[] results = mTrend_.ReadAnnotations(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                itemsCtrl_.Initialize(results);

                // save results.
                mResults_ = results;
            }
            else
            {
                // check if already waiting for results.
                if (mAsyncSent_)
                {
                    return;
                }

                // begin read data.
                OpcItemResult[] results = mTrend_.ReadAnnotations(
                    new TsCHdaItem[] { item },
                    null,
                    new TsCHdaReadAnnotationsCompleteEventHandler(OnReadComplete),
                    out mRequest_);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                asyncResultsCtrl_.Initialize(mServer_, results);
                mAsyncSent_ = true;
            }
        }
예제 #5
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemDelete()
        {
            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            if (m_synchronous)
            {
                // delete data.
                TsCHdaResultCollection[] results = SyncDelete(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                ItemsCTRL.Initialize(results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin delete data.
                OpcItemResult[] results = AsyncDelete(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, results);
                m_asyncSent = true;
            }
        }
예제 #6
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemDelete()
        {
            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            if (mSynchronous_)
            {
                // delete data.
                TsCHdaResultCollection[] results = SyncDelete(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                itemsCtrl_.Initialize(results);

                // save results.
                mResults_ = results;
            }
            else
            {
                // check if already waiting for results.
                if (mAsyncSent_)
                {
                    return;
                }

                // begin delete data.
                OpcItemResult[] results = AsyncDelete(new TsCHdaItem[] { item });

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                asyncResultsCtrl_.Initialize(mServer_, results);
                mAsyncSent_ = true;
            }
        }
        /// <summary>
        /// Updates the values of the item.
        /// </summary>
        private void DoInsert()
        {
            // get the values to insert/replace.
            mValues_ = new TsCHdaItemValueCollection[] { valuesCtrl_.GetValues() };

            // check if there is nothing to do.
            if (mValues_[0] == null || mValues_[0].Count == 0)
            {
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            // add the item identifier information to the collection.
            mValues_[0].ItemName     = item.ItemName;
            mValues_[0].ItemPath     = item.ItemPath;
            mValues_[0].ServerHandle = item.ServerHandle;
            mValues_[0].ClientHandle = item.ClientHandle;

            if (mSynchronous_)
            {
                // insert data.
                TsCHdaResultCollection[] results = mServer_.Insert(mValues_, mReplace_);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                resultsCtrl_.Initialize(mServer_, mValues_, results);

                // save results.
                mResults_ = results;
            }
            else
            {
                // check if already waiting for results.
                if (mAsyncSent_)
                {
                    return;
                }

                // begin insert data.
                OpcItemResult[] results = mServer_.Insert(
                    mValues_,
                    mReplace_,
                    null,
                    new TsCHdaUpdateCompleteEventHandler(OnUpdateComplete),
                    out mRequest_);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                asyncResultsCtrl_.Initialize(mServer_, results);
                mAsyncSent_ = true;
            }
        }
예제 #8
0
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // get the attribute ids.
            if (m_attributeIDs == null)
            {
                m_attributeIDs = AttributesCTRL.GetAttributeIDs(true);
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // get the paramaters.
            TrendCTRL.Update(m_trend);

            // get the attributes.
            m_attributeIDs = AttributesCTRL.GetAttributeIDs(true);

            if (m_synchronous)
            {
                // read data.
                TsCHdaItemAttributeCollection results = m_trend.ReadAttributes(item, m_attributeIDs);

                if (results == null || results.Count != m_attributeIDs.Length)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                ResultsCTRL.Initialize(m_server, results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin read data.
                TsCHdaResultCollection results = m_trend.ReadAttributes(
                    item,
                    m_attributeIDs,
                    null,
                    new TsCHdaReadAttributesCompleteEventHandler(OnReadComplete),
                    out m_request);

                if (results == null || results.Count != m_attributeIDs.Length)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, m_attributeIDs, results);
                m_asyncSent = 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();
            }
        }
        /// <summary>
        /// Creates a server handle for the selected item and reads the data.
        /// </summary>
        private void DoItemRead()
        {
            // get the attribute ids.
            if (mAttributeIDs_ == null)
            {
                mAttributeIDs_ = attributesCtrl_.GetAttributeIDs(true);
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = mTrend_.Items[mItem_];

            if (item == null)
            {
                item = mTrend_.AddItem(mItem_);
            }

            // get the paramaters.
            trendCtrl_.Update(mTrend_);

            // get the attributes.
            mAttributeIDs_ = attributesCtrl_.GetAttributeIDs(true);

            if (mSynchronous_)
            {
                // read data.
                TsCHdaItemAttributeCollection results = mTrend_.ReadAttributes(item, mAttributeIDs_);

                if (results == null || results.Count != mAttributeIDs_.Length)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                resultsCtrl_.Initialize(mServer_, results);

                // save results.
                mResults_ = results;
            }
            else
            {
                // check if already waiting for results.
                if (mAsyncSent_)
                {
                    return;
                }

                // begin read data.
                TsCHdaResultCollection results = mTrend_.ReadAttributes(
                    item,
                    mAttributeIDs_,
                    null,
                    new TsCHdaReadAttributesCompleteEventHandler(OnReadComplete),
                    out mRequest_);

                if (results == null || results.Count != mAttributeIDs_.Length)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                asyncResultsCtrl_.Initialize(mServer_, mAttributeIDs_, results);
                mAsyncSent_ = true;
            }
        }
        /// <summary>
        /// Updates the values of the item.
        /// </summary>
        private void DoInsert()
        {
            // get the values to insert/replace.
            m_values = new TsCHdaItemValueCollection[] { ValuesCTRL.GetValues() };

            // check if there is nothing to do.
            if (m_values[0] == null || m_values[0].Count == 0)
            {
                return;
            }

            // create item (if necessary).
            TsCHdaItem item = m_trend.Items[m_item];

            if (item == null)
            {
                item = m_trend.AddItem(m_item);
            }

            // add the item identifier information to the collection.
            m_values[0].ItemName     = item.ItemName;
            m_values[0].ItemPath     = item.ItemPath;
            m_values[0].ServerHandle = item.ServerHandle;
            m_values[0].ClientHandle = item.ClientHandle;

            if (m_synchronous)
            {
                // insert data.
                TsCHdaResultCollection[] results = m_server.Insert(m_values, m_replace);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display results.
                ResultsCTRL.Initialize(m_server, m_values, results);

                // save results.
                m_results = results;
            }
            else
            {
                // check if already waiting for results.
                if (m_asyncSent)
                {
                    return;
                }

                // begin insert data.
                OpcItemResult[] results = m_server.Insert(
                    m_values,
                    m_replace,
                    null,
                    new TsCHdaUpdateCompleteEventHandler(OnUpdateComplete),
                    out m_request);

                if (results == null || results.Length != 1)
                {
                    ////throw new InvalidResponseException();
                }

                // display initial results.
                AsyncResultsCTRL.Initialize(m_server, results);
                m_asyncSent = true;
            }
        }
        ///////////////////////////////////////////////////////////////////////
        #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;
            }
        }