示例#1
0
        private async void GattScanner_OnReceived(object sender, BluetoothManager.BluetoothDevice e)
        {
            System.Diagnostics.Debug.WriteLine("(Name: " + e.Name + " Address: " + BluetoothUtils.AddressInt64ToString(e.Address) + ")");
            if (e.Name.Contains("xj"))
            {
                System.Diagnostics.Debug.WriteLine("Got you");
                BluetoothManager.Instance.GattScanner.StopScan();
            }
            else
            {
                return;
            }
            var gattClient = await e.ConnectToGattServerAsync();

            if (gattClient != null)
            {
                System.Diagnostics.Debug.WriteLine("Connected");
                int serviceCount = 0;
                IGattClientService[] services = null;
                while (serviceCount == 0)
                {
                    System.Diagnostics.Debug.WriteLine("No Service");
                    services = await gattClient.DiscoverAllPrimaryServiceAsync();

                    serviceCount = services.Length;
                }
                foreach (var service in services)
                {
                    System.Diagnostics.Debug.WriteLine("SERVICE:" + service.Uuid);
                    var characteristics = await service.DiscoverAllCharacteristicsAsync();

                    foreach (var characteristic in characteristics)
                    {
                        System.Diagnostics.Debug.WriteLine("CHARACTERISTIC:" + characteristic.Uuid);
                        byte[] value = (await characteristic.ReadCharacteristicValueAsync()).Value;
                        if (value == null)
                        {
                            System.Diagnostics.Debug.WriteLine("CHARACTERISTIC VALUE: NULL");
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("CHARACTERISTIC VALUE: " + Encoding.ASCII.GetString(value));
                        }
                    }
                }
            }
        }
示例#2
0
 private void BluetoothLEWatcher_Received(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
 {
     BluetoothManager.BluetoothDevice bluetoothDevice = BluetoothManager.BluetoothDevice.GetBluetoothDeviceFromUwpLEAdvertisementReceivedEventArgs(BluetoothManager, args);
     OnReceived?.Invoke(this, bluetoothDevice);
 }