don / BluetoothSerial

Cordova (PhoneGap) Plugin for Serial Communication over Bluetooth
Other
1.07k stars 670 forks source link

write() function not working with thermal printer #461

Open emilkitua opened 1 year ago

emilkitua commented 1 year ago

Hello,

I am using the plugin to connect and print using a thermal printer. but the write() function is not working giving error: Device connection was lost.

my code:

`

import { BluetoothSerial } from '@awesome-cordova-plugins/bluetooth-serial/ngx';

....

async printStuff() {
    // this.alertMessage2(this.selectedPrinter);
    this.bluetooth.connect(this.selectedPrinter)
    .subscribe(async() => {
      //2. Connected successfully
      // this.alertMessage2('392: ' + success)

      await this.bluetooth.write(this.espEncode())
         .then(success => {
            //3. Print successful
            //If you want to tell user print is successful,
            //handle it here
            //4. IMPORTANT! Disconnect bluetooth after printing
            // console.log('sucess')
            this.alertMessage2('401: ' + success)
            this.bluetooth.disconnect()
         }, err => {
            //If there is an error printing to bluetooth printer
            //handle it here
            console.error('43:' + err)
            this.alertMessage2('error 43: ' + err)

         })
    }, err => {

      //If there is an error connecting to bluetooth printer
      //handle it here
      this.alertMessage('error 416: ' + err, '')

      this.bluetooth.disconnect();

      console.error(err)
    })

    // await this.print.sendToBluetoothPrinter(this.selectedPrinter, this.espEncode());
  }`
sadalsuud commented 1 year ago

In my case no it does not shows any message, supposedly print, but It does not print

bobolat commented 10 months ago

i have the same problem..got Write successfully OK but printer no action