Skip to content

Commit ddf8cdc

Browse files
Add PartialCutPaper util
1 parent 4e15e2b commit ddf8cdc

5 files changed

Lines changed: 35 additions & 3 deletions

File tree

android/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
buildscript {
22
repositories {
3-
jcenter()
3+
// google()
4+
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

@@ -27,12 +31,11 @@ android {
2731

2832
repositories {
2933
google()
30-
jcenter()
3134
mavenCentral()
3235
}
3336

3437
dependencies {
3538
implementation 'com.facebook.react:react-native:+'
3639
implementation "com.google.zxing:core:3.3.0"
37-
implementation 'com.sunmi:printerlibrary:1.0.23'
40+
implementation 'com.sunmi:printerlibrary:1.0.24'
3841
}

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
@@ -146,6 +146,13 @@ public void cutpaper() throws Exception {
146146
sunmiPrinterService.cutPaper(null);
147147
}
148148

149+
/**
150+
* Partial cut via ESC/POS command for devices/cutters that support it.
151+
*/
152+
public void cutpaperPartial() throws Exception {
153+
sendRawData(BytesUtil.PartialCutPaper());
154+
}
155+
149156
/**
150157
* Initialize the printer
151158
* 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
@@ -336,4 +336,15 @@ public void cutPaper(final Promise promise) {
336336
promise.reject("0", e.getMessage());
337337
}
338338
}
339+
340+
@ReactMethod
341+
public void cutPaperPartial(final Promise promise) {
342+
try {
343+
SunmiPrintHelper.getInstance().cutpaperPartial();
344+
promise.resolve(null);
345+
} catch (Exception e) {
346+
e.printStackTrace();
347+
promise.reject("0", e.getMessage());
348+
}
349+
}
339350
}

index.d.ts

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

0 commit comments

Comments
 (0)