//---------------------------------------------------------------------------------------------------------------------- // btnConnect_Click //----------------------- // This method tries to connect to the specified OPC Server. // If connected successfully, this method also registers the name of the client with the server and // adds an OPC Group. //---------------------------------------------------------------------------------------------------------------------- private void btnConnect_Click(object sender, EventArgs e) { TsCDaBrowseElement[] BrowserElement; TsCDaBrowsePosition BrowserPos; OpcItem Path = new OpcItem(""); _filter.BrowseFilter = TsCDaBrowseFilter.All; _filter.ReturnAllProperties = true; _filter.ReturnPropertyValues = true; try { Cursor = Cursors.WaitCursor; if (!_myServer.IsConnected) { // No connection to server, connect to it _textBoxServerUrl.Enabled = false; _myServer.Connect(_textBoxServerUrl.Text); // Connect now with Server BrowserElement = _myServer.Browse(Path, _filter, out BrowserPos); /// All succeeded, update buttons and text fields _textBoxServerUrl.Enabled = false; _btnConnect.Text = "Disconnect"; BrowseCTRL.ShowSingleServer(_myServer, _filter); PropertiesCTRL.Initialize(null); } else { // connection to server exists, disconnect to it _textBoxServerUrl.Enabled = true; BrowseCTRL.Clear(); PropertiesCTRL.Initialize(null); _myServer.Disconnect(); _btnConnect.Text = "Connect"; } Cursor = Cursors.Default; // Set default cursor } catch (OpcResultException exe) { Cursor = Cursors.Default; /// Set default cursor MessageBox.Show(exe.Message, exe.Source, MessageBoxButtons.OK, MessageBoxIcon.Warning); _textBoxServerUrl.Enabled = true; _btnConnect.Text = "Connect"; } catch (Exception ex) { Cursor = Cursors.Default; /// Set default cursor MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Warning); _textBoxServerUrl.Enabled = true; _btnConnect.Text = "Connect"; } }