///////////////////////////////////////////////////////////////////////
        #region Public Methods

        /// <summary>
        /// Connects to the server with the specified OpcUrl and credentials.
        /// </summary>
        public override void Connect(OpcUrl url, OpcConnectData connectData)
        {
            if (_factory == null)
            {
                _factory = new Com.Factory();
            }
            // connect to server.
            base.Connect(url, connectData);

            // all done if no subscriptions.
            if (_subscriptions.Count == 0)
            {
                return;
            }

            // create subscriptions (should only happen if server has been deserialized).
            SubscriptionCollection subscriptions = new SubscriptionCollection();

            foreach (Ae.TsCAeSubscription template in _subscriptions)
            {
                // create subscription for template.
                try { subscriptions.Add(EstablishSubscription(template)); }
                catch { }
            }

            // save new set of subscriptions.
            _subscriptions = subscriptions;
        }
        /// <summary>
        /// Connects to the server with the specified OpcUrl and credentials.
        /// </summary>
        public override void Connect(OpcUrl url, OpcConnectData connectData)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.HistoricalAccess);
            if (Factory == null)
            {
                Factory = new Com.Factory();
            }
            // connect to server.
            base.Connect(url, connectData);

            // fetch supported attributes.
            GetAttributes();

            // fetch supported aggregates.
            GetAggregates();

            // create items for trends.
            foreach (TsCHdaTrend trend in trends_)
            {
                ArrayList itemIDs = new ArrayList();

                foreach (TsCHdaItem item in trend.Items)
                {
                    itemIDs.Add(new OpcItem(item));
                }

                // save server handles for each item.
                OpcItemResult[] results = CreateItems((OpcItem[])itemIDs.ToArray(typeof(OpcItem)));

                if (results != null)
                {
                    for (int ii = 0; ii < results.Length; ii++)
                    {
                        trend.Items[ii].ServerHandle = null;

                        if (results[ii].Result.Succeeded())
                        {
                            trend.Items[ii].ServerHandle = results[ii].ServerHandle;
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>Connects to the server with the specified OpcUrl and credentials.</summary>
        /// <exception caption="OpcResultException Class" cref="OpcResultException">If an OPC specific error occur this exception is raised. The Result field includes then the OPC specific code.</exception>
        /// <param name="url">The network address of the remote server.</param>
        /// <param name="connectData">Any protocol configuration or user authentication information.</param>
        public override void Connect(OpcUrl url, OpcConnectData connectData)
        {
            LicenseHandler.ValidateFeatures(LicenseHandler.ProductFeature.DataAccess);
            if (Factory == null)
            {
                if (Factory == null)
                {
                    Factory = new Com.Factory();
                }
            }
            // connect to server.
            base.Connect(url, connectData);

            // all done if no subscriptions.
            if (subscriptions_ == null)
            {
                return;
            }

            // create subscriptions (should only happen if server has been deserialized).
            TsCDaSubscriptionCollection subscriptions = new TsCDaSubscriptionCollection();

            foreach (TsCDaSubscription template in subscriptions_)
            {
                // create subscription for template.
                try
                {
                    subscriptions.Add(EstablishSubscription(template));
                }
                catch
                {
                    // Ignore exceptions here
                }
            }

            // save new set of subscriptions.
            subscriptions_ = subscriptions;
        }
        /// <summary>
        /// Initializes the object.
        /// </summary>
        public TsCHdaServer()

        {
            Factory = new Com.Factory();
        }
예제 #5
0
        /// <summary>
        /// Returns a list of servers that support the specified specification on the specified host.
        /// </summary>
        public OpcServer[] GetAvailableServers(OpcSpecification specification, string host, OpcConnectData connectData)
        {
            lock (this)
            {
                NetworkCredential credentials = (connectData != null)?connectData.GetCredential(null, null):null;

                // connect to the server.
                m_server = (IOPCServerList2)Com.Interop.CreateInstance(CLSID, host, credentials);
                m_host   = host;

                try
                {
                    ArrayList servers = new ArrayList();

                    // convert the interface version to a guid.
                    Guid catid = new Guid(specification.Id);

                    // get list of servers in the specified specification.
                    IOPCEnumGUID enumerator = null;

                    m_server.EnumClassesOfCategories(
                        1,
                        new Guid[] { catid },
                        0,
                        null,
                        out enumerator);

                    // read clsids.
                    Guid[] clsids = ReadClasses(enumerator);

                    // release enumerator object.
                    Com.Interop.ReleaseServer(enumerator);
                    enumerator = null;

                    // fetch class descriptions.
                    foreach (Guid clsid in clsids)
                    {
                        Factory factory = new Com.Factory();

                        try
                        {
                            OpcUrl url = CreateUrl(specification, clsid);

                            OpcServer server = null;

                            if (specification == OpcSpecification.OPC_DA_30)
                            {
                                server = new TsCDaServer(factory, url);
                            }

                            else if (specification == OpcSpecification.OPC_DA_20)
                            {
                                server = new TsCDaServer(factory, url);
                            }

                            else if (specification == OpcSpecification.OPC_AE_10)
                            {
                                server = new TsCAeServer(factory, url);
                            }

                            else if (specification == OpcSpecification.OPC_HDA_10)
                            {
                                server = new TsCHdaServer(factory, url);
                            }

                            servers.Add(server);
                        }
                        catch (Exception)
                        {
                            // ignore bad clsids.
                        }
                    }

                    return((OpcServer[])servers.ToArray(typeof(OpcServer)));
                }
                finally
                {
                    // free the server.
                    Com.Interop.ReleaseServer(m_server);
                    m_server = null;
                }
            }
        }