我正在嘗試與藍牙可編程微控制器進行通信。微控制器上的藍牙設備與藍牙串行COM端口號4進行通信(具體)。Android:與Android手機進行藍牙串行(Com端口)通信
問題:如何讓Android應用程序從此COM端口(編號4)讀取數據?
我知道UUID是一個衆所周知的唯一ID,它適用於此設備,但我認爲它與指定COM端口沒有任何關係。
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
btSocket = btDevice.createRfcommSocketToServiceRecord(myUUID);
btSocket.connect();
valid.append(btDevice.getName() + "\n" + btDevice.getAddress());
north.append("Socket Connected");
InputStream mmInStream = btSocket.getInputStream();
OutputStream mmOutStream = btSocket.getOutputStream();
byte[] buffer = new byte[10];
int bytes;
StringBuffer str = new StringBuffer();
while (true) {
try {
mmOutStream.write("a".getBytes());
//Reads a # of bytes until the end of stream is reached
bytes = mmInStream.read(buffer);
//Transform to string
str.append(buffer.toString()+"\t"); //Clear the buffer
Log.e("DATA", "THE DATA: "+ str.toString());
south.setText(str.toString());
str.delete(0,str.length());
} catch (IOException e) {
break;
} }}