如何在for循环中读取带有Queque List的BLE设备的所有特性?

时间:2018-02-21 11:25:41

标签: android bluetooth-lowenergy

林'构建一个从BLE设备下载所有信息的应用程序。该设备可以将信息存储在闪存中。 BLE装置有2个特征。所以我要构建一个代码来从中下载所有信息。 我已经创建了一个字符级的Queque来读取,然后我有一个for循环来读取这些特性。 为此,我实现了一个扩展" Service"

的类

这是我的代码:

TimerTask timerTask = new TimerTask() {

        @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
        @Override
        public void run() {
            continuaLetturaForza = true;
            continuaLetturaTemperatura = true;
            int counter = 0;
            while(continuaLetturaForza || continuaLetturaTemperatura){
                counter++;
                Log.v("CICLO WHILE", counter+"");
                if (currDevice != null) {
                    if(ReadQueue!= null && ReadQueue.size()>0){
                        for(int index=0; index< ReadQueue.size(); index++){
                            mGatt.readCharacteristic(ReadQueue.get(index));
                            /*try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }*/
                        }
                    }
                }else{
            //TO DO
        }
            }
            if(gattClientCallback!=null && mGatt != null)
                gattClientCallback.disconnectGattServer();
        }
    };

如果我尝试启动我的应用程序,我可以看到具有我的两个特征的 ReadQueque 列表,所以我读取特征1和特征2,但实际上系统真实只是第一个特征。

但如果我取消注释这行代码:

/*try {
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }*/

找到所有系统,我可以读取特征1和2.如果我没有插入Thread.sleep,我只读取第一个特征。

为什么?

0 个答案:

没有答案