/// <summary> /// Called to disconnect from a server. /// </summary> public void OnDisconnect() { try { // close notification callbacks. EventListCTRL.RemoveSubscriptions(); // disconnect server. if (m_server != null) { try { m_server.Disconnect(); } catch {} m_server.Dispose(); m_server = null; } // uninitialize controls. StatusCTRL.Start(null); SubscriptionsCTRL.ShowSubscriptions(null); OutputCTRL.Text = ""; } catch (Exception e) { MessageBox.Show(e.Message, "Disconnect Server Failed"); } }
/// <summary> /// Called to disconnect from a server. /// </summary> public void OnDisconnect() { try { // close notification callbacks. eventListCtrl_.RemoveSubscriptions(); // disconnect server. if (server_ != null) { try { server_.Disconnect(); } catch { } server_.Dispose(); server_ = null; } // uninitialize controls. statusCtrl_.Start(null); subscriptionsCtrl_.ShowSubscriptions(null); outputCtrl_.Text = ""; } catch (Exception e) { MessageBox.Show(e.Message, "Disconnect Server Failed"); } }
public void Run() { try { const string serverUrl = "opcae://localhost/Technosoftware.AeSample"; Console.WriteLine(); Console.WriteLine("Simple OPC AE Client based on the OPC AE Client SDK .NET Standard"); Console.WriteLine("-----------------------------------------------------------------"); Console.Write(" Press <Enter> to connect to "); Console.WriteLine(serverUrl); Console.ReadLine(); Console.WriteLine(" Please wait..."); TsCAeServer myAeServer = new TsCAeServer(); // Connect to the server myAeServer.Connect(serverUrl); Console.WriteLine(" Connected, press <Enter> to create an active subscription and press <Enter>"); Console.WriteLine(" again to deactivate the subscription. This stops the reception of new events."); Console.ReadLine(); TsCAeSubscriptionState state = new TsCAeSubscriptionState { Active = true, BufferTime = 0, MaxSize = 0, ClientHandle = 100, Name = "Simple Event Subscription" }; TsCAeCategory[] categories = myAeServer.QueryEventCategories((int)TsCAeEventType.Condition); TsCAeAttribute[] attributes = null; attributes = myAeServer.QueryEventAttributes(categories[0].ID); int[] attributeIDs = new int[2]; attributeIDs[0] = attributes[0].ID; attributeIDs[1] = attributes[1].ID; TsCAeSubscription subscription; subscription = (TsCAeSubscription)myAeServer.CreateSubscription(state); subscription.DataChangedEvent += OnDataChangedEvent; subscription.SelectReturnedAttributes(categories[0].ID, attributeIDs); Console.ReadLine(); subscription.DataChangedEvent -= OnDataChangedEvent; Console.WriteLine(" Subscription deactivated, press <Enter> to remove the subscription and disconnect from the server."); subscription.Dispose(); // Remove subscription myAeServer.Disconnect(); // Disconnect from server myAeServer.Dispose(); // Dispose server object Console.ReadLine(); Console.WriteLine(" Disconnected from the server."); Console.WriteLine(); } catch (OpcResultException e) { Console.WriteLine(String.Format(" {0}", e.Message)); Console.ReadLine(); return; } catch (Exception e) { Console.WriteLine(String.Format(" {0}", e.Message)); Console.ReadLine(); return; } }