I have a plugin, cordova-plugin-datecs-printer, and I can print some strings with it on a thermal printer. The problem is that I'm not able to print large numbers of strings this way I'm coding. I have already been informed by the plugin creator that the error is in the way I am dealing with the promises, but I have already tried to change the way I deal with them in different ways and I am not getting it. I tried to look for a few examples and learn more about promises, but I can not apply anything to this case.
My code:
printItem(){
this.print.listBluetoothDevices().then(result => {
console.log(JSON.stringify(result));
this.print = result;
}).catch(err => {
});
this.print.connect('00:02:5B:B4:7C:3A').then(result => {
console.log(JSON.stringify(result));
this.print = result;
}).catch(err => {
});
var printStr = "";
printStr += "{reset}{center}Instituto do Meio Ambiente {br}";
printStr += "------------------------------------------------";
printStr += "AUTO DE INFRACAO AMBIENTAL 9453-D {br}";
printStr += "------------------------------------------------";
printStr += "DADOS DO AUTUADO {br}";
var printStr2 = "";
printStr2 += " {br}";
printStr2 += "{reset}{left}Nome: ";
printStr2 += "ADD VARIAVEL NOME {br}";
printStr2 += "CPF: ";
printStr2 += "ADD VARIAVEL CPF {br}";
//Promises I want to chain
this.print.printText(printStr, 'ISO-8859-1');
this.print.printText(printStr2, 'ISO-8859-1');
this.print.feedPaper(100).then(result => {
console.log(JSON.stringify(result));
this.print = result;
}).catch(err => {
});
EDIT: Provider I'm using (print):
listBluetoothDevices() {
return new Promise<any>((resolve, reject) => {
this.win.DatecsPrinter.listBluetoothDevices((success) => resolve(success), (error) => reject(error));
});
}
connect(deviceAddress: string): Promise<any> {
return new Promise<any>((resolve, reject) => {
setTimeout(() => this.win.DatecsPrinter.connect(deviceAddress, (success) => resolve(success), (error) => reject(error)), this.defaultTimeout);
});
}
printText(text: string, charset: string = 'ISO-8859-1'): Promise<any> {
return new Promise<any>((resolve, reject) => {
this.win.DatecsPrinter.printText(text, charset, (success) => resolve(success), (error) => reject(error));
});
}