【问题标题】:Phonegap Don's BluetoothSerial plugin: send and print text to a bluetooth printerPhonegap Don 的 BluetoothSerial 插件:向蓝牙打印机发送和打印文本
【发布时间】:2014-07-28 16:02:42
【问题描述】:

在 Android/Phonegap(使用 adobe phonegap builder 构建)项目上工作以将一些字符串打印到蓝牙打印机。

我正在使用最新版本的 Phonegap 和 Don's BluetoothSerial plugin

我有两个问题:

  1. 我可以使用 bluetoothSerial.write 发送一个字符串,它说这是一个 成功,但我的打印机没有任何反应(我尝试输入一些“\n”但没用)
  2. bluetoothSerial.connectbluetoothSerial.connectInsecure 都会失败

我已尽力检查网络上的现有代码,但没有发现任何相关信息。我完全迷失了,不知道是我做错了什么还是我错过了什么。

请看下面我的非常基本的代码:

HTML

<button id="testco" type="button">Test Connect</button>
<button id="listnwrite" type="button">List & Write</button>
<button id="insecure" type="button">Insecure connect</button>
<button id="deco" type="button">Disconnect bluetooth</button>

JavaScript

$(document).ready(function() {

    $("#testco").click(function() {
        bluetoothSerial.connect("00:19:5D:23:D1:7F", connectSuccess, connectFailure);
    });

    $("#listnwrite").click(function() {
        bluetoothSerial.list(function(devices) {
            devices.forEach(function(device) {
                var data = "something \n";
                alert(device.address);
                bluetoothSerial.connect(device.address, connectSuccess, connectFailure);
                bluetoothSerial.write(data, success, failure);
            })
        }, connectFailure);
    });

    $("#insecure").click(function() {
        bluetoothSerial.connectInsecure("00:19:5D:23:D1:7F", connectSuccess, connectFailure);
    });

    $("#deco").click(function() {
        bluetoothSerial.disconnect(sucessdeco, faildeco);
    });

});

所有失败/成功函数都发送一些警报('[ko/ok]')来检查状态。

有人可以帮助我吗?我需要将一些特殊字符发送到我的蓝牙打印机进行打印吗?

【问题讨论】:

标签: android cordova printing bluetooth


【解决方案1】:

检查后这个插件不是用于蓝牙打印机。我现在正在使用一个映射到我的 BT 打印机 SDK 的插件,它的工作原理非常棒。

【讨论】:

  • 你能说出你是怎么用BT打印机打印的吗?感激不尽
【解决方案2】:

要使用蓝牙打印机运行您的代码,您的打印机需要支持 ESC / POS 协议 (http://en.wikipedia.org/wiki/ESC/P) 并配置为接收。

然后你必须用“\ r \ n”结束你的字符串。

 $("#listnwrite").click(function() {
        bluetoothSerial.list(function(devices) {
            devices.forEach(function(device) {
                var data = "something \r\n";
                alert(device.address);
                bluetoothSerial.connect(device.address, connectSuccess, connectFailure);
                bluetoothSerial.write(data, success, failure);
            })
        }, connectFailure);
 });

就我而言,我使用蓝牙收据打印机“Star”型号:TSP650II 要进入“ESC / POS”模式,需要将 DIP 开关 1(在打印机上)置于关闭状态。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 1970-01-01
    • 2014-08-25
    • 2011-07-05
    • 1970-01-01
    • 2014-07-22
    • 2011-08-19
    相关资源
    最近更新 更多