Code Monkey home page Code Monkey logo

starprndemoionicv2's Introduction

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


starprndemoionicv2's People

Contributors

infoxicator avatar nicksonyap avatar rcasascalculus avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

starprndemoionicv2's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.