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());
}`
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:
`