Application Demo using the @ionic-native/star-prnt wrappers for the cordova plugin StarPRNT
Install the Cordova and Ionic Native plugins:
ionic cordova platform add android
or ionic cordova platform add ios
cordova plugin add cordova-plugin-starprnt
npm install --save @ionic-native/star-prnt
or npm install --save @ionic-native/star-prnt@4
based on Ionic docs
ionic cordova run android -l -c
or ionic cordova run ios -l -c
Important
The ionic-native plugin is not available through npm yet, in the meantime download a copy here star-prnt and place it in your app node_modules/@ionic-native directory
Add this plugin to your app's module
usage: import { StarPRNT } from '@ionic-native/star-prnt';
constructor(private starprnt: StarPRNT) { }
...
this.starprnt.portDiscovery('all')
.then((res: any) => console.log(res))
.catch((error: any) => console.error(error));
let printObj:PrintObj = {
text:"Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n",
cutReceipt:true,
openCashDrawer:false
}
this.starprnt.printRawText('BT:StarMicronics', 'EscPosMobile', printObj)
.then(result => {
console.log('Success!');
})
Connect to the printer before start sending commands:
let hasBarcodeReader = false;
this.starprnt.connect('BT:StarMicronics', 'EscPosMobile', hasBarcodeReader)
.subscribe(result =>{
console.log(result); //Success!
}, error => {
alert("Communication Error: ");
})
Notes:
-You need to connect before printing if using StarIOExtManager
-You should call this function on app resume event if you have disconnected on pause event
-After connecting the getStatus observable starts firing with the printer status
Send Commands to the connected printer setting the port to null
let printObj:PrintObj = {
text:"Star Clothing Boutique\n123 Star Road\nCity, State 12345\n\n",
cutReceipt:true,
openCashDrawer:false
}
this.starprnt.printRawText(null, 'StarLine', printObj)
.then(result => {
alert("Success!")
}).catch(error => {
alert("communication error")
})
Only starts firing after the connect() function has been called
this.printerStatusSuscription = this.starprnt.getStatus()
.subscribe(printerStatus =>{
this.zone.run(() => {
console.log(printerStatus.dataType);
});
});
Printer Events
- Printer cover open: printerCoverOpen
- Printer cover close: printerCoverClose
- Printer impossible: printerImpossible
- Printer online: printerOnline
- Printer offline: printerOffline
- Printer paper empty: printerPaperEmpty
- Printer paper near empty: printerPaperNearEmpty
- Printer paper ready: printerPaperReady
- AlignmentPosition
- BarcodeSymbology
- BarcodeWidth
- BitmapConverterRotation
- BlackMarkType
- CutPaperAction
- FontStyleType
- InternationalType
- LogoSize
- QrCodeLevel
- QrCodeModel