// Set the alert-level characteristic on the remote device public async Task SetAlertLevelCharacteristic() { // try-catch block protects us from the race where the device disconnects // just after we've determined that it is connected. try { byte[] data = new byte[1]; data[0] = (byte)alertLevel; // The LinkLoss service should contain exactly one instance of the AlertLevel characteristic GattCharacteristic characteristic = linkLossService.GetCharacteristics(GattCharacteristicUuids.AlertLevel)[0]; await characteristic.WriteValueAsync(data.AsBuffer(), GattWriteOption.WriteWithResponse); } catch (Exception) { // ignore exception } }
private void GetAllCharacteristics(List <GattCharacteristic> characteristics) { #if WINDOWS_UWP || WINDOWS_PHONE_APP foreach (Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic characteristic in _service.GetAllCharacteristics()) { characteristics.Add(characteristic); } #elif WINDOWS_PHONE || WINDOWS_APP foreach (Windows.Devices.Bluetooth.GenericAttributeProfile.GattCharacteristic characteristic in _service.GetCharacteristics(Guid.Empty)) { characteristics.Add(characteristic); } #endif }