마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

ble writeCharacteristic에 대해 질문 드립니다..

0 추천

값을 받는것이 아니라,, 보내는 작업을 하려고 합니다.

ble통신할 때 한 번에 보낼 수있는 byte가 최대 20이라고 하는데 이건 문제가 없구요..

해당 앱에서 버튼A라는 녀석을 눌렀을 때 byte 배열(byte[])에 값을 넣어서 보내려고 합니다.

byte a=1;

byte b=2;

byte[] send = {a,b};

mBluetoothLeService.writeCharacteristic(mWriteCharacteristic, send );

-

public void writeCharacteristic(BluetoothGattCharacteristic characteristic,
byte[] send) 
{
if (mBluetoothAdapter == null || mBluetoothGatt == null) 
{
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
 
mBluetoothGatt.writeCharacteristic(characteristic);
}


이런식으로 보내려고 하는데 맞는 방법인가요..?

anci (19,950 포인트) 님이 2015년 3월 2일 질문
anci님이 2015년 3월 2일 수정

1개의 답변

+1 추천
 
채택된 답변
BluetoothGattCharacteristic mSCharacteristic;

..................

public void serialSend(String theString) {
    if (mConnectionState == connectionStateEnum.isConnected) {
        mSCharacteristic.setValue(theString);
        mBluetoothLeService.writeCharacteristic(mSCharacteristic);
    }
}

전 이렇게 사용하고 있는데요...

nicehee (73,100 포인트) 님이 2015년 3월 2일 답변
anci님이 2015년 3월 2일 채택됨
댓글 감사합니다.
현재 메인액티비티쪽에서
byte[] data = {1,1};
mBluetoothLeService.writeCharacteristic(mWriteCharacteristic, data);
이렇게 하였고,
블루투스서비스쪽 클래스에서
public void writeCharacteristic(BluetoothGattCharacteristic characteristic,
            byte[] data)
    {
        if (mBluetoothAdapter == null || mBluetoothGatt == null)
        {
            Log.w(TAG, "BluetoothAdapter not initialized");
            return;
        }
//        Log.i(TAG, "characteristic " + characteristic.toString());
        if(characteristic==null)
        {
            Log.d("characteristic null","bb");
        }
        characteristic.setValue(data);
        mBluetoothGatt.writeCharacteristic(characteristic);
       
    }
요로코롬 사용했는데, 디버깅해보니 이상은 없고 byte[] data 값도 잘 받아오는데 이렇게 해도 무관한지요?
잘 받아온다면 문제없겠지요..
characteristic.setValue();
에 byew[] 배열도 넣을 수 있으니..
...