tmalbonph / cordova-plugin-sunmi-inner-printer

Cordova/Ionic Plugin for Sunmi V1 Printer
MIT License
15 stars 19 forks source link

Check sunmi v1 plugin printer status #3

Closed saravanacs closed 5 years ago

saravanacs commented 5 years ago

Please anyone help me, Using Cordova sunmi printer is working fine. But, i need Printer status before printing. Example, Validate printer status, Don't allow to do printer is not available and not ready or paper not available.

Thanks in Advance

tmalbonph commented 5 years ago

Please anyone help me, Using Cordova sunmi printer is working fine. But, i need Printer status before printing. Example, Validate printer status, Don't allow to do printer is not available and not ready or paper not available.

Thanks in Advance

Hi @saravanacs What is the SUNMI device you are using? I can only verify on sunmi V1.

saravanacs commented 5 years ago

@tmalbonph Hi sir, i use Sunmi V1

tmalbonph commented 5 years ago

@tmalbonph Hi sir, i use Sunmi V1

  1. For paper not available, you can only detect it while your printing.
  2. If you are not targeting Native java code, you won't be able to check the status of the printer unless you remember its status during printer setup.
  3. If you are targeting Javascript base solution like phonegap and ionic3+, I can help you but the code is not in the public domain.
  4. Refer to the updated source here: https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer
saravanacs commented 5 years ago

@tmalbonph I write below code for printing data, but before printing check printer is available and above mentioned validations

checkPrint(data) { /try { //this.printerInfo = sunmiInnerPrinter.hasPrinter(); sunmiInnerPrinter.printerInit(); sunmiInnerPrinter.printTextWithFont('\nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers \nABC Computers ', 'Calibri', 36); if (JSON.stringify(sunmiInnerPrinter) !== "{}") { this.printerInfo = JSON.stringify(sunmiInnerPrinter); return; } this.printerInfo = sunmiInnerPrinter.hasPrinter(); // it is safe to use sunmiInnerPrinter here } catch (err) { this.printerInfo = ("error: " + JSON.stringify(err.message)); }/ try {

var address = data.BranchAddress; //var name = "Saravana Kumar. M" var receiptNo = data.ReceiptNo; var subscriberName = data.SubscriberName; var receivedAmount = data.ReceivedAmount; var pendingAmount = data.PendingAmount; var advanceAmount = data.AdvanceAmount; var paymentMode = data.PaymentMode; var collectionAgent = data.PreparedBy; var group = data.Group; sunmiInnerPrinter.printString("Receipt No: "+receiptNo+ "\n"+"Date : "+'20-09-2019'); sunmiInnerPrinter.printTextWithFont('\n\t Test Pvt.Ltd ', 'Segoe UI Black', 32); sunmiInnerPrinter.printString("\n\t"+address+"\n"); sunmiInnerPrinter.printTextWithFont('\nName : '+subscriberName, 'Arial Black', 30); sunmiInnerPrinter.printString("\n------------------------------\n"+"Group : "+group+"\n"+"Received Amount : Rs. "+receivedAmount+"\n"+"Pending Amount : Rs. "+pendingAmount + "\n"+ "Advance Amount : Rs."+advanceAmount+"\n"+"Payment Mode : "+paymentMode+"\n"+"------------------------------"+"\n"+"* System generated Bill."+"\n"+"\t Prepared by : "+collectionAgent+"\n"+"No Signature Needed\n"+"\n\t\t\t\t\tThank You ..!!\n\n"+"\n\n") } catch (err) { this.printerInfo = ("error: " + JSON.stringify(err.message)); } }

saravanacs commented 5 years ago

@tmalbonph https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer

In this link, where is located printer status code( i mean file location) sir

tmalbonph commented 5 years ago

@tmalbonph https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer

In this link, where is located printer status code( i mean file location) sir

You will need to use the plugin entry here: cordova-plugin-sunmi-inner-printer/www/innerprinter.js

tmalbonph commented 5 years ago

For example

  printString: function (text, resolve, reject) {
    exec(resolve, reject, "Printer", "printString", [text]);
  },

there is a resolve and reject parameter entry, at reject callback, you can detect status of the printer being printed in progress. That is the only reliable way to check for the status.

saravanacs commented 5 years ago

  printString: function (text, resolve, reject) {
    exec(resolve, reject, "Printer", "printString", [text]);
  },

Where i put this code sir. I posted my print function code above . Please edit that code sir and send me where set resolve and reject functionality

tmalbonph commented 5 years ago
  printString: function (text, resolve, reject) {
    exec(resolve, reject, "Printer", "printString", [text]);
  },

Where i put this code sir. I posted my print function code above . Please edit that code sir and send me where set resolve and reject functionality

It is not that simple, You need to code at a minimum of 120-550 lines of code to make the robust printing code works on SUNMI V1 using Javascript. More codes if your using ionic3+

tmalbonph commented 5 years ago

If you want to get your hands dirty; you need to digest my suggestion from top to bottom on this thread here: https://github.com/labibramadhan/cordova-sunmi-inner-printer/issues/14

saravanacs commented 5 years ago

https://stackoverflow.com/questions/44655755/ionic-2-application-to-print-via-sunmi-v1/44727956#44727956

@tmalbonph for above link, cordova plugin printer using check printer is available. If i use this steps for get printer status ? is it possible sir ?

tmalbonph commented 5 years ago

https://stackoverflow.com/questions/44655755/ionic-2-application-to-print-via-sunmi-v1/44727956#44727956

@tmalbonph for above link, cordova plugin printer using check printer is available. If i use this steps for get printer status ? is it possible sir ?

Yes that is the basic idea, as I have mention on top of this thread, you need to provide both the resolve and reject callback to monitor status of your printer and the data your application is printing.