1

这可能很微妙:

我为 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-Module Gen 2 或 3 的设备的更新版本。这似乎是这里的问题,因为具有 BT Gen 1 的旧打印机工作正常,其他打印机工作正常50% 的时间。

有什么解决方法/修复吗?

4

1 回答 1

0

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

首先,我从他们的 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 ...

于 2018-06-21T10:50:30.860 回答