Ejemplo n.º 1
0
        public static bool connect()
        {
            //initialize the connection info class
            DAServer = new DaServerMgt();
            connectInfo = new ConnectInfo();

            string url = "opcda://localhost/Kepware.KEPServerEX.V5/{B3AF0BF6-4C0C-4804-A122-6F3B160F4397}";

            int clientHandle = 1;

            //initialize the connect info object data
            connectInfo.LocalId = "en";
            connectInfo.KeepAliveTime = 5000;
            connectInfo.RetryAfterConnectionError = true;
            connectInfo.RetryInitialConnection = true;
            connectInfo.ClientName = "IDCServer";

            bool connectFailed = false;

            try
            {
                logger.Info("Connecting to DAServer: {0}, {1}, {2}", url, clientHandle, connectInfo.ToString());
                DAServer.Connect(url, clientHandle, ref connectInfo, out connectFailed);

                // Update our connection status
                if (!connectFailed)
                {
                    logger.Info("Connection Succeeded");
                    return true;
                }
                else
                {
                    logger.Error("Connection Failed");
                    return false;
                }
            }
            catch (Exception e)
            {
                logger.Error("Handled connect exception. Reason: " + e.Message);
                throw e;
            }
        }