android 蓝牙转串口,安卓:用Android手机的蓝牙串口(COM端口)的通信

I am trying to communicate with a Bluetooth programmable Microcontroller. The Bluetooth device on the microcontroller communicates (specifically) on Bluetooth Serial COM Port number 4.

QUESTION: How can I get the Android App to read data from this COM port (number 4)?

I know the UUID is a well known unique ID,that works for this device, but I don't think that it has anything to do with specifying the COM port.

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;

} }}

解决方案

The COM port is something that exists only on the microcontroller, not the Bluetooth device attached to it. The Bluetooth device does not even know which COM port the microcontroller used to connect to it. The Bluetooth device's connection to the micro is via the TX and RX lines. The fact that they are attached to pins on the micro assigned to a specific COM port is irrelevant and unknown to the Bluetooth device.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值