コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: vadimas/events
        private async void ButtonAction1_Click(object sender, RoutedEventArgs e)
        {
            DevicesInformation = $"Device Id,Name,service.Uuid,service Name,service.AttributeHandle,characteristic.Uuid,Char Name,CharacteristicProperties,Char ProtectionLevel,UserDescription,,,{Environment.NewLine}";
            Debug.WriteLine(DevicesInformation);
            var bts = await DeviceInformation.FindAllAsync();

            foreach (var device in bts.Where(di => di.Name == RsServiceDiscovery.DeviceName))
            {
                try
                {
                    var service = await GattDeviceService.FromIdAsync(device.Id);

                    if (null == service)
                    {
                        continue;
                    }
                    var characteristics = service.GetAllCharacteristics();
                    if (null == characteristics || characteristics.Count <= 0)
                    {
                        return;
                    }

                    foreach (var characteristic in characteristics)
                    {
                        try
                        {
                            var serviceName = CharacteristicUuidsResolver.GetNameFromUuid(service.Uuid);
                            var charName    = CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid);

                            string msg =
                                $"{device.Id}, {device.Name}, {service.Uuid}, {serviceName}, {service.AttributeHandle}, {characteristic.Uuid}, {charName}, {characteristic.CharacteristicProperties}, {characteristic.ProtectionLevel}, {characteristic.UserDescription}{Environment.NewLine}";
                            Debug.WriteLine(msg);
                            DevicesInformation += msg;
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }
                catch
                {
                    string msg = $"{device.Id}, {device.Name}, , , , , , , , {Environment.NewLine}";
                    Debug.WriteLine(msg);
                    DevicesInformation += msg;
                }
            }
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: vadimas/events
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            var bts = await DeviceInformation.FindAllAsync();

            const string deviceId = @"\\?\BTHLEDevice#{9a66fa00-0800-9191-11e4-012d1540cb8e}_e0144d4f3d49#a&1f09a1af&0&0020#{6e3bb679-4372-40c8-9eaa-4509df260cd8}";

            var device = bts.First(di => di.Name == DeviceName && di.Id == deviceId);

            if (null == device)
            {
                return;
            }
            _service = await GattDeviceService.FromIdAsync(device.Id);

            if (null == _service)
            {
                return;
            }
            _characteristics = _service.GetAllCharacteristics();
            if (null == _characteristics || _characteristics.Count <= 0)
            {
                return;
            }

            var characteristic = _characteristics.First(charact => charact.Uuid == RollingSpiderCharacteristicUuids.Parrot_PowerMotors);

            try
            {
                var charName = CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid);
                Debug.WriteLine(charName);
                for (int i = 0; i < 255; i++)
                {
                    Debug.WriteLine(i);
                    byte[] arr    = { (byte)02, (byte)40, (byte)20, (byte)0D, 00, 09, 00, 04, 00, 52, 43, 00, 04, (byte)i, 02, 00, 01, 00, };
                    var    writer = new DataWriter();
                    writer.WriteBytes(arr);
                    await characteristic.WriteValueAsync(writer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);

                    await Task.Delay(TimeSpan.FromSeconds(1));
                }
            }
            catch
            {
            }
        }