/// Connect to selected client /** Parameter "URL" must be either "DEVICE" or "SIMULATOR". No other inputs supported for now. * Simulator and device URLs hard-coded into controller. Support for other URLs can be added later. * <param name="URL">"SIMULATOR" or "DEVICE"</param> */ public void connectClient(string URL) { // Physical device if selected if (URL == "DEVICE") { this.URL = DEVICE_URL; } // Simulator by default else { this.URL = SIMULATOR_URL; } // Try connecting to client try { simulatorParams = new Tut.MppOpcUaClientLib.MppClient.MppClientCtorParams(this.URL); client = new Tut.MppOpcUaClientLib.MppClient(simulatorParams); startListener(); assignUnits(); //Handle exception if failed } catch (Exception e) { Console.WriteLine("------- ERROR CONNECTING--------"); Console.WriteLine(e); Console.WriteLine("------- --------"); throw; } }
/// <summary> /// Connect to the system and subscribe to listen for changes in values. Base code from course material /// </summary> /// <param name="url">URL for the system to be connected to</param> public void connect(string url) { try { // Create a new MPP client instance var ctorParams = new UaLib.MppClient.MppClientCtorParams(url); m_mppClient = new UaLib.MppClient(ctorParams); // Signing up for events m_mppClient.ProcessItemsChanged += m_mppClient_ProcessItemsChanged; // Adding process items to subscription. // A ProcessItemsChanged event will instantly be raised after // addToSubscription() has been called! m_mppClient.ConnectionStatus += M_mppClient_ConnectionStatus; foreach (var key in INT_ITEMS) { m_mppClient.addToSubscription(key); } foreach (var key in BOOL_ITEMS) { m_mppClient.addToSubscription(key); } foreach (var key in DOUBLE_ITEMS) { m_mppClient.addToSubscription(key); } } catch (Exception e) { // Handle the exception... Console.WriteLine("Error connecting listener: " + e.Message); } }