cordova-sunmi-inner-printer
cordova-sunmi-inner-printer copied to clipboard
Paper Cut Command is not there...
I cant find the Command to cut the paper. please help... My all other functionalities are working fine. i only need command to cut the paper.
:(
I Tried implementing that myself but it is not working.
SunmiPrinter Developer documentation_2.pdf
I manage to cut the Paper using the Documentation. Here is what i have done to achieve it. 1. cordova-sunmi-inner-printer\src\android\woyou\aidlservice\jiuiv5\IWoyouService.aidl
in this file add this code given below if its not there already after this line void commitPrinterBuffer();
/**
*切纸
*/
void cutPaper(in ICallback callback);
/**
* 获取切刀次数
*/
int getCutPaperTimes();
cordova-sunmi-inner-printer\src\android\com\sunmi\innerprinter\Printer.java
add this code in that file after this method : ->public void printOriginalText(String text, final CallbackContext callbackContext) {
public void cutPaper(final CallbackContext callbackContext) {
final IWoyouService printerService = woyouService;
ThreadPoolManager.getInstance().executeTask(new Runnable() {
@Override
public void run() {
try {
printerService.cutPaper(new ICallback.Stub() {
@Override
public void onRunResult(boolean isSuccess) {
if (isSuccess) {
callbackContext.success("");
} else {
callbackContext.error(isSuccess + "");
}
}
@Override
public void onReturnString(String result) {
callbackContext.success(result);
}
@Override
public void onRaiseException(int code, String msg) {
callbackContext.error(msg);
}
});
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "ERROR: " + e.getMessage());
callbackContext.error(e.getMessage());
}
}
});
}
Also place this condition on the Top after this code: ->else if (action.equals("printerSelfChecking")) { printerSelfChecking(callbackContext); return true; }
else if (action.equals("cutPaper")) {
cutPaper(callbackContext);
return true;
}
cordova-sunmi-inner-printer\www\innerprinter.js
in this file just add another condition.
cutPaper: function () {
return new Promise(function (resolve, reject) {
cordova.exec(resolve, reject, "Printer", "cutPaper", []);
});
},
- Remove and add platform again @android6.3.0 and just call that function now.
window.sunmiInnerPrinter.cutPaper();
👍
I was able to cut paper with following raw commands (without modifying plugin code)
var cutpaper = [0x1d, 0x56, 0x42, 0x00];
var cutpaperUint8 = new Uint8Array(cutpaper);
var cutpaperBase64 = BufferToBase64(cutpaperUint8);
window.sunmiInnerPrinter.sendRAWData(cutpaperBase64);
function BufferToBase64(buf) {
var binstr = Array.prototype.map.call(buf, function (ch) {
return String.fromCharCode(ch);
}).join('');
return btoa(binstr);
}
I was able to cut paper with following raw commands (without modifying plugin code)
var cutpaper = [0x1d, 0x56, 0x42, 0x00]; var cutpaperUint8 = new Uint8Array(cutpaper); var cutpaperBase64 = BufferToBase64(cutpaperUint8); window.sunmiInnerPrinter.sendRAWData(cutpaperBase64); function BufferToBase64(buf) { var binstr = Array.prototype.map.call(buf, function (ch) { return String.fromCharCode(ch); }).join(''); return btoa(binstr); }
Hi @nileshgamit
I use your code to my home.ts
cutpuper(){ var cutpaper = [0x1d, 0x56, 0x42, 0x00]; var cutpaperUint8 = new Uint8Array(cutpaper); var cutpaperBase64 = BufferToBase64(cutpaperUint8); sunmiInnerPrinter.sendRAWData(cutpaperBase64);
function BufferToBase64(buf) { var binstr = Array.prototype.map.call(buf, function (ch) { return String.fromCharCode(ch); }).join(''); return btoa(binstr); } }
But It's nothing happen on the sunmi v1, can you teach me please, Thank's a lot
@uokivan I can confirm that sunmi v1 prints and cut the paper after print with this plugin and code I've provided. You may try removing local cache for project before rebuilding your app.
Just for your information, I'm using meteor 1.7.0.5 with cordova 6.4.0 to build Android app.
Here is the entire code for your reference. sunmi-print-code.txt
One point to note here is, 'sunmi is not printing text in order with non-native app'. I had couple of conversation with their support team and there was no resolution for this issue, so we ended up using Bixolon 302 printer.
@nileshgamit Not working for me on the Sunmi V1 as well.
@yunhan0 I'm using this plugin - https://www.npmjs.com/package/cordova-plugin-sunmi-inner-printer/v/1.0.3 with cordova 6.4.0 and nodejs v8.12.0. Building app on Ubuntu 16.04 LTS. Are you using same plugin? I am not sure if it helps. Can you share your code gist?
@nileshgamit I tried the plugin you mentioned, and I'm cordova using 6.5.0.
function sunmiPrint(data) {
// init printer by sunmi inbuilt function
window.sunmiInnerPrinter.printerInit()
window.sunmiInnerPrinter.printString('\n\n')
window.sunmiInnerPrinter.setAlignment(1)
sunmiSetBold()
window.sunmiInnerPrinter.printTextWithFont(data.name + '\n', '', 36)
sunmiUnbold()
/*** A lot of other printing code **/
window.sunmiInnerPrinter.setAlignment(0)
window.sunmiInnerPrinter.printString(
'Date: ' + Date(Date.now()).toString() + '\n'
)
sunmiCutPaper()
}
function sunmiSetBold() {
let bold = [0x1B,0x45,0x01]
let boldUint8 = new Uint8Array(bold)
var boldBase64 = BufferToBase64(boldUint8)
sunmiInnerPrinter.sendRAWData(boldBase64)
}
function sunmiUnbold() {
let bold = [0x1B,0x45,0x0]
let boldUint8 = new Uint8Array(bold)
var boldBase64 = BufferToBase64(boldUint8)
sunmiInnerPrinter.sendRAWData(boldBase64)
}
function sunmiCutPaper() {
let cutpaper = [0x1d, 0x56, 0x42, 0x00]
let cutpaperUint8 = new Uint8Array(cutpaper)
let cutpaperBase64 = BufferToBase64(cutpaperUint8)
window.sunmiInnerPrinter.sendRAWData(cutpaperBase64)
}
The set bold and cancel bold command is working fine, but cutting paper doesn't work for me. I read Sunmi's documentation, and can confirm 0x1d, 0x56, 0x42, 0x00 is the right command.
@yunhan0 Code looks good. I doubt if it has anything to do with Sunmi printer model. I was playing around with sunmi T1 mini POS with inbuilt printer. Try removing "window." as it's going to be app code. Also, try printing "new line" after Cutter command.
Hello @nileshgamit
I implemented a POS app for Sunmi T1 Mini and i want to print a page but i am using xamarin forms, xamarin not support java, it's support C#. How can print a page..
Hello @nileshgamit , @yunhan0 , @ahmad6242
I implemented some code for print string
public void Print(string PrintText)
{
var context = Android.App.Application.Context;
intent.SetPackage("woyou.aidlservice.jiuiv5");
intent.SetAction("woyou.aidlservice.jiuiv5.IWoyouService");
context.StartService(intent);
context.BindService(intent, connService, 0);
callback = default(ICallback);
connService.Service.PrinterInit(callback);
connService.Service.SetAlignment(0, callback);
//connService.Service.PrintQRCode("http://weixin.qq.com/r/znVheSDEAn19rWQa9yDc", 8, 2, callback);
connService.Service.PrintText(PrintText, callback);
connService.Service.LineWrap(3, callback);
connService.Service.CutPaper(callback);
}
}
But i want to print a image with some text which print method support it.
A new query what is the use of this method sunmiInnerPrinter.sendRAWData(cutpaperBase64); .