如何阅读BluetoothGattCharacteristic属性,如特征Readable,Writable或Notifiable.
我正在尝试使用Xamarin/Android启用多个BLE特性的通知,但似乎无法这样做.如果我尝试一次启用多个BLE事件,该应用程序似乎停止接收任何BLE事件.
任何人都可以使用Tamarin/Android确认这是否可行.我们有一个原生的iOS应用程序,可以正常启用多个通知.我们使用的基本步骤如下:
每当我们尝试在多个特征上启用通知时,我们就不再接收任何事件.
我也无法找到任何启用多个特性的示例.
我希望我在这里错过了使用Xamarin/Android API的基本信息.
public override void OnServicesDiscovered (BluetoothGatt gatt, GattStatus status)
{
    base.OnServicesDiscovered (gatt, status);
    foreach (BluetoothGattService service in gatt.Services) {
        string uuid = service.Uuid.ToString ().ToUpper();
        if (uuid.Equals (BLEServices.HRService.ToUpper())) {
            _Adap.LogMessage ("HRService discovered");
            foreach(BluetoothGattCharacteristic characteristic in service.Characteristics) {
                string c_uuid = characteristic.Uuid.ToString ().ToUpper ();
                _Adap.LogMessage (" HRCharacteristic: " + c_uuid);
                if (c_uuid.Equals(_Adap.useCharacteristic.ToUpper())) {
                    _Adap.LogMessage ("  enabling HRCharacteristic");
                    gatt.SetCharacteristicNotification(characteristic, true);
                    BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor (Java.Util.UUID.FromString (BLEServices.CLIENT_CHARACTERISTIC_CONFIG), GattDescriptorPermission.Write | GattDescriptorPermission.Read);
                    characteristic.AddDescriptor (descriptor);
                    descriptor.SetValue …notifications xamarin.android characteristics bluetooth-lowenergy xamarin
我当前的代码使用一系列异步过程,最终达到结果.我需要以这样的方式包装每一个,每个都通过同步方法访问,结果作为返回值.我想使用执行程序服务来执行此操作,以便允许其中许多服务同时发生.我觉得Future可能与我的实现相关,但我无法找到一个很好的方法来实现这一点.
我现在拥有的:
public class DoAJob {
  ResultObject result;
  public void stepOne() {
    // Passes self in for a callback
    otherComponent.doStepOne(this);
  }
  // Called back by otherComponent once it has completed doStepOne
  public void stepTwo(IntermediateData d) {
    otherComponent.doStepTwo(this, d);
  }
  // Called back by otherComponent once it has completed doStepTwo
  public void stepThree(ResultObject resultFromOtherComponent) {
    result = resultFromOtherComponent;
  //Done with process
  }
}
这在内部工作得非常好,但现在我需要将我的进程映射到具有返回值的同步方法,如:
public ResultObject getResult(){
  // ??? What goes here ???
}
有没有人对如何优雅地实现它有一个好主意?
我正在开发一个从BLE设备读取数据的android应用程序.我在这里遇到了很多关于如何读取多个特征的解决方案,其中大部分都是建议的队列.
我确实实现了Queue方法,一切都在我的代码中正常工作.我开始这个主题的原因是找到最好的和最有效的解决方案,并清除我对某些BLE服务特性如何工作的疑虑.
我已经将以下两个链接作为参考,这有助于我使我的代码工作.
来源1:
来源2:
我的要求是阅读心率测量和电池水平.最初我尝试将心率和电池特性添加到队列中,然后为每个添加的元素调用读/设置方法.
主要活动:
private void displayGattServices(List<BluetoothGattService> gattServices) 
{
   // get the required service & characteristics
   ................
   ................  
   // add the characteristics via Queue
   hRM_characteristicReadQueue.add(characteristics);
   // Initiate read/set methods
   read_Characteristic();   
};
private void read_Characteristic()
 {
   bluetoothHDPService.read(hRM_characteristicReadQueue.element());
   bluetoothHDPService.set(hRM_characteristicReadQueue.element(),true);
   hRM_characteristicReadQueue.remove();
};
bluetoothHDPService:
public void read(BluetoothGattCharacteristic characteristic) 
 {
    if (bluetoothAdapter == null || bluetoothGatt == null) 
    {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    };
    bluetoothGatt.readCharacteristic(characteristic);
};
public void set(BluetoothGattCharacteristic characteristic, boolean enabled) 
{ …我正在尝试编写一个可以访问Zephyr HxM Smart心脏监护仪的蓝牙LE应用程序.此显示器有几种蓝牙服务,但我对电池服务,心率服务以及具有活动和峰值加速的自定义服务感兴趣.电池电平,(BAT),心率测量(HR)和自定义测量(CUS)各有一个特征.HxM每秒更新一次.
我正在使用Android 4.4的Galaxy S4进行此操作.
它没有按照文档的预期工作.
我最初的做法是:
Read BAT
Set notification for HR 
Set notification for CUS.
然后等待回调.设置通知意味着呼叫
BluetoothGatt.setCharacteristicNotification(Characteristic char , boolean enabled)
(也可以对BAT进行通知,但是,规范并不要求支持它.但是,HxM确实支持它.)
这没用.我得到了人力资源的BAT和通知,但不是CUS.如果我取消了第二步,我收到了CUS的通知.我无法得到两者.(这表明我正在正确地阅读这些特征,因此[可能]不是问题.)
我发现一些迹象表明Android的蓝牙堆栈存在同步问题,但没有硬文档.然后我尝试了以下内容:
Read BAT.
Wait for the BAT reading, then set notification for HR,
Get HR, then disable notification for HR, and start notification for CUS.
Get CUS, then disable notification for CUS, and start notification for HR.
And continue to loop.
我得到了BAT,就是这样.
通过反复试验,我发现了以下工作:
Read BAT.
Wait for the BAT reading, then set …notifications android bluetooth bluetooth-lowenergy android-bluetooth
android ×3
gatt ×2
synchronous ×2
asynchronous ×1
bluetooth ×1
concurrency ×1
java ×1
service ×1
xamarin ×1