I am working on a BLE application. I am able to connect to MI band and get the services through my Xamarin forms BLE app. But when I am trying to write characteristics I am getting exception. I'm getting exception
Characteristic does not support write.
for the method WriteAsync()
. This is my code where I am writing to characteristics:
private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
{
try
{
await adapter.ConnectToDeviceAsync(device);
var sb = new StringBuilder("Getting information from Device Information service: \n");
var characteristics = await deviceInfoService.GetCharacteristicsAsync();
var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002A27-0000-1000-8000-00805F9B34FB"));
// characteristic.CanWrite = true;
//foreach (var characteristic in characteristics)
//{
try
{
// await Task.Delay(300);
var bytes = await characteristic.ReadAsync();
var str = Encoding.UTF8.GetString(bytes, 0, 0);
ManufacturerLabel.Text = str;
//var characteristic = await deviceInfoService.GetCharacteristicAsync(GattCharacteristicIdentifiers.DataExchange);
if (characteristic != null)
{
byte[] senddata = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(SendMessageLabel.Text) ? "jenx.si was here" : SendMessageLabel.Text);
await Task.Delay(300);
var newbytes = await characteristic.WriteAsync(senddata);
var strnew = Encoding.UTF8.GetString(senddata, 0, 0);
ManufacturerLabel.Text = newbytes.ToString();
//var strnew = Encoding.UTF8.GetString(newbytes, 0, 0);
}
// ManufacturerLabel.Text = str;
}
catch (Exception ex)
{
return ex.Message;
}
//}
return sb.ToString();
}
I have no clue how to fix this any suggestions?