private void EpConnectButton_Click(object sender, EventArgs e) { //Check if sessions exists; If yes > delete subscriptions and disconnect if (mySession != null && !mySession.Disposed) { try { //mySubscription.Delete(true); } catch { ; } myClientHelperAPI.Disconnect(); mySession = myClientHelperAPI.Session; ResetUI(); } else { try { //Register mandatory events (cert and keep alive) myClientHelperAPI.KeepAliveNotification += new KeepAliveEventHandler(Notification_KeepAlive); myClientHelperAPI.CertificateValidationNotification += new CertificateValidationEventHandler(Notification_ServerCertificate); //Check for a selected endpoint if (mySelectedEndpoint != null) { //Call connect myClientHelperAPI.Connect(mySelectedEndpoint, userPwButton.Checked, userTextBox.Text, pwTextBox.Text).Wait(); //Extract the session object for further direct session interactions mySession = myClientHelperAPI.Session; //UI settings epConnectServerButton.Text = "Disconnect from server"; browsePage.Enabled = true; monitoringPage.Enabled = true; myCertForm = null; } else { MessageBox.Show("Please select an endpoint before connecting", "Error"); return; } } catch (Exception ex) { myCertForm = null; ResetUI(); MessageBox.Show(ex.InnerException.Message, "Error"); } } }
private void DisconnectB_Click(object sender, EventArgs e) { string lastServer = myHelperApi.Session.Endpoint.Server.ApplicationUri; myHelperApi.Disconnect(); mySession = null; DisconnectB.Enabled = false; ConnectB.Enabled = true; ConnectionStatusLabel.Text = "Disconnected"; ConnectionStatusLabel.ForeColor = Color.Red; // AddLogCallback("Client", "Disconnected from " + lastServer, true); }
/// <summary> /// 断开连接 /// </summary> /// <returns></returns> public bool Disconnect() { RemoveSubscription(); uAClient.RemoveSubscription(_Subscription); uAClient.Disconnect(); return(true); }
/// <summary> /// Disconnect from the UA server. /// </summary> private void btnDisconnect_Click(object sender, EventArgs e) { try { if (m_Subscription != null) { btnMonitor_Click(null, null); } if (m_SubscriptionBlock != null) { btnMonitorBlock_Click(null, null); } // Disconnect from Server m_Server.Disconnect(); // Toggle enable flag of buttons toggleButtons(false); } catch (Exception ex) { MessageBox.Show("Disconnect failed:\n\n" + ex.Message); } }
private void Notification_KeepAlive(Session sender, KeepAliveEventArgs e) { if (this.InvokeRequired) { this.BeginInvoke(new KeepAliveEventHandler(Notification_KeepAlive), sender, e); return; } // check for events from discarded sessions. if (!Object.ReferenceEquals(sender, mySession)) { return; } // check for disconnected session. if (!ServiceResult.IsGood(e.Status)) { // UpdateLog("Client", "Lost connection to server; Reconnect failed", false); //Release connection try { myHelperApi.RemoveSubscription(mySubscription); } catch { ; } myHelperApi.Disconnect(); mySession = myHelperApi.Session; // ClearUI(); } }
public int Disconnect() { try { m_Server.Disconnect(); m_Connected = false; return(0); } catch { return(-1); } }
public void destroy() { try { if (opcSession != null) { //Call connect myClientHelperAPI.Disconnect(); opcSession = null; log.Info("PLCHandler disconnect successfull"); } } catch (Exception exp) { log.Error("Error in PLCHandler.destroy()", exp); } }
public void destroy() { try { this.isRunning = false; if (opcSession != null) { //Call connect myClientHelperAPI.Disconnect(); opcSession = null; log.Info("OPC disconnect successfull"); } } catch (Exception exp) { log.Info("opcDisConnect error = " + exp); } }
public void Disconnect() { myClientHelperAPI.Disconnect(); mySession = myClientHelperAPI.Session; var page = (Page)HttpContext.Current.CurrentHandler; string url = page.AppRelativeVirtualPath; if (url == "~/Connect.aspx") { ControlDisable(); ResetUI(); } else { Server.Transfer("Connect.aspx"); } ClientScript.RegisterStartupScript(this.GetType(), "Success", "messtimer('success','Disconnect Successfully')", true); }
/// <summary> /// Disconnect from server. /// </summary> private int Disconnect() { int result; try { // Call the disconnect service of the server. monitoredItemsControl.RemoveSubscription(); m_Server.Disconnect(); result = 1; // State is disconnected now. ConnectDisconnectBTN.Text = "Connect"; UrlCB.Enabled = true; // Disconnect succeeded. m_Connected = false; // Update status label. toolStripStatusLabel.Text = "Disconnected from server"; toolStripStatusLabel.Image = global::Siemens.OpcUA.Client.Properties.Resources.success; } catch (Exception e) { result = -1; // Update status label. toolStripStatusLabel.Text = "An exception occured during disconnect: " + e.Message; toolStripStatusLabel.Image = global::Siemens.OpcUA.Client.Properties.Resources.error; } // Cleanup attribute list. this.attributeListControl.AttributeList.Items.Clear(); // Cleanup monitored items list. this.monitoredItemsControl.MonitoredItemsList.Items.Clear(); // Cleanup treeview. browseControl.BrowseTree.BeginUpdate(); browseControl.BrowseTree.Nodes.Clear(); browseControl.BrowseTree.EndUpdate(); return(result); }
private void EpConnectServerButton_Click(object sender, EventArgs e) { var classOPCUA = new OPCUA(); //Check if sessions exists; If yes > delete subscriptions and disconnect if (mySession != null && !mySession.Disposed) { myClientHelperAPI.Disconnect(); mySession = myClientHelperAPI.Session; ResetUI(); } else { try { //Register mandatory events (cert and keep alive) myClientHelperAPI.KeepAliveNotification += new KeepAliveEventHandler(classOPCUA.Notification_KeepAlive); myClientHelperAPI.CertificateValidationNotification += new CertificateValidationEventHandler(classOPCUA.Notification_ServerCertificate); //Check for a selected endpoint if (mySelectedEndpoint != null) { //Call connect myClientHelperAPI.Connect(mySelectedEndpoint, userPwButton.Checked, userTextBox.Text, pwTextBox.Text); //Extract the session object for further direct session interactions mySession = myClientHelperAPI.Session; //UI settings epConnectServerButton.Text = "Disconnect from server"; //myCertForm = null; if (descriptionGridView.Enabled == false) { descriptionGridView.Enabled = true; descriptionGridView.BackgroundColor = SystemColors.Window; nodeTreeView.Enabled = true; nodeTreeView.BackColor = SystemColors.Window; numericS7RecordsCount.Enabled = true; numericS7RecordsCount.BackColor = SystemColors.Window; textBoxSQLTableName.Enabled = true; textBoxSQLTableName.BackColor = SystemColors.Window; textBoxSQLIDColName.BackColor = SystemColors.Window; textBoxSQLIDColName.Enabled = true; textBoxSQLValColName.BackColor = SystemColors.Window; textBoxSQLValColName.Enabled = true; textBoxSQLDATColName.BackColor = SystemColors.Window; textBoxSQLDATColName.Enabled = true; } if (Config.Sets.Primary_ODBC_DSN != "") { connStringBuilder.Dsn = Config.Sets.Primary_ODBC_DSN; connStringBuilder.Add("Uid", Config.Sets.Primary_ODBC_User); connStringBuilder.Add("Pwd", Config.Sets.Primary_ODBC_Pass); } if (Config.Sets.Primary_OPCUA_Node != "") { //discoveryTextBox.Text = Config.Sets.Primary_OPCUA_Node; textBoxS7DBName.Text = Config.Sets.Primary_S7_DBName; textBoxS7RecArrayName.Text = Config.Sets.Primary_OPCUA_RecArray; textBoxS7RecResetCountName.Text = Config.Sets.Primary_OPCUA_RecResetCount; } if (Config.Sets.Primary_SQL_NumberOfRec != 0) { numericS7RecordsCount.Value = Config.Sets.Primary_SQL_NumberOfRec; textBoxSQLTableName.Text = Config.Sets.Primary_SQL_TableName; textBoxSQLIDColName.Text = Config.Sets.Primary_SQL_IDColName; textBoxSQLValColName.Text = Config.Sets.Primary_SQL_ValColName; textBoxSQLDATColName.Text = Config.Sets.Primary_SQL_DATColName; buttonSaveConfig.Enabled = true; buttonSaveConfig.BackColor = Color.Transparent; } if (myReferenceDescriptionCollection == null) { try { myReferenceDescriptionCollection = myClientHelperAPI.BrowseRoot(); foreach (ReferenceDescription refDesc in myReferenceDescriptionCollection) { nodeTreeView.Nodes.Add(refDesc.DisplayName.ToString()).Tag = refDesc; foreach (TreeNode node in nodeTreeView.Nodes) { node.Nodes.Add(""); } } } catch (Exception ex) { if (BGW_OPCUA.IsBusy) { BGW_OPCUA.CancelAsync(); } MessageBox.Show(ex.Message, "Error"); } } } else { MessageBox.Show("Please select an endpoint before connecting", "Error"); return; } } catch (Exception ex) { if (BGW_OPCUA.IsBusy) { BGW_OPCUA.CancelAsync(); } //myCertForm = null; MessageBox.Show(ex.Message, "Error"); } } }