如何使用 matlab 'Instrument Control'-Toolbox 通过蓝牙连接 android 设备?
How to connect android device via bluetooth with matlab 'Instrument Control'-Toolbox?
我想通过 蓝牙 与 matlab 连接 android 设备用于在 matlab 和我自己的 android 应用程序之间交换数据。但是我无法通过 'Instrument Control'-Toolbox 与我的 android 设备连接。为什么?
首先,我扫描了所有可用的设备,然后尝试(使用 "connect" 按钮)与 android.
连接
我搜索了一下,上面写着:
- Instrument Control Toolbox 支持蓝牙串行端口规范 (SPP)
supported profiles
only SPP support
所以我阅读了技术规范。从我的设备上,我找不到它们支持所需的 SPP 蓝牙配置文件。
- 三星 Galaxy Young 2 (SM-G 130HN):
蓝牙®-配置文件:HSP、OPP、SAP、A2DP、PBAP , HFP, AVRCP, DI, HID, HOGP, PAN, MAP
tech spez. galaxy young
- Samsung Galaxy S Advance:
蓝牙配置文件:GAP、SSP、SDAP、HSP、HFP、A2DP、SAP、OPP、PBAT ,地图,AVRCP,HID
tech spez. galaxy s
- HTC One M7:
常用配置文件:HSP[耳机]、HFP[免提]、A2DP[立体声音频]、 AVRCP[媒体控制],HID[外设]
tech spez. HTC One M7
但在 android 文档中它说:
- 最常见的蓝牙套接字类型是 RFCOMM,这是 Android API 支持的类型。 RFCOMM 是一种基于蓝牙的面向连接的流式传输。它也称为串行端口配置文件 (SPP)。
support SPP profile in android
所以我认为 android 本身支持 SPP,但我使用的设备不支持?
有没有办法通过蓝牙将其中一部手机与 matlab 连接?
哪些 android 设备在工作?
解决方案
这里'activate bluetooth spp in android'说:
- 在 Android phone 上,您可能需要 运行 一个通过 SPP 启动服务的应用程序。
您需要侦听传入的连接请求,因此您应该使用此功能:
listenUsingRfcommWithServiceRecord(String, UUID)
在这里你可以找到一些例子:
代码示例
final Thread connect = new Thread(new Runnable() {
@Override
public void run() {
BluetoothServerSocket serverSocket;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
UUID sppUUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
BluetoothSocket bluetoothSocket = null;
try {
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord("your app name", sppUUID);
bluetoothSocket = serverSocket.accept(); // blocking call, until a connection is established.
Log.i("TAG", "serverSocket accept");
} catch (IOException e) {
Log.e("TAG", "IOException");
}
// If a connection was accepted
if (bluetoothSocket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(bluetoothSocket);
}
}
});
connect.start();
我的错误是认为我可以在没有自己的应用程序的情况下连接 matlab 和 android,只需使用设置中的 android 'bluetooth' 连接部分。
我想通过 蓝牙 与 matlab 连接 android 设备用于在 matlab 和我自己的 android 应用程序之间交换数据。但是我无法通过 'Instrument Control'-Toolbox 与我的 android 设备连接。为什么?
我搜索了一下,上面写着:
- Instrument Control Toolbox 支持蓝牙串行端口规范 (SPP)
supported profiles
only SPP support
所以我阅读了技术规范。从我的设备上,我找不到它们支持所需的 SPP 蓝牙配置文件。
- 三星 Galaxy Young 2 (SM-G 130HN):
蓝牙®-配置文件:HSP、OPP、SAP、A2DP、PBAP , HFP, AVRCP, DI, HID, HOGP, PAN, MAP
tech spez. galaxy young - Samsung Galaxy S Advance:
蓝牙配置文件:GAP、SSP、SDAP、HSP、HFP、A2DP、SAP、OPP、PBAT ,地图,AVRCP,HID
tech spez. galaxy s - HTC One M7:
常用配置文件:HSP[耳机]、HFP[免提]、A2DP[立体声音频]、 AVRCP[媒体控制],HID[外设]
tech spez. HTC One M7
但在 android 文档中它说:
- 最常见的蓝牙套接字类型是 RFCOMM,这是 Android API 支持的类型。 RFCOMM 是一种基于蓝牙的面向连接的流式传输。它也称为串行端口配置文件 (SPP)。
support SPP profile in android
所以我认为 android 本身支持 SPP,但我使用的设备不支持?
有没有办法通过蓝牙将其中一部手机与 matlab 连接?
哪些 android 设备在工作?
解决方案
这里'activate bluetooth spp in android'说:
- 在 Android phone 上,您可能需要 运行 一个通过 SPP 启动服务的应用程序。
您需要侦听传入的连接请求,因此您应该使用此功能:
listenUsingRfcommWithServiceRecord(String, UUID)
在这里你可以找到一些例子:
代码示例
final Thread connect = new Thread(new Runnable() {
@Override
public void run() {
BluetoothServerSocket serverSocket;
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
UUID sppUUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
BluetoothSocket bluetoothSocket = null;
try {
serverSocket = bluetoothAdapter.listenUsingRfcommWithServiceRecord("your app name", sppUUID);
bluetoothSocket = serverSocket.accept(); // blocking call, until a connection is established.
Log.i("TAG", "serverSocket accept");
} catch (IOException e) {
Log.e("TAG", "IOException");
}
// If a connection was accepted
if (bluetoothSocket != null) {
// Do work to manage the connection (in a separate thread)
manageConnectedSocket(bluetoothSocket);
}
}
});
connect.start();
我的错误是认为我可以在没有自己的应用程序的情况下连接 matlab 和 android,只需使用设置中的 android 'bluetooth' 连接部分。