Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string url = "opcda://localhost/Kepware.KEPServerEX.V6/{B3AF0BF6-4C0C-4804-A122-6F3B160F4397}";

            connectInfo.LocalId                   = "en";
            connectInfo.KeepAliveTime             = 1000;
            connectInfo.RetryAfterConnectionError = true;
            connectInfo.RetryInitialConnection    = false;
            connectInfo.ClientName                = "CS Simple Client";
            connectFailed = false;

            int clientHandle = 1;

            try
            {
                DAserver.Connect(url, clientHandle, ref connectInfo, out connectFailed);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Handled Connect exception. Reason: " + ex.Message);

                connectFailed = true;
            }

            if (connectFailed)
            {
                MessageBox.Show("Connect failed");
            }

            SubscribeToOPCDAServerEvents();

            Subscribe2Data();
            ModifySubscription(true);
        }
Esempio n. 2
0
        // Функция проверки подключеиня к серверу
        public bool TestConnection()
        {
            bool result = false;

            if (String.IsNullOrEmpty(URL))
            {
                return(false);
            }
            try
            {
                Kepware.ClientAce.OpcDaClient.ConnectInfo connectInfo = new Kepware.ClientAce.OpcDaClient.ConnectInfo();
                Kepware.ClientAce.OpcDaClient.DaServerMgt DAServer    = new Kepware.ClientAce.OpcDaClient.DaServerMgt();
                Boolean connectFailed = false;

                connectInfo.LocalId                   = "en";
                connectInfo.KeepAliveTime             = KeepAliveTime;
                connectInfo.RetryAfterConnectionError = RetryAfterConnectionError;
                connectInfo.RetryInitialConnection    = RetryInitialConnection;
                connectInfo.ClientName                = "OPCClient";

                Int32 clientHandle = 1;

                DAServer.Connect(URL, clientHandle, ref connectInfo, out connectFailed);
                result = !connectFailed;
                DAServer.Disconnect();
                return(result);
            }
            catch { return(false); }
        }