Question Regarding Plugin.BLE Characteristic.WriteAsync

Hello,
I have a Xamarin Forms App that connects to a custom made Bluetooth LE device. I have configured my Xamarin forms App to WriteAsync to a characteristic. It works swimmingly in Android. I have a button event handler that calls a task and the Write occurs in Milliseconds. However, in iOS it does not work the same. I have debug statements that show it is called and returns true but the firmware in the BLE device never sees the call.

One thing I do notice is that if I call the function when I very first start the App it works. After the first call the state of the app changes and I wonder if it has something to do with not being called from the main thread. I did try to get it to call from the main thread but that didn't work either.

I have several Characteristics that I can ReadAsync with no problems, this is the first time I have tried to write one. Here is the code for the write.
WriteOk always returns true regardless what the BLE device hears.
public async Task ResetInhaleTimer()
{

            if (digitalData.CanWrite)
           {
        var WriteOk = await digitalData.WriteAsync(mybyte, new CancellationToken(true)).ConfigureAwait(false);
            if(!WriteOk)
            {
                Debug.WriteLine(" Writing to the Digital Char and AhHa C# Thinks it did NOT write");
           }
           else
            {
                Debug.WriteLine("Writing to the digital char and AhHa C# Thinks it did write");
            }
            }return false;


    }
Tagged:
Sign In or Register to comment.