如何通过蓝牙发送 Android 命令?
How to send Android commands via Bluetooth?
我正在尝试学习如何使用此库通过蓝牙发送命令:
https://github.com/akexorcist/Android-BluetoothSPPLibrary
但是当我尝试以这种形式发送这些命令时:
(Send: "$$$" Receive: "CMD"
Send: "S&,0404\r" Receive: "AOK"
Send: "S&,0400\r" Receive: "AOK"
Send: "---\r" Receive: "END")
我需要把这个命令写下来,
但是我不知道怎么办。
我想通过蓝牙连接到 android 设备并发送文本。
void teplotahore() {
STup.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
teplotad++;
prevodst(teplotac, teplotad);
bt.send("Text", true);
}
}
);
}
public void send(String data, boolean CRLF) {
if(mChatService.getState() == BluetoothState.STATE_CONNECTED) {
if(CRLF)
data += "\r\n";
mChatService. write(data.getBytes());
}
}
请告诉我如何(发送:"S&,0404\r" 接收:"AOK")重写为字节形式以通过蓝牙发送。
或者谁有类似的项目,请发给我。我想学习它。
我对这些问题的理论越来越多,但对我来说不是 运行。
Bluetoothchat是google提供的示例工程。您可以检查此以了解使用蓝牙传输数据。
我正在尝试学习如何使用此库通过蓝牙发送命令: https://github.com/akexorcist/Android-BluetoothSPPLibrary
但是当我尝试以这种形式发送这些命令时:
(Send: "$$$" Receive: "CMD"
Send: "S&,0404\r" Receive: "AOK"
Send: "S&,0400\r" Receive: "AOK"
Send: "---\r" Receive: "END")
我需要把这个命令写下来,
但是我不知道怎么办。
我想通过蓝牙连接到 android 设备并发送文本。
void teplotahore() {
STup.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
teplotad++;
prevodst(teplotac, teplotad);
bt.send("Text", true);
}
}
);
}
public void send(String data, boolean CRLF) {
if(mChatService.getState() == BluetoothState.STATE_CONNECTED) {
if(CRLF)
data += "\r\n";
mChatService. write(data.getBytes());
}
}
请告诉我如何(发送:"S&,0404\r" 接收:"AOK")重写为字节形式以通过蓝牙发送。
或者谁有类似的项目,请发给我。我想学习它。
我对这些问题的理论越来越多,但对我来说不是 运行。
Bluetoothchat是google提供的示例工程。您可以检查此以了解使用蓝牙传输数据。