private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { IsServiceInitialized = false; // This is an appropriate place to save to persistent storage any datapoint the application cares about. // For the purpose of this sample we just discard any values. datapoints.Clear(); // Allow the GattDeviceService to get cleaned up by the Windows Runtime. // The Windows runtime will clean up resources used by the GattDeviceService object when the application is // suspended. The GattDeviceService object will be invalid once the app resumes, which is why it must be // marked as invalid, and reinitalized when the application resumes. if (service != null) { service.Dispose(); service = null; } if (characteristic != null) { characteristic = null; } if (watcher != null) { watcher.Stop(); watcher = null; } }
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) { 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); } } }
/// <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); } } }
private void Stop() { Log("Stopping HRP"); if (characteristic != null) { Log("Clearing GattCharacteristic"); characteristic.ValueChanged -= characteristic_ValueChanged; characteristic = null; } if (watcher != null) { Log("Clearing device changed watcher"); watcher.Stop(); watcher = null; } if (service != null) { Log("Clearing GattDeviceService"); service.Dispose(); service = null; } running = false; }
private void StartDeviceConnectionWatcher() { this.watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty); this.watcher.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) { // this.watcher.Stop(); // this.watcher = null; if (true == isConnected) { if (null != this.Connected) { this.Connected(this, this); } } else { if (null != this.Disconnected) { this.Disconnected(this, this); } } } }; this.watcher.Start(); }
/// <summary> /// Register to be notified when a connection is established to the Bluetooth device /// </summary> private void StartDeviceConnectionWatcher() { watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty); watcher.Updated += DeviceConnection_Updated; watcher.Start(); }
public void UnregisterForConnectionEvents() { if (_connectionWatcher != null) { _connectionWatcher.Updated -= DeviceConnection_Updated; _connectionWatcher.Stop(); _connectionWatcher = null; } }
private void StartDeviceConnectionWatcher() { watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { "System.Devices.Connected" }, String.Empty); Log("Registering device connection watcher updated event handler"); watcher.Updated += DeviceConnection_Updated; Log("Starting device connection watcher"); watcher.Start(); }
/// <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); } }
public override void Stop() { if (Running) { #if DEBUG logger.Debug("Stopping HRP"); #endif Running = false; #if DEBUG logger.Debug("Stopping timeout timer"); #endif timeoutTimer.Stop(); if (characteristic != null) { #if DEBUG logger.Debug("Clearing GattCharacteristic"); #endif characteristic.ValueChanged -= Characteristic_ValueChanged; characteristic = null; } if (watcher != null) { #if DEBUG logger.Debug("Clearing device changed watcher"); #endif watcher.Stop(); watcher = null; } if (service != null) { #if DEBUG logger.Debug("Clearing GattDeviceService"); #endif service.Dispose(); service = null; } #if DEBUG logger.Debug("Resetting counters"); #endif DoReset(); } }
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); } }
private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e) { IsServiceInitialized = false; // This is an appropriate place to save to persistent storage any datapoint the application cares about. // Let us save the last known state of the backpack var lastItem = datapoints.Last(); localSettings.Values["last-backpack-state"] = lastItem.ToString(); // Then clear the information datapoints.Clear(); // Allow the GattDeviceService to get cleaned up by the Windows Runtime. // The Windows runtime will clean up resources used by the GattDeviceService object when the application is // suspended. The GattDeviceService object will be invalid once the app resumes, which is why it must be // marked as invalid, and reinitalized when the application resumes. if (service != null) { service.Dispose(); service = null; } if (rx_characteristic != null) { rx_characteristic = null; } if (tx_characteristic != null) { tx_characteristic = null; } if (watcher != null) { watcher.Stop(); watcher = null; } }
//Stops the service internal void Stop() { IsServiceInitialized = false; _datapoints.Clear(); if (_service != null) { _service.Dispose(); } if (_characteristic != null) { _characteristic = null; } if (_watcher != null) { _watcher.Stop(); _watcher = null; } }
public override void Dispose() { if (characteristic != null) { characteristic.ValueChanged -= Characteristic_ValueChanged; characteristic = null; } if (watcher != null) { watcher.Stop(); watcher = null; } if (service != null) { service.Dispose(); service = null; } }
async Task <bool> RegisterForConnectionEvents() { UnregisterForConnectionEvents(); string deviceContainerId = "{" + DeviceContainerId + "}"; PnpObject containerPnpObject = await PnpObject.CreateFromIdAsync(PnpObjectType.DeviceContainer, deviceContainerId, new string[] { CONNECTED_FLAG_PROPERTY_NAME }); var connectedProperty = containerPnpObject.Properties[CONNECTED_FLAG_PROPERTY_NAME]; bool isConnected = false; Boolean.TryParse(connectedProperty.ToString(), out isConnected); _connectionWatcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { CONNECTED_FLAG_PROPERTY_NAME }, String.Empty); _connectionWatcher.Updated -= DeviceConnection_Updated; _connectionWatcher.Updated += DeviceConnection_Updated; _connectionWatcher.Start(); return(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"); } } }
private void StartDeviceConnectionWatcher() { _watcher = PnpObject.CreateWatcher(PnpObjectType.DeviceContainer, new string[] { ConnectedProperty }, String.Empty); _watcher.Updated += DeviceConnection_Updated; _watcher.Start(); }