Esempio 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;
            }
        }
Esempio n. 2
0
        public bool Connect()
        {
            bool connect = false;

            try
            {
                String      s  = CultureInfo.CurrentCulture.Name;
                ConnectInfo ci = new ConnectInfo();
                ci.ClientName                = "Kepware.KEPServerEX.V6";
                ci.LocalId                   = s;// "en";
                ci.KeepAliveTime             = 10000;
                ci.RetryAfterConnectionError = true;
                ci.RetryInitialConnection    = true;


                ci.RetryInitialConnection = true;
                _daServerMgt = new DaServerMgt();

                bool   connectFailed = false;
                int    clientHandle  = 1;
                string url           = getOPCServeurURL();

                _daServerMgt.Connect(url, clientHandle, ref ci, out connectFailed);

                if (!connectFailed)
                {
                    connect = true;
                }
                else
                {
                }
            }
            catch (Exception e)
            {
                Writer.writeAll("Handled Connect exception. Reason: " + e.ToString());
                connect = false;
            }
            return(connect);
        }
Esempio n. 3
0
        public bool Connect(IOPCInterface o)
        {
            bool connect = false;

            connect = Connect();
            if (connect)
            {
                try
                {
                    _daServerMgt.ReadCompleted      += o.OPC_ReadCompleted;
                    _daServerMgt.DataChanged        += o.OPC_DataChanged;
                    _daServerMgt.ServerStateChanged += o.OPC_ServerStateChanged;
                }
                catch (Exception e)
                {
                    Writer.writeAll("Handled Connect exception. Reason: " + e.ToString());
                    _daServerMgt = null;
                    connect      = false;
                }
            }
            return(connect);
        }
Esempio n. 4
0
 public Form1()
 {
     _daServerMgt = new DaServerMgt();
     InitializeComponent();
     tbStatus.Text = "Not Connected";
 }
Esempio n. 5
0
 public Form1()
 {
     _daServerMgt = new DaServerMgt();
     InitializeComponent();
     tbStatus.Text = "Not Connected";
 }