Example #1
0
 /// <summary>
 /// Clear notifications on a characteristic, enqueueing the request
 /// </summary>
 /// <param name="iCharacteristic"></param>
 /// <param name="iDataSentCallback">Callback class with which to return the clear notification results</param>
 /// <returns>True if requested characteristic has been loaded</returns>
 public bool ClearCharacteristicNotification(Guid iCharacteristic, DeviceDataSentCallBack iDataSentCallback)
 {
     if (_characteristics.TryGetValue(iCharacteristic, out BluetoothGattCharacteristic characteristic))
     {
         DisableNotifications(characteristic).With(iDataSentCallback).Fail(iDataSentCallback).Enqueue();
         return(true);
     }
     return(false);
 }
Example #2
0
 /// <summary>
 /// Write data to the characteristic, enqueueing the request
 /// </summary>
 /// <param name="iCharacteristic">Guid representing the characteristic</param>
 /// <param name="iData">Data to be sent</param>
 /// <param name="iDataSentCallback">Callback class with which to return the write results</param>
 /// <returns>True if requested characteristic has been loaded</returns>
 public bool WriteCharacteristicData(Guid iCharacteristic, byte[] iData, DeviceDataSentCallBack iDataSentCallback)
 {
     if (_characteristics.TryGetValue(iCharacteristic, out BluetoothGattCharacteristic characteristic))
     {
         WriteCharacteristic(characteristic, iData).With(iDataSentCallback).Fail(iDataSentCallback).Enqueue();
         return(true);
     }
     iDataSentCallback?.OnRequestFailed(_currentDevice, (int)GattStatus.Failure);
     return(false);
 }
Example #3
0
        /// <summary>
        /// Enable notifications on a characteristic, enqueueing the request
        /// </summary>
        /// <param name="iCharacteristic"></param>
        /// <param name="iDataReceivedCallback">Callback class with which to return the notification read results</param>
        /// <param name="iDataSentCallback">Callback class with which to return the set notification results</param>
        /// <returns>True if requested characteristic has been loaded</returns>
        public bool EnableCharacteristicNotification(Guid iCharacteristic, IDataReceivedCallback iDataReceivedCallback, DeviceDataSentCallBack iDataSentCallback)
        {
            if (_characteristics.TryGetValue(iCharacteristic, out BluetoothGattCharacteristic characteristic))
            {
                // Set up notification callback for receiving data from the gateway
                SetNotificationCallback(characteristic).With(iDataReceivedCallback);

                // Enable the notifications and enqueue the request
                EnableNotifications(characteristic).With(iDataSentCallback).Fail(iDataSentCallback).Enqueue();

                return(true);
            }
            return(false);
        }