Example #1
0
        internal Task <bool> WriteValueAsyncTask(BluetoothGattAttributeHandle handle)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            Interop.Bluetooth.BtGattClientRequestCompletedCallback cb = (result, requestHandle, userData) =>
            {
                if (result == (int)BluetoothError.None)
                {
                    tcs.SetResult(true);
                }
                else
                {
                    tcs.SetResult(false);
                }
            };

            int err = Interop.Bluetooth.BtGattClientWriteValue(handle, cb, IntPtr.Zero);

            if (err.IsFailed())
            {
                GattUtil.Error(err, "Failed to write value to remote device");
                tcs.SetResult(false);
                BluetoothErrorFactory.ThrowBluetoothException(err);
            }
            return(tcs.Task);
        }
Example #2
0
        internal BluetoothGattClientImpl(string remoteAddress)
        {
            _readValueCallback  = ReadValueCallback;
            _writeValueCallback = WriteValueCallback;

            if (BluetoothAdapter.IsBluetoothEnabled)
            {
                int err = Interop.Bluetooth.BtGattClientCreate(remoteAddress, out _handle);
                GattUtil.ThrowForError(err, "Failed to get native client handle");
            }
            else
            {
                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
            }
        }