在低功耗蓝牙中写入字符缓冲区

时间:2016-03-31 12:57:25

标签: ios bluetooth-lowenergy

我正在开发支持蓝牙低功耗的应用程序。 我将与支持特性的硬件设备进行通信。让我们假设特征被定义为" TestCharacteristic"。 根据场景,我想将不同的数据写入相同的特征。

在我的iOS应用中,我将有两个按钮。

我想在点击第一个按钮时发送一个20字节的字符缓冲区,在点击第二个按钮时发送20字节的不同字符缓冲区。

OnButton 1点击:

BluetoothGattCharacteristic charac = Service  
            .getCharacteristic("TestCharacteristic");  
    if (charac == null) {  
        Log.e(TAG, "char not found!");  
        return false;  
    }  


    byte[20] value = {0xEF, 1, 1, 0, 0, 0, 0xEF, 0, 0, 0, 0, 0, 0xEF, 1, 2, 0, 0, 0, 0xEF, 0, 0, 0, 0, 0, 0xEF, 0, 0, 0, 0, 0 };  
    charac.setValue(value);  
    boolean status = mBluetoothGatt.writeCharacteristic(charac); 

OnButton 2点击:

BluetoothGattCharacteristic charac = Service  
            .getCharacteristic("TestCharacteristic");  
    if (charac == null) {  
        Log.e(TAG, "char not found!");  
        return false;  
    }  


    byte[20] value = {0xDC, 0, 0, 0 ,0 , 0xDC, 0, 0, 0 ,0, 0xDC, 0, 0, 0 ,0, 0xDC, 0, 0, 0 ,0};  
    charac.setValue(value);  
    boolean status = mBluetoothGatt.writeCharacteristic(chara  
c);

上述操作可能吗? 我可以为同一个特征发送不同的值吗?

谢谢&问候, 菲尔

0 个答案:

没有答案