package com.controler;
import android.app.Activity;
import java.io.*;
import java.util.*;
import android.app.*;
import android.bluetooth.*;
import android.content.*;
import android.os.*;
import android.widget.*;
import android.view.*;
public class ControlerActivity extends Activity {
/** Called when the activity is first created. */
public BluetoothAdapter mBTAdapter;
public BluetoothSocket mBTSocket;
public BluetoothDevice mBTDevice;
public OutputStream mmOutStream;
public InputStream mmInStream;
public Handler mHandler;
public BluetoothDevice device;
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBTAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBTAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,0);
}
//////////////////////////////////////////////////////////////
/////////////////////////////////////NXT 연결 부분
Button bt_connect = (Button)findViewById(R.id.bt_connect);
bt_connect.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
device = mBTAdapter.getRemoteDevice("00:16:53:0A:90:84");
try {
mBTSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
mBTSocket.connect(); // 연결
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
//////////////////////////////////////////////////////////////////
/////////////전송 부분
Button bt_up = (Button)findViewById(R.id.bt_up);
bt_up.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String message = "2";
byte[] Buffer = message.getBytes();
try {
mmOutStream = mBTSocket.getOutputStream();
mmOutStream.write(Buffer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}
NXT에서 2라는 숫자를 받았을대 전진하게 하는 소스를 작성하였습니다.
그래서 2를 보낼려고 하는데 계속 NXT쪽에서 메시지를 받지를 못합니다. 이유가 너무 궁금합니다.
다른 방법있으면 좀 가르쳐 주시면 감사하겠습니다.
아 참..
Buffer에다가 2를 줘서도 전송을 해 봤습니다.
안드로이드에서는 디버깅으로 했을때 2를 전송까지 오류는 없는데 계속 NXT에서 못받내요..
혹시 전송 방법이 틀린건가요?