SunmiPrinter EN 0224
SunmiPrinter EN 0224
Document Revisions
Version Undate Date Updates Owner
- 1-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Modification: rearrange the
1.1.180912 2018/09/12 田昆龙
document
- 2-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Introduction
Some SUNMI devices come with an inbuilt thermal printer (with
a buffer), which allow Apps to directly print thermal receipts
through SDK. The SUNMI devices which are equipped with a printer
are:
Mobile products – V1, V1s, V2 Pro, etc.
Smart payment products – P1, P1 4g, etc.
Desktop POS – T1, T2, T1 MINI, T2 MINI, etc.
POS scale – S2, etc.
There are two specs of inbuilt printers for SUNMI devices:
• Support 80mm paper width, paper cutter equipped,
compatible with the 58mm spec. T1 is equipped with this spec of
printer.
• Support 58mm paper width, no paper cutter. V1 is
equipped with this spec of printer.
● Integration
Add dependency and attribute configuration to the build.gradle under the directory
of the App:
dependencies{
implementation ‘com.sunmi:printerlibrary:1.0.13’
}
● Initialization
Like binding a service component, we can call the binding method through
singleton call
@Override
protected void onConnected(SunmiPrinterService service){
//Here is the remote service interface handle after the binding
service has been successfully connected
//Supported print methods can be called through service
}
@Override
protected void onDisconnected() {
//The method will be called back after the service is disconnected.
A reconnection strategy is recommended here
}
}
- 1-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
● A Simple Case to Call Print
try{
sunmiPrinterService.printText(“content to be printed\n”,
new InnerResultCallbcak() {
@Override
public void onRunResult(boolean isSuccess) throws
RemoteException {
//Return the execution result (not a real printing):
succeeded or failed
}
@Override
public void onReturnString(String result) throws
RemoteException {
//Some interfaces return inquired data
asynchronously
}
@Override
public void onRaiseException(int code, String msg) throws
RemoteException {
//The exception returned when the interface failed to
execute
}
@Override
public void onPrintResult(int code, String msg) throws
RemoteException {
//The real printing result returned in transaction
printing mode
}
}});
} catch (RemoteException e) {
e.printStackTrace();
//If some interfaces can only be used for specified device models, the
call error reminder will pop out. For example, the interface of a cash drawer can
only be used for a desktop device.
}
● Disconnection
After a normal call, you can call the following method to disconnect the service.
InnerPrinterManager.getInstance().unBindService(context, innerPrinterCallback);
- 2-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
● Class Specifications
InnerPrinterManager
InnerPrinterCallback
SunmiPrinterService
InnerPrinterException
InnerResultCallbcak
InnerLcdCallback
InnerTaxCallback
- 3-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.1.2.Via AIDL
Intro to AIDL
AIDL (Android Interface Definition language) is a description language of an
Andriod inner progress communication interface, which can be used to define the
commnucation interface in progress. SUNMI AIDL supplies capsulated common
printing cammands to facilitate developers’ quick access to SUNMI printers.
- 4-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
desktop (desktop devices) for SUNMI T1, T2, etc.
——Mainly includes:
IWoyouService.aidl
ICallback.aidl
ITax.aidl
desktop + lcd (desktop + customer display) for SUNMI desktop devices
with a customer display like T1mini, T2mini.
——Mainly includes:
IWoyouService.aidl
ICallback.aidl
ITax.aidl
ILcdCallback.aidl
General resource
WoyouConsts.java
- 5-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
void printerInit( )
1
Printer initialization
1.Printer Initialization
Function: void printerInit( )
Note: reset the logic programs (type setting, bold, etc.) of a printer but not to clear
the data in the buffer. Therefore, uncompleted print jobs will be continued after resetting.
2.Printer Self-Inspection
Function: void printerSelfChecking (ICallback callback)
Parameter: callback result callback.
Example:
woyouService.printerSelfChecking(callback);
String getPrinterSerialNo( )
1
Get the SN of a printer board
2 String getPrinterModal( )
Get printer type interface
3 String getPrinterVersion( )
Get printer firmware version
4 Build.MODEL (constant)
Device name
5 int updatePrinterState()
Get the latest status of a printer
6 String getServiceVersion()
Get the version number of a print service
- 6-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
8 int getPrinterPaper()
Get the current paper spec of a printer
Note: this interface is not available to V1 for now. aside from getting the status
actively, you can also obtain them asynchronously by registering broadcast. Please refer
to Appendix A.
- 7-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.2.3. ESC/POS Instruction
编号 方 法
No. Method
woyouService.sendRAWData(new
byte[]{0x1B,0x45,0x01}, callback);
// 1B,45, 01 are instructions to realize bold font
- 8-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Example:
woyouService.setPrinterStyle( WoyouConsts.ENABLE
_ILALIC,WoyouConsts.ENABLE);
//to print italic text for the content printed subsequently
woyouService.setPrinterStyle(WoyouConsts.SET_LINE
_SPACING,123);
// to realize the leading (123 pixels) for the content
printed subsequently
Note: this interface is only available to the print service (v4.2.22 and above)!
1 int getPrinterMode()
Get the printer mode
2 int getPrinterBBMDistance()
Paper feed distance
1.2.6.Character Printing
No. Method/Instruction
- 9-
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
esc/pos instruction: bold font {0x1B, 0x45, 0x1}, cancel bold font {0x1B,
4 0x45, 0x0}
Set and cancel the bold font effect
1.Set Alignment
Function: void setAlignment (int alignment, ICallback callback)
Parameter:
alignment alignment: 0 align left, 1 center, 2 align right.
callback Result callback.
Note: it is a global method which will affect the subsequent printing. If a printer
initialization method has been called, this method will be restored to its default setting.
Example:
woyouService.setAlignment(1, callback);
woyouService.setFontName("gh", callback);
- 10 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Note: it is a global method which will affect the subsequent printing. The settings will
be canceled if an initialization has been called. Setting font size is not included in the print
method in the standard international instruction, and it will affect character width and the
number of characters in a line correspondingly. As a result of this, the type setting based
on monospace font will be changed.
Example:
woyouService.setFontSize(36, callback);
woyouService.sendRAWData(new
byte[]{0x1B,0x45,0x0}, callback); // Cancel the instruction
of making fonts bold
5. Print Text
Function: void printText(String text, in ICallback callback)
Parameters:
text the text to be printed. The part of the text which exceeds a line will be
warped onto the next line. The force line break"\n" must be added to the end of a
line of content which not fully occupy the line in order to print this line of content,
otherwise it will be cached in the buffer.
callback Result callback.
Note: if a style (alignment, font size, bold, etc.) of the text to be printed needs to be
changed, please set before calling printText method.
Example:
woyouService.setAlignment(1, callback);
woyouService.setFontSize(36, callback);
woyouService.printText("商米科技 SUNMI
Technology\n", callback);
- 11 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
text the text to be printed. The part of the text which exceeds a line will be
wrapped onto the next line. The force line breaker "\n" must be added to the
end of a line of content which not fully occupy a line in order to print this line of text,
otherwise it will be cached in the buffer.
typeface font name (setting font is not available to the existing version.
Default).
fontsize font size. It takes effect only to this method.
callback Result callback.
Note: font setting is only valid for this time.
Example:
woyouService.printTextWithFont("商米
SUNMI\n","",36,callback);
Return value:
Note: output characters are in the same width of vector fonts, which means that
they are not monospace.
Example:
woyouService.printOriginalText
("κρχκμνκλρκνκνμρτυφ\n", callback);
- 12 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.Print a Row of a Table (Unavailable to Arabic
Characters)
Function: void printColumnsText(String[] colsTextArr, int[] colsWidthArr, int[]
colsAlign, ICallback callback)
Parameters:
colsTextArr each column’s array of text string.
colsWidthArr each column’s width array, which is calculated based on English
characters. Each Chinese character takes the space of two English characters, and
the width exceeds 0.
colsAlign each column’s alignment: 0 align left, 1 center, 2 align right.
callback Result callback.
Note: the array length of the three parameters should be the same. If the colsText[i]
is wider than the colsWidth[i], the exceeding part will be wrapped onto the next line. This
is unavailable to Arabic characters.
Example:
woyouService.printColumnsText(new String[]{"商米
SUNMI","商米 SUNMI","商米 SUNMI"}, new int[]{4,4,8},
new int[]{1,1,1},callback);
woyouService.printColumnsString(new String[]{"商米
SUNMI","商米 SUNMI","商米 SUNMI"}, new int[]{1,1,2},
new int[]{1,1,1},callback);
- 13 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.2.8. Print Images
编号 方 法
No. Method
1. Print Image
Function: void printBitmap (Bitmap bitmap, ICallback callback)
Parameters:
bitmap image Bitmap object.
callback Result callback.
Note: the resolution of an image should be within 2M, and the width should be set in
accordance with the paper spec (58: 384 Pixel, 80: 576 Pixel). It cannot be shown if it
exceeds the paper width.
Example:
woyouService.printBitmap(bitmap,callback);
Note: the resolution of an image should with within 2M, and the width should be set
in accordance with the paper spec (58mm: 384 Pixel, 80mm: 576 Pixel). It cannot be
shown if it exceeds the paper width.
Available to: P1 (v3.2.0 and above), P14g (v1.2.0 and above), V1s (v3.2.0 and above),
V2 (v1.0.0 and above), T1 (v2.4.0 and above), T2 (v1.0.5 and above), S2 (v1.0.5 and
above), T1mini (v2.4.1 and above), T2mini (v1.0.0 and above).
Example:
woyouService.printBitmapCustom(bitmap,callback);
- 14 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.2.9. Print 1D/2D Barcodes
No. Method
1. Print 1D Barcodes
Function: void printBarCode(String data, int symbology, int height, int width, int
textPosition, ICallback callback)
Parameters:
data the 1D barcode to be printed
symbology barcode type (0-8):
0 UPC-A
1 UPC-E
2 JAN13(EAN13)
3 JAN8(EAN8)
4 CODE39
5 ITF
6 CODABAR
7 CODE93
8 CODE128
height barcode height (ranges from 1-255. 162 by default).
width barcode width (ranges from 2-6. 2 by default).
textPosition text position (0-3)
0 don’t print text
1 text above the barcode
2 text under the barcode
3 text above and under the barcode
callback Result callback
- 15 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
8-digit numbers (the last digit is for parity check). The effective
ean8
length is 8 digits (numbers).
The effective length is 13 digits, and the last digit is for parity
ean13
check.
Example:
woyouService.printBarCode("1234567890", 8, 162, 2,
2, callback);
2. Print QR Barcodes
Function: void printQRCode (String data, int modulesize, int errorlevel, ICallback
callback)
Parameters:
data QR code to be printed.
modulesize the size of the QR code block. Unit: dot, which should be within 4-
16.
errorlevel QR code error correction level (0-3):
0 error correction level L ( 7%)
1 error correction level M (15%)
2 error correction level Q (25%)
3 error correction level H (30%)
callback Result callback.
Note: after calling this method, the content will be printed under normal print status,
and every QR code block is 4 Pixel (when smaller than 4 Pixel, the code parsing might fail).
version19 (93*93) is a maximum mode supported.
- 16 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Example:
woyouService.printQrCode("商米科技 SUNMI
Technology", 4, 3, callback);
3. Print 2D barcodes
Function: void print2DCode(String data, int symbology, int modulesize, int
errorlevel, ICallback callback)
Parameters:
data the 2D barcode to be printed.
symbology the type of 2D barcode
1 Qr (same as the printQRCode interface)
2 PDF417
3 DataMatrix
modulesize the effective code block size, and it varies in accordance with
different types of 2D barcode
Qr code 4~16 (same as the printQRCode interface)
PDF417 1~4
DataMatrix 4~16
errorlevel 2D barcode error correction level, and it varies in accordance with different
types of 2D barcodes
Qr code 0~3 (same as the printQRCode interface)
PDF417 0~8
DataMatrix ECC200 error correction is used by default, and adjustment on
setting is unavailable.
callback Result callback.
Note: after calling this method, the content will be printed under normal print status.
This interface is available to version 4.1.2 and above.
- 17 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
- 18 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
enterPrinterBuffer(true) ——enter into the transaction mode, the subsequent
orders won’t be outputted instantly
printText(/*something*/)
printBitmap(/*bitmap resource*/)
…… other print-relevant methods——print some content
commitPrinterBuffer()/commitPrinterBufferWithCallback(callback)——submit a
transaction, and the printer will start printing. The result (succeeded or failed)
will be returned in callback.
……Wait for the return of the last transaction
printText(/*something*/)
printBitmap(/*bitmap resource*/)
…… other print-relevant methods——you can choose to wait for the result of the
last transaction printing or proceed printing
commitPrinterBuffer()/commitPrinterBufferWithCallback(callback)——continue to
submit the next transaction, and the printer will continue to print at this time
exitPrinterBuffer(true)/exitPrinterBufferWithCallback(true, callback)——call it
when you need to exit transaction mode, and printing will be continued if new
data has been entered after the last submission, otherwise it won’t continue
printing.
2.
6. Detailed methods:
No. Method
void commitPrinterBuffer()
5
Submit transaction printing
- 19 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1. The lib package transaction printing interface
Function: void commitPrint (TranBean[] tranBean, ICallback callback)
Parameters:
tranBean Print job list.
callback Result callback.
Example:
woyouService.commitPrint(tranBean, callback);
woyouService.enterPrinterBuffer(false);
woyouService.exitPrinterBuffer(true);
- 20 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
false not to print the content in the queue of transacion and save it
to submit next time
callback Result callback
Versions supported: except V1 device.
Example
woyouService.exitPrinterBuffer(true);
woyouService.commitPrinterBuffer();
woyouService.commitPrinterBufferWithCallback(callback
);
Note: line feed by force. Implement n LFs on the paper after the content has been
printed.
Example:
woyouService.printBitmap(3, callback);
- 21 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
No. Method
int getCutPagerTimes()
2
Get the number of times a cutter has been used
1. Cut Paper
Function: void cutPaper (ICallback callback)
Parameter:
callback Result callback
Note: the gap between the printhead and the paper cutter will be filled up by calling
the interface to make sure the printed content won’t be cut.
It is only available to the desktop devices with a cutter.
Example:
woyouService.cutPager(callback);
int getOpenDrawerTimes()
2
Get the times a cash drawer has been opened
3 int getDrawerStatus()
Get the current status of a cash drawer
- 22 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Note: it is only available to the desktop devices with a cash drawer function.
Example:
woyouService.openDrawer(callback);
int getForcedDouble()
1
Get the status of global fonts in double height and double width
boolean isForcedAntiWhite()
2
Get the anti-white style enable of global fonts
3 boolean isForcedBold()
Get the bold style enable of global fonts
4 boolean isForcedUnderline()
Get the underline style enable of global fonts
5 int getForcedRowHeight()
Get the set value of global line height
6 int getFontName()
Get the font currently being used
7 int getPrinterDensity()
Get the printer density
Note: the interfaces above (except the interface to get the printer density) are
available to V1, V1s, P1 with a version v3.2.0 and above and P14g with a version v1.2.0
and above.
- 23 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
1.2.15. Description of the Customer Display
Interface
This is available to the devices of mini series. Please see the table below for
instruction:
No. Method
- 24 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
Note: only available to the desktop devices of mini series which have a customer
display. The text cannot be displayed if it is too long.
- 25 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
A developer can get te printer mode interface getPrinterMode() to find out the mode
of a printer.
2.Learn label paper – if it is the first time for you to use it or you have changed a
different type of label paper, please open setting->inbuilt printing->label learning and
click the button learn label paper which shows as the picture below.
This will initiate label paper learning process. Please ensure there are at least 3 pieces
of labels. A popoup box will show to indicate the result of learning when the learning
process ends.
Label-related interfaces:
No. Method
1 void labelLocate()
Position the next label
2 void labelOutput()
Output a label
Print a label:
Label-related interfaces only provide how to position a label, so printing a label
content shall be formed by developers to their needs, just like what should be done with
thermal printing. What should be paid attention to is the height of a label content should
- 26 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
be within the hight of a label, otherwise the content may exceed a label paper to the next
label or lead to an inaccurate label positioning.
If you use a 30mm-high label paper, a content of 240 (30mmx8 dots) pixel-high can
be printed. The default print line spacing is 32 pixel line, so an 8-line text content or a
384x240 high picture can be printed normally.
For example – how to form a simple label content:
labelLocate() //Positioning the label before printing is required
setPrinterStyle(WoyouConsts.ENABLE_BOLD, WoyouConsts.ENABLE)
//Set to realize bold fonts
linewrap(1, null) //Leave a blank line at the head
setAlignment(0, null) //Set the content to align left
printText(“商品 Item: ⾖豆浆 Soybean milk\n”, null)
//Print content, \n line feed is needed
printText(“到期时间 Expiration time: 12-13 14 时 12-13 14:00\n”, null)
//Print content, \n line feed is needed
printBarCode(“{C1234567890123456”, 8, 90, 2, 2, null)
//Print a barcode. Here the barcode printed is a code128c
type barcode with a height of 90, which occupies 154 pixel line (a blank line above and
below the barcode will be left)
printText(“\n”, null) //The barcode needs to be outputted with a line feed
labelOutput() //The label will be outputted in accordance with needs
after printing
A content basically take all the area of a label will be outputted, please see the picture
below:
A developer can add other APIs to design his/her desired label content.
Note: Currently label can only be used through interface method instead of
Bluetooth ESC command.
- 27 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
- 28 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
msg succeeded: null; failed: description on the exception.
Note: this interface return result indicates the results of instrctuction execution and
printing (it may take some time for printing).
-2 "# encoding is not support"; //#indicates that the #th byte went wrong
"oops,add task failed (the buffer of the task queue is 10M),please try
-3
later";
-5 "Illegal parameter";
- 29 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
- 30 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
2.2.1. The Tool Class BluetoothUtil, a Standard Tool for
Bluetooth Connection
public class BluetoothUtil {
- 31 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
2.2.2. Examples on Connecting Printing Service with
Bluetooth
1: Get BluetoothAdapter
if (btAdapter == null) {
Toast.makeText(getBaseContext(),"Please Open Bluetooth!",
Toast.LENGTH_LONG).show();
return;
}
2.2.3. Notes
A bluetooth devices can only be used by adding Bluetooth Permission
Decalaration to the project in the App:
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
- 32 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
3. Via JS in HTML
3.1. Description of JS
Essentially, calling a printer via JS is using JS bridge in HTML to operate Android native
codes to print, and print via Bluetooth or via AIDL. (SUNMI printer itself is not a network
printer, which means that the webpage application can not directly communicate with the
printer and an app to receive data on Andriod is needed.)
b. Initialize WebView.
WebView mWebView = (WebView) findViewById(R.id.wv_view);
// set the encoding
mWebView.getSettings().setDefaultTextEncodingName("utf-8");
// support js
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebChromeClient(new WebChromeClient());
- 33 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
//Add a corresponding webpage monitor class
mWebView.setWebViewClient(new WebViewClientDemo());
WebViewClientDemo extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//The current WebView will be used when opening a new link; other
system browsers won’t be used.
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
/**
* Register JavascriptInterface. You can name "lee" whatever you want.
* If you use "lee", you only need to use lee. method name () in html
* And you can call the method with the same name in
MyJavascriptInterface, and the parameters shall be the same.
*/
mWebView.addJavascriptInterface(new JsObject(), "lee");
}
}
class JsObject {
@JavascriptInterface
public void funAndroid(final String i) {
Toast.makeText(getApplicationContext(), "calling the local method
funAndroid by JS. " + i, Toast.LENGTH_SHORT).show();
try {
woyouService.printerSelfChecking(callback);//Using AIDL to print
something.
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
- 34 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
The temperature of
the printhead is back "woyou.aidlservice.jiuv5.NORMAL_HEATING_ACITON"
to normal
Something went
wrong when closing "woyou.aidlservice.jiuv5.COVER_ERROR_ACTION"
the lid
- 35 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
- 36 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
4. Why can’t I print the image even though I execute the
image printing?
First of all, the content to be printed (except QR code) which cannot fill a line will be
saved in the buffer. If you find the image cannot be printed out after calling the
printBitmap interface, the reason might be the image width is smaller than the paper
width. You can call the linewrap interface to print the buffered image.
If the method stated above failed, you need to check the callback of the interface to see
whether there is an exception. Commonly, an oversized image might be the cause of
failing to call the interface. SUNMI printers support images with a resolution smaller than
2M (not the actual size of an image), and the maximum displayable width depends on the
paper spec. As a result of this, developers need to adjust the size of the image to be
printed.
Additionally, if a developer sends a raster bitmap through Bluetooth hexadecimal
instruction and the printing failed, the developer needs to check whether there is a
mistake in the instruction, for a byte data error might affect the realization of the whole
instruction.
- 37 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
the code scanning speed. However, to print a barcode exceeding 25 or more, the value
can be set as 1.
public static byte[] getPrintBarCode(String data, int height, int width, int
textposition){
if(width < 1 || width > 6){width = 2;}
if(textposition < 0 || textposition > 3){textposition = 0;}
if(height < 1 || height>255){height = 162;}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try{
buffer.write(new byte[]{0x1D,0x66,0x01,0x1D,0x48,(byte)textposition,
0x1D,0x77,(byte)width,0x1D,0x68,(byte)height,0x0A});
byte[] barcode = checkCode128Auto(data.getBytes());
buffer.write(new byte[]{0x1D,0x6B,0x49,(byte)(barcode.length)});
buffer.write(barcode);
}catch(Exception e){
e.printStackTrace();
}
return buffer.toByteArray();
}
- 38 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
public static byte[] checkCode128Auto(byte[] data){
ByteArrayOutputStream temp = new ByteArrayOutputStream();
int pos = 0;
boolean mode_C = true;
temp.write(0x7b);
temp.write(0x43);
while(pos < data.length){
if(data[pos] == '{' && pos + 1 != data.length){
switch (data[pos + 1]){
case 'A':
case 'B':
if(mode_C){mode_C =
false;temp.write(data[pos++]);temp.write(data[pos++]);
}else{pos++;pos++;}
break;
case 'C':
if(!mode_C){mode_C =
true;temp.write(data[pos++]);temp.write(data[pos++]);
}else{pos++;pos++;}
break;
default:
break;}
}else if(pos + 1 == data.length){
if(mode_C){temp.write(0x7b);temp.write(0x42);mode_C = false;}
temp.write(data[pos++]);
}else if(data[pos] < '0' || data[pos] > '9'){
if(mode_C){temp.write(0x7b);temp.write(0x42);mode_C = false;}
temp.write(data[pos++]);
} else if(data[pos+1] < '0' || data[pos+1] > '9'){
if(mode_C){temp.write(0x7b);temp.write(0x42);mode_C = false;}
temp.write(data[pos++]);
temp.write(data[pos++]);
}else{
if(!mode_C){temp.write(0x7b);temp.write(0x43);mode_C = true;}
int left = data[pos] - '0';
int right = data[pos + 1] - '0';
int num = left*10 + right;
if(num < 0 || num > 99){
return null;
}else{
temp.write(num);
}
pos++;
pos++;
}
}
return temp.toByteArray();
}
- 39 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
On the premise of using the suitable resource document, please be sure that you have
introduced the static nested class Stub! in callback class generated by AIDL introduced.
new ICallback(…) —> new ICallback.Stub()
This problem won’t occur if the developer using remote introduction library follows the
document and uses the encapsulated InnerPrinterCallback class, etc.
- 40 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
7. How to select and set a character set.
Background: the inbuilt printers are compatible with the transmission in a form of
binary byte stream, so a character set must be selected and set for the text to be printed
which is sent in a form of byte code; multi-byte, GB18030 character encoding are the
default device settings.
[参数] [编码]
[Parameter] [Encoding]
0x00 || 0x48 "GB18030";
0x01 || 0x49 "BIG5";
0xFF “utf-8”;
The device settings can be adjusted in accordance to the needs of different countries
or other requirements to enable the printers to identify the data stream of the content to
be printed. To print CP437, please send:
- 41 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
- 42 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
8. Description of black mark print
SUNMI T1 can print using the printing paper with black marks which comply to the
standard.
Requirements on the printing paper with black marks: different from other
black mark printers, SUNMI T1 printer has no sensor to detect black marks but provide a
black mark printing function through reflectivity (if the reflectivity is not bigger than 6%
(Infrared wave lengths within 700-1000nm), the paper sensor will detect it as no paper).
Due to the different theory used, a SUNMI T1 printer in black mark print mode cannot
accurately locate the black mark as other black mark printers and there are some errors.
Requirement on the location of the black mark: the black mark should be in the
horizontal center for the paper sensor to detect it.
The theory SUNMI T1 used to realize black mark print:
The paper sensor and the cutter are not in the same horizontal line, and the black
mark on the paper will first run through the paper sensor (the location of 1) and then run
through the printhead (the location of 2) and finally arrive the location of the cutter (the
location of 3).d
In black mark print mode, if the printer detects that there is no paper, it will keeping
moving 7mm. After moving 7mm, if no paper has been detected, the printer will process it
as no paper, and if paper is detected after moving 7mm, the printer will process it as
black mark print.
If the content to be printed covers the black mark, the printing will be proceeded,
which means if the black mark arrives at the location of 2 and there is still a print job, the
print job will continue till it is completed.
- 43 -
上海商米科技有限公司打印机开发者文档
PrinterD eveloperD ocum entation ofShanghaiSU N M ITechnology Co.,Ltd.
In this mechanism, the end of content to be printed should keep a certain distance
with paper sensor (the end of content should keep a distance of 6mm with the black mark
edge) to ensure that the content is between 2 black marks.
Instruction sequence in the black mark print mode:
1. send the content to be printed
2. enter the instruction on moving the paper till the black mark has been detected
{0x1c, 0x28, 0x4c, 0x02, 0x00, 0x42, 0x31}
3. enter the cutter instruction {0x1d, 0x56, 0x00}
Users can change the black mark print mode and the location of cutter in Setting-
>Print->Inbuilt print management.
- 44 -