【问题标题】:How to connect android device via bluetooth with matlab 'Instrument Control'-Toolbox?如何通过蓝牙与 matlab '仪器控制'-工具箱连接 android 设备?
【发布时间】:2015-08-14 14:29:50
【问题描述】:

我想通过 bluetoothandroid 设备ma​​tlab 连接,以便在 matlab 和我自己的 android 应用程序之间交换数据。但我无法通过“仪器控制”工具箱与我的安卓设备连接。为什么?


首先,我扫描了所有可用的设备,然后尝试连接(使用“连接”按钮)与 android。


我搜索了一下,上面写着:

所以我阅读了技术规范。从我的设备中,我找不到它们支持所需的 SPP 蓝牙配置文件。

  • 三星 Galaxy Young 2 (SM-G 130HN):
    蓝牙®-配置文件:HSP、OPP、SAP、A2DP、PBAP、HFP、AVRCP、DI、HID、HOGP、PAN , 地图
    tech spez. galaxy young
  • 三星 Galaxy S Advance:
    蓝牙配置文件:GAP、SSP、SDAP、HSP、HFP、A2DP、SAP、OPP、PBAT、MAP、AVRCP、HID
    tech spez. galaxy s
  • HTC One M7:
    常用配置文件:HSP [耳机]、HFP [免提]、A2DP [立体声音频]、AVRCP [媒体控制]、HID [外围设备] em>
    tech spez. HTC One M7

但在 android 文档中它说:

  • 最常见的蓝牙套接字类型是 RFCOMM,这是 Android API 支持的类型。 RFCOMM 是一种基于蓝牙的面向连接的流式传输。它也称为串行端口配置文件 (SPP)。
    support SPP profile in android

所以我认为android本身支持SPP,但不支持我使用的设备?
有没有办法通过蓝牙将其中一部手机与matlab连接起来?
哪些安卓设备可以运行?

【问题讨论】:

    标签: android matlab sockets bluetooth serial-port


    【解决方案1】:

    解决方案

    这里'activate bluetooth spp in android' 说:

    • 在 Android 手机上,您可能需要运行一个通过 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' 连接部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多