【问题标题】:android bluetooth SPP connection terminates before sending all dataandroid蓝牙SPP连接在发送所有数据之前终止
【发布时间】:2018-11-29 18:35:58
【问题描述】:

这可能很微妙:

我为 Android 6 开发了一个应用程序,它可以在 Bixolon SPP-R-200II 上打印多张收据。首先,正常方式工作正常,连接、打印等看起来不错。

由于测试,我遇到了一个特殊错误。有时打印在完成之前就停止了。日志显示:

06-20 15:04:17.456 5369-5393/? W/bt_rfcomm: port_rfc_closed RFCOMM connection in state 2 closed: Peer connection failed (res: 16) 06-20 15:04:17.457 5369-5397/? E/bt_btif_sock_rfcomm: find_rfc_slot_by_id unable to find RFCOMM slot id: 7 06-20 15:04:17.463 5369-5393/? I/bt_btm_sec: btm_sec_disconnected clearing pending flag handle:2 reason:8 06-20 15:04:17.463 5369-5393/? W/bt_l2cap: L2CA_SetDesireRole() new:x0, disallow_switch:0 L2CA_SetDesireRole() new:x0, disallow_switch:0 06-20 15:04:17.463 5369-5387/? E/BluetoothRemoteDevices: state12newState1 06-20 15:04:17.463 5369-5387/? D/BluetoothRemoteDevices: aclStateChangeCallback: sending ACL disconnected intent 06-20 15:04:17.464 5369-5387/? D/BluetoothRemoteDevices: aclStateChangeCallback: State:DisConnected to Device:74:F0:7D:E4:8E:3C 06-20 15:04:17.466 5369-5369/? D/BluetoothMapService: onReceive onReceive: android.bluetooth.device.action.ACL_DISCONNECTED 06-20 15:04:17.468 5369-5369/? V/BluetoothPbapService: action: android.bluetooth.device.action.ACL_DISCONNECTED 06-20 15:04:17.472 5369-5369/? V/BluetoothFtpService: Ftp Service onStartCommand PARSE INTENT action: android.bluetooth.device.action.ACL_DISCONNECTED 06-20 15:04:17.475 5369-5369/? D/BluetoothDunService: parseIntent: action: android.bluetooth.device.action.ACL_DISCONNECTED

我发现 Android 4 和更新版本的 BT 堆栈存在一些问题,设备具有 BT 模块 Gen 2 或 3。这似乎是这里的问题,因为 BT Gen 1 的旧打印机工作正常,其他人在 50% 的时间里都没有。

是否有任何解决方法/修复?

【问题讨论】:

    标签: android bluetooth spp bixolon-printer


    【解决方案1】:

    好的,这似乎是打印机的故障,这是我实际工作的解决方案:

    首先,我从他们的 SDK 中反编译了 Bixolon API。我检查了他们是如何实现传输的,并发现在多个设备上或从 Android 的指定 API 级别需要以较小的包发送数据。见以下代码:

    发件人:

        osr.write(output);
    

    改为:

        //this is needed for API lvl > 16 due to connection losses with big data
        if (output.length > 1024) {
        for (int i = 0; i < output.length; i += 1024) {
            osr.write(output, i, i + 1024 > output.length ? output.length - i : 1024);
            try
            {
                Thread.sleep(150);
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        } else {
            osr.write(output);
        }
    

    请记住,osr 是 OutputStream...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-14
      • 1970-01-01
      • 2017-08-25
      • 2012-07-02
      • 1970-01-01
      • 2011-10-26
      • 1970-01-01
      • 2011-05-01
      相关资源
      最近更新 更多