Skip to content

Commit 0382acc

Browse files
Add PartialCutPaper util
1 parent c579bf7 commit 0382acc

5 files changed

Lines changed: 33 additions & 0 deletions

File tree

android/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
buildscript {
22
repositories {
3+
// google()
34
mavenCentral()
45
}
56

67
dependencies {
8+
// Update from 2.3.0 to at least 4.2.2 or 7.x
9+
// classpath 'com.android.tools.build:gradle:4.2.2'
710
classpath 'com.android.tools.build:gradle:2.3.0'
11+
812
}
913
}
1014

android/src/main/java/com/sunmi/v2/printer/BytesUtil.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,16 @@ public static byte[] CutPaper() {
284284
// 66D 0D
285285
return returnText;
286286
}
287+
288+
public static byte[] PartialCutPaper() {
289+
// from https://file.cdn.sunmi.com/SUNMIDOCS/SunmiPrinter-Developer-Docs-1-1.pdf
290+
// byte[] returnText = {0x20,0x0A, 0x1D, 0x56, 0x41, 0x00 }; // 切纸; GS V
291+
// 66D 0D
292+
293+
byte[] returnText = {0x20,0x0A, 0x1D, 0x56, 0x42, 0x01 }; // 部分切纸; GS V
294+
// 66D 1D
295+
return returnText;
296+
}
287297

288298
public static byte[] selfCheck(){
289299
byte[] returnText = {0x1F, 0x1B, 0x1F, 0x53};

android/src/main/java/com/sunmi/v2/printer/SunmiPrintHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ public void cutpaper() throws Exception {
175175
sunmiPrinterService.cutPaper(null);
176176
}
177177

178+
/**
179+
* Partial cut via ESC/POS command for devices/cutters that support it.
180+
*/
181+
public void cutpaperPartial() throws Exception {
182+
sendRawData(BytesUtil.PartialCutPaper());
183+
}
184+
178185
/**
179186
* Initialize the printer
180187
* All style settings will be restored to default

android/src/main/java/com/sunmi/v2/printer/SunmiV2PrinterModule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,15 @@ public void cutPaper(final Promise promise) {
345345
promise.reject("0", e.getMessage());
346346
}
347347
}
348+
349+
@ReactMethod
350+
public void cutPaperPartial(final Promise promise) {
351+
try {
352+
SunmiPrintHelper.getInstance().cutpaperPartial();
353+
promise.resolve(null);
354+
} catch (Exception e) {
355+
e.printStackTrace();
356+
promise.reject("0", e.getMessage());
357+
}
358+
}
348359
}

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export declare const SunmiV2Printer: {
2121
clearBuffer: () => Promise<void>;
2222
openCashDrawer: () => Promise<void>;
2323
cutPaper: () => Promise<void>;
24+
cutPaperPartial: () => Promise<void>;
2425
getPrinterStatus: () => Promise<
2526
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 505 | 507
2627
>;

0 commit comments

Comments
 (0)