【问题标题】:Android Slow Bluetooth RFCOMM Transfer Rate with RN4678带有 RN4678 的 Android 慢速蓝牙 RFCOMM 传输速率
【发布时间】:2022-11-02 09:40:22
【问题描述】:

我们正在试验一堆新的平板电脑,我们尝试的每一台都遇到了 RN4678 板传输速率慢的问题。我们目前使用联想 M10 FHD Plus。我们尝试了一些,例如台电 M40S、诺基亚 T20 和三星 Galaxy Tab A8。前两个的传输率很糟糕,而后者还可以,但并不理想。我们无法使用 Lenovo M10 Plus 第 3 代,因为按钮太靠近角落,无法与我们的平板电脑支架一起使用。

这是我的代码:

public void SendMessage(BluetoothSocket socket, String msg) {
    OutputStream outStream;
    try {
        outStream = BluetoothConnectionService.outputStream;
        outStream.write("S".getBytes());
        Thread.sleep(4000);
        processThread = true;
        mApp.running = true;
        BluetoothSocketListener bsl = new BluetoothSocketListener(socket,
                CollectingDetail.this);
        Thread messageListener = new Thread(bsl);

        messageListener.start();
        timer = new CounterClass(remaingTime, 1000);
        timer.start();
        bt_stop.setText("Stop");

        IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED);
        filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
        registerReceiver(bluetoothReceiver, filter);
        bluetoothReceiver.setRegistered(true);
    } catch (IOException | InterruptedException e) {
        Log.e("BLUETOOTH_COMMS", e.getMessage());

        connectSocket();
    } 
}

public static class BluetoothSocketListener implements Runnable {
    private final WeakReference<CollectingDetail> wrActivity;
    private BluetoothSocket socket;

    public BluetoothSocketListener(BluetoothSocket socket, CollectingDetail collectingDetail) {
        this.socket = socket;
        wrActivity = new WeakReference<CollectingDetail>(collectingDetail);
    }

    @Override
    public void run() {
        final CollectingDetail activity = wrActivity.get();
        if (activity != null) {
            activity.inStream = null;
            if (!Thread.currentThread().isInterrupted()) {
                int bufferSize = 512;
                byte[] buffer = new byte[bufferSize];
                Log.i("Bluetooth bytes", new String(buffer));
                activity.inStream = BluetoothConnectionService.inputStream;
                int availableBytes;
                int bytesRead = -1;
                String message = "";

                while (activity.processThread) {
                    message = "";
                    try {
                        availableBytes = activity.inStream.available();
                        if (availableBytes > 0) {
                            bytesRead = activity.inStream.read(buffer);
                            if (bytesRead != -1 && bytesRead < bufferSize) {
                                message = new String(buffer, 0, bytesRead);

                                if (activity.mainHandler != null) {
                                    activity.mainHandler.post(new MessagePoster(message, activity));

                                }


                            }
                        }
                    } catch (IOException e) {
                        Log.e("BLUETOOTH_COMMS", "Error reading bytes");
                        try {
                            socket.close();
                        } catch (IOException e1) {
                            Log.e("BLUETOOTH_COMMS", "Could not close socket");
                        }
                        activity.processThread = false;
                    }
                }
            }
        }
    }
}


public void seprateData(String message) {
    try {
        message = message.replaceAll("(\\r\\n|\\n|\\r)", ",");
        String[] a = message.split(",");
        boolean goodData = false;

        for (int i = 0; i < a.length; i++) {
            final String data = a[i];
            if (data.length() > 0 && !data.equals(" ")) {
                if (data.length() >= 10 && data.startsWith("5A")) {
                    al_sepratedMessageList.add(data);
                    goodData = true;

                }
            }
        }

        if (goodData) {
            calculation();
            if (ConnectThrough.equalsIgnoreCase("usb")) {
                UsbConnectionSerivce.sendMessage("K");
            } else {
                BluetoothConnectionService.sendMessage(socket, "K");
            }
        }

    } catch (Exception e) {
        Log.e("BiSym", "Error Parsing BiSym Data");
    }
}

有什么方法可以在不更改固件的情况下提高传输速率?似乎其他人也面临类似的问题,但没有一个答案有真正的解决方案.你能帮帮我吗?谢谢。

【问题讨论】:

    标签: android bluetooth android-bluetooth rfcomm spp


    【解决方案1】:

    你重复测试了吗?蓝牙使用与 2.4 GHz Wifi 和微波炉相同的频率。在拥挤的 Wifi 环境和/或过多的蓝牙连接中,速度变慢是正常的。

    乐队里只有这么多空间。

    在没有干扰的区域重复您的测试,看看您是否得到相同的结果。

    一种廉价的隔离方法是用 0.25 英寸的铁丝网制作法拉第笼。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多