/// <summary> /// Callback method that MdsLib calls when a device connects or disconnects /// </summary> /// <param name="mdsevent">details of device connection/disconnection</param> public void OnDeviceConnectionEvent(MDSEvent mdsevent) { var method = ((NSString)mdsevent.BodyDictionary.ValueForKey(new NSString("Method"))); if (method == new NSString("POST")) { // Device connected var bodyDict = (NSDictionary)mdsevent.BodyDictionary.ValueForKey(new NSString("Body")); var serial = (NSString)bodyDict.ValueForKey(new NSString("Serial")); var connDict = (NSDictionary)bodyDict.ValueForKey(new NSString("Connection")); var uuid = (NSString)connDict.ValueForKey(new NSString("UUID")); Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent CONNECTED: Serial {serial}"); ConnectionComplete?.Invoke(this, new MdsConnectionListenerEventArgs(serial, new Guid(uuid))); } else if (method == new NSString("DEL")) { // Device disconnected var serial = ((NSString)mdsevent.BodyDictionary.ValueForKey(new NSString("Serial"))); Debug.WriteLine($"MdsConnectionListener OnDeviceConnectionEvent DISCONNECTED: Serial {serial}"); Disconnect?.Invoke(this, new MdsConnectionListenerEventArgs(serial)); } else { throw new MdsException($"OnDeviceConnectionEvent unexpected method: {method}"); } }
private void MakeConnection() { WriteLine("Attempting to connect to " + this.aEndPoint.ToString() + "..."); try { this.pClient.Connect(this.aEndPoint); this.tPing = new Thread(new ThreadStart(SendPing)); ConnectionComplete?.Invoke(this, new EventArgs()); } catch (SocketException e) { ConnectionError?.Invoke(e); WriteError(e); } if (this.tPing != null) { this.tPing.Start(); } }
/// <summary> /// Callback method that MdsLib calls when connection of a device has completed /// </summary> /// <param name="MACaddress"></param> /// <param name="serial"></param> public void OnConnectionComplete(string MACaddress, string serial) { Debug.WriteLine($"SUCCESS MdsConnectionListener OnConnectionComplete callback called: MACaddress {MACaddress} Serial {serial}"); ConnectionComplete?.Invoke(this, new MdsConnectionListenerEventArgs(MACaddress)); }