zoukankan      html  css  js  c++  java
  • Android-BlutoothBle,蓝牙中心设备(peripheral)向外围设备(GattServer)连续写入多个Characteristic的注意事项

    新写入一个characteristic时,应该等上一个写入characteristic操作结束后,在回调函数里面得到返回状态过后,再能继续写入下一个characteristic

    新写入一个characteristic时,

    public static boolean Write_Characteristic_Callback_Success = true;
    
    
        Thread t1=new Thread(new Runnable() {
        @Override
        public void run() {
          //上一次回调是否成功,不成功继续等待
          while(!Write_Characteristic_Callback_Success){}
          //开始写入之前,把Write_Characteristic_Callback_Success置为false
          Write_Characteristic_Callback_Success=false;
          mBluetoothLeService.writeCharacteristic(finalBluetoothGattCharacteristic);
        }
      });
    
      t1.start();
      try {
        //等待该线程执行结束
        
    t1.join();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    
    

    在回调函数里面得到返回状态

            @Override
            public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
    
                if(status==BluetoothGatt.GATT_SUCCESS){
                    Write_Characteristic_Callback_Success=true;//自定义的全局静态变量,记录上一个写入操作回调函数得到的状态
                    broadcastUpdate(ACTION_DATA_WRITE_SUCCESS, characteristic);
                }
            }

    Android蓝牙开发的各种坑

  • 相关阅读:
    C#连接MySQL
    国双面试题
    Redis入门安装配置
    vs2013密钥
    单例模式
    用R画韦恩图
    Snipaste截图
    秩和检验
    用R包中heatmap画热图
    OTU(operational taxonomic units),即操作分类单元
  • 原文地址:https://www.cnblogs.com/sunupo/p/10390533.html
Copyright © 2011-2022 走看看