public async void SendCommandTo1StChar(IReadOnlyList <GattCharacteristic> characteristics, byte[] commandToWrite) { var characteristic = characteristics[0]; Debug.WriteLine("Try to write to " + CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid)); try { var writer = new DataWriter(); writer.WriteBytes(commandToWrite); await characteristic.WriteValueAsync(writer.DetachBuffer()); } catch { } }
private static void ValidateChars(string deviceId, GattDeviceService service, Guid charsUuid) { var chars = service.GetCharacteristics(charsUuid); if (chars == null || chars.Count == 0) { return; } var charsName = CharacteristicUuidsResolver.GetNameFromUuid(charsUuid); Debug.WriteLine($" {chars.Count} found for {charsName}"); foreach (GattCharacteristic characteristic in chars) { var charName = CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid); var friendlyDesc = characteristic.UserDescription; Debug.WriteLine($" {charName} - {friendlyDesc} - {characteristic.ProtectionLevel}"); } }
public async void LoadDevicesCharacteristics(List <DeviceInformation> parrotDevices) { foreach (var device in parrotDevices) { try { var service = await GattDeviceService.FromIdAsync(device.Id); if (null == service) { continue; } var characteristics = service.GetAllCharacteristics(); if (null == characteristics || characteristics.Count <= 0) { return; } Debug.WriteLine($"{characteristics.Count} chars found for {device.Id}"); AddLogAction($"{characteristics.Count} chars found for {device.Id}"); foreach (var characteristic in characteristics) { try { var charName = CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid); Debug.WriteLine("char name: " + charName); AddLogAction($"{characteristics.Count} chars found for {device.Id}"); // read properties Debug.WriteLine("char name: " + characteristic.CharacteristicProperties); } catch { } } } catch { Debug.WriteLine("0 chars found for " + device.Id); } } }
public async void SendCommandToAllChar(IReadOnlyList <GattCharacteristic> characteristics, byte[] commandToWrite) { foreach (var characteristic in characteristics) { Debug.WriteLine("Try to write to " + CharacteristicUuidsResolver.GetNameFromUuid(characteristic.Uuid)); try { var writer = new DataWriter(); writer.WriteBytes(commandToWrite); await characteristic.WriteValueAsync(writer.DetachBuffer()); Debug.WriteLine("Write sucessfull"); } catch { Debug.WriteLine("Write error"); } } }