//---------------------------------------------------------------------------------------------------------------------- // 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"; } }
/// <summary> /// UI: close current server session, and clear related contents from UI /// <summary> public void CloseSessionView_OpcuaClient(bool resetUIButton = true) { Opcua_EndpointDisconnect(); if (resetUIButton) { var ignored = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { BrowseCTRL.Clear(); SessionsCTRL.Clear(); gridEndpointSelector.Visibility = Visibility.Collapsed; EndpointSelectorCTRL.Visibility = Visibility.Visible; EndpointSelectorCTRL.IsEnabled = true; EnableSessionOpButtons(true); }); } }
async void Window_PageClosing(object sender, RoutedEventArgs e) { if (m_masterPage == null && m_pages.Count > 0) { MessageDlg dialog = new MessageDlg("Close all sessions?", MessageDlgButton.Yes, MessageDlgButton.No); MessageDlgButton result = await dialog.ShowAsync(); if (result != MessageDlgButton.Yes) { return; } } BrowseCTRL.Clear(); for (int ii = 0; ii < m_pages.Count; ii++) { if (Object.ReferenceEquals(m_pages[ii], sender)) { m_pages.RemoveAt(ii); break; } } }