0

I am unable to connect with bluetooth printer using below plugin

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

Is there any way to connect bluetooth printer using ionic 3?

Somnath
  • 368
  • 2
  • 9
  • 22
  • Which error do you receive? Could you share the code that you used? otherwise is difficult to say what is the problem – LuckyStarr Oct 26 '17 at 07:56
  • I am using https://ionicframework.com/docs/native/bluetooth-serial/ and https://ionicframework.com/docs/native/printer/ but I am unable to connect with my device. – Somnath Oct 26 '17 at 09:19
  • What do you mean with ` I am unable to connect with my device`? Do you receive an error during the installation of the plugins, during the connection to the devices or you don't see the BLE device. More info you give more probably you receive an answer – LuckyStarr Oct 26 '17 at 11:08

2 Answers2

4

Here's an example of printing to bluetooth receipt printer with ionic 2+. I wrote this because I was having the same problem.

So I tried using ionic native bluetooth serial connection to 'write' to print and it worked.

It should work on ionic 3 as well:

https://github.com/razmans/ionicBluetoothPrint

  • Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. See [how to answer](https://stackoverflow.com/help/how-to-answer) – SilverNak Dec 13 '17 at 09:56
1

Follow these 3 steps: 1-Find bluetooth devices, 2-Connect the device with its id, 3-Print

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”); });
    }