コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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
                }
            }
        }
コード例 #3
0
 public void UnregisterForConnectionEvents()
 {
     if (_connectionWatcher != null)
     {
         _connectionWatcher.Updated -= DeviceConnection_Updated;
         _connectionWatcher.Stop();
         _connectionWatcher = null;
     }
 }
コード例 #4
0
        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);
            }
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        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");
                }
            }
        }