【问题标题】:Ionic Bluetooth printing POS command not working离子蓝牙打印POS命令不起作用
【发布时间】:2017-06-23 02:08:24
【问题描述】:

我正在开发这个 ionic 应用程序,并且我正在使用蓝牙热敏打印机使用这个库打印收据。

https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer

我想在打印后剪纸,因为我的打印机有这个功能。

BTPrinter.printPOSCommand(function(data){
    console.log("Success");
    console.log(data)
},function(err){
    console.log("Error");
    console.log(err)
}, "1D")

我尝试了 0x1d 和“0x1d v 1”,但它不起作用。

【问题讨论】:

    标签: android cordova ionic-framework printing bluetooth


    【解决方案1】:

    您究竟是如何尝试发送该命令的?试试:

    BTPrinter.printPOSCommand(function(data){
        console.log("Success");
        console.log(data)
    },function(err){
        console.log("Error");
        console.log(err)
    }, "0x1d")
    

    如果这不起作用,您可以尝试编辑插件本身以添加方法,但这有点复杂。

    在 pluginfolder/src/android 的 Bluetoothprint.java 文件中尝试以下操作:

    得到以下方法:

     boolean printPOSCommand(CallbackContext callbackContext, byte[] buffer)     throws IOException {
            try {
            //mmOutputStream.write(("Inam").getBytes());
            //mmOutputStream.write((((char)0x0A) + "10 Rehan").getBytes());
            mmOutputStream.write(buffer);
            //mmOutputStream.write(0x0A);
    
            // tell the user data were sent
            Log.d(LOG_TAG, "Data Sent");
            callbackContext.success("Data Sent");
            return true;
        } catch (Exception e) {
            String errMsg = e.getMessage();
            Log.e(LOG_TAG, errMsg);
            e.printStackTrace();
            callbackContext.error(errMsg);
        }
        return false;
    }
    

    将方法属性byte[] buffer改为string buffer 并换行

     mmOutputStream.write(buffer);
    

    到:

    mmOutputStream.write(buffer.getBytes());
    

    还只是为了确保您的打印机支持您可以尝试直接放置的方法:

    mmOutputStream.write(0x1d);
    

    只是为了测试它是否有效。

    编辑:

    试试我找到的这个 byteArray:

    public static byte[] FEED_PAPER_AND_CUT = {0x1D, 0x56, 66, 0x00};
    BTPrinter.printPOSCommand(function(data){
        console.log("Success");
        console.log(data)
    },function(err){
        console.log("Error");
        console.log(err)
    }, FEED_PAPER_AND_CUT)
    

    【讨论】:

    • 我已经完全尝试过,但它不起作用。 :(
    • 尝试编辑插件文件本身。我已经更新了我的答案,所以你可以试试。
    • 非常感谢.. 我一定会试一试的,你说msg.getBytes() 你的意思是buffer 而不是msg 对.. ?
    • 是的,已编辑和修复。 :)
    • 不幸的是,纸张仍然没有被裁切.. :(
    猜你喜欢
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 2021-04-14
    • 2018-12-08
    • 2017-05-06
    • 2012-04-07
    相关资源
    最近更新 更多