Skip to content

Ionic 2/3 Demo application using the cordova-plugin-starprnt for Star micronics printers and the Ionic-Native wrapper

Notifications You must be signed in to change notification settings

infoxicator/StarprnDemoIonicV2

Repository files navigation

StarPRNT Plugin Ionic 2/3 Demo Application

Application Demo using the @ionic-native/star-prnt wrappers for the cordova plugin StarPRNT

Install

Install the Cordova and Ionic Native plugins:

Add platform:

ionic cordova platform add android

or ionic cordova platform add ios

Install plugin: (should already be added)

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

Run:

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

SMPort Example:

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!');
 })

StarIOExtManager:

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") 
    })

getStatus Observable Example:

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

API Reference

Classes

Interfaces

Enumerations


About

Ionic 2/3 Demo application using the cordova-plugin-starprnt for Star micronics printers and the Ionic-Native wrapper

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published