/// <summary> /// Invoked when a connection is established to the Bluetooth device /// </summary> /// <param name="sender">The watcher object that sent the notification</param> /// <param name="args">The updated device object properties</param> private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { var status = await rx_characteristic.WriteClientCharacteristicConfigurationDescriptorAsync( RX_CHARACTERISTIC_NOTIFICATION_TYPE); if (status == GattCommunicationStatus.Success) { IsServiceInitialized = true; // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required watcher.Stop(); watcher = null; } // Notifying subscribers of connection state updates if (DeviceConnectionUpdated != null) { DeviceConnectionUpdated(isConnected); } } }
private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { #if DEBUG logger.Debug("Device connection updated, args = " + args); #endif var connectedProperty = args.Properties["System.Devices.Connected"]; #if DEBUG logger.Debug("Connected property, args = " + connectedProperty.ToString()); #endif bool isConnected = false; if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { var status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync( CHARACTERISTIC_NOTIFICATION_TYPE); if (status == GattCommunicationStatus.Success) { #if DEBUG logger.Debug("Stopping device connection watcher"); #endif // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required watcher.Stop(); watcher = null; #if DEBUG logger.Debug("Configuration successfull"); #endif } } }
/// <summary> /// Invoked when a connection is established to the Bluetooth device /// </summary> /// <param name="sender">The watcher object that sent the notification</param> /// <param name="args">The updated device object properties</param> private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { foreach (GattCharacteristic ch in notify_characteristics) { GattCommunicationStatus notify_status = await EnableNotificationAsync(ch); if (notify_status == GattCommunicationStatus.Success) { IsServiceInitialized = true; // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required watcher.Stop(); watcher = null; } } // Notifying subscribers of connection state updates if (DeviceConnectionUpdated != null) { DeviceConnectionUpdated(isConnected); } } }
/// <summary> /// Invoked when a connection is established to the Bluetooth device /// </summary> /// <param name="sender">The watcher object that sent the notification</param> /// <param name="args">The updated device object properties</param> private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; List <MyoHw> myoSender = pairedMyos.Where(p => p.deviceContainerId == args.Id).ToList(); if ((myoSender.Any()) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { ConnectUpdate(myoSender[0], isConnected); // Notifying subscribers of connection state updates myoSender[0].OnConnectUpdate(isConnected); } }
private void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties[CONNECTED_FLAG_PROPERTY_NAME]; bool isConnected = false; string deviceContainerId = "{" + DeviceContainerId + "}"; Debug.WriteLine("DeviceConnection_Updated: " + connectedProperty.ToString()); if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected)) { if (!_connected && isConnected) { var nowait = Task.Run(new Action(() => { ReregisterAllValueChangeEvents(); })); } OnConnectionChanged(isConnected); } }
private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties[ConnectedProperty]; bool isConnected = false; if ((_deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { var status = await _characteristic.WriteClientCharacteristicConfigurationDescriptorAsync(CHARACTERISTIC_NOTIFICATION_TYPE); if (status == GattCommunicationStatus.Success) { IsServiceInitialized = true; _watcher.Stop(); _watcher = null; } DeviceConnectionUpdated?.Invoke(isConnected); } }
/// <summary> /// Invoked when a connection is established to the Bluetooth device /// </summary> /// <param name="sender">The watcher object that sent the notification</param> /// <param name="args">The updated device object properties</param> private void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; if ((selectedDeviceContainerID == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { foreach (MetaWearController.DeviceCallbacks dc in deviceCallbacks) { dc.connected(); } } else if (selectedDeviceContainerID == args.Id) { foreach (MetaWearController.DeviceCallbacks dc in deviceCallbacks) { dc.disconnected(); } } }
private async void DeviceConnection_Updated(PnpObjectWatcher sender, PnpObjectUpdate args) { Log("Device connection updated, args = " + args); var connectedProperty = args.Properties["System.Devices.Connected"]; bool isConnected = false; if ((deviceContainerId == args.Id) && Boolean.TryParse(connectedProperty.ToString(), out isConnected) && isConnected) { var status = await characteristic.WriteClientCharacteristicConfigurationDescriptorAsync( GattClientCharacteristicConfigurationDescriptorValue.Notify); if (status == GattCommunicationStatus.Success) { Log("Stopping device connection watcher"); // Once the Client Characteristic Configuration Descriptor is set, the watcher is no longer required watcher.Stop(); watcher = null; Log("Configuration successfull"); } } }