【问题标题】:How to connect bluetooth printer using ionic 3?如何使用 ionic 3 连接蓝牙打印机?
【发布时间】:2018-04-07 09:55:44
【问题描述】:

我无法使用以下插件连接蓝牙打印机

$ ionic cordova plugin add de.appplant.cordova.plugin.printer
$ npm install --save @ionic-native/printer

有什么方法可以使用 ionic 3 连接蓝牙打印机?

【问题讨论】:

  • 您收到哪个错误?你能分享你使用的代码吗?否则很难说是什么问题
  • 我正在使用ionicframework.com/docs/native/bluetooth-serialionicframework.com/docs/native/printer 但我无法连接到我的设备。
  • “我无法连接我的设备”是什么意思?在安装插件期间、连接设备期间是否收到错误消息,或者您看不到 BLE 设备。您提供的信息越多,您就越有可能收到答案

标签: ionic-framework plugins bluetooth-printing


【解决方案1】:

以下是使用 ionic 2+ 打印到蓝牙收据打印机的示例。我写这个是因为我遇到了同样的问题。

所以我尝试使用离子原生蓝牙串行连接来“写入”进行打印,并且成功了。

它也应该适用于 ionic 3:

https://github.com/razmans/ionicBluetoothPrint

【讨论】:

  • 鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。见how to answer
【解决方案2】:

遵循以下 3 个步骤:1-查找蓝牙设备,2-连接设备及其 id,3-打印

devices = [];
btnFindDevices() {
   this.bluetoothSerial.isEnabled().then(() => {
   this.bluetoothSerial.discoverUnpaired().then((allDevices) => {
   this.devices = allDevices;
   console.log(allDevices);
});
});
}

btnBlueToothConnect() {
   if (this.devices.length > 0) {
   //this code connects device which’s position is 0. Change it whatever you 
   //want.
   this.bluetoothSerial.connect(this.devices[0].id).subscribe((data) => {
   console.log(“Connected”, data);
   }, (error) => {
   console.log(“not Connected”, error);
   });
    }
    else {
    console.log(“Device List did not genereted yet.”);
    }
    }

    btnBlueToothPrint() {
    //Attention… Bluetooth printer prints data when whole line filled. For 
    //example in my case printer is 32 colon,
    //“hello world” has 11 characters. so it prints after 3 times clicked 
    //the print button.
        this.bluetoothSerial.write(‘hello world’).then(() => { console.log(“s”); }, () => { console.log(“f”); });
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    相关资源
    最近更新 更多