@kduma-autoid/capacitor-sunmi-printer
v0.5.5
Published
Adapter for printing on internal printers of Sunmi POS devices
Downloads
175
Readme
@kduma-autoid/capacitor-sunmi-printer
Adapter for printing on internal printers of Sunmi POS devices
Install
npm install @kduma-autoid/capacitor-sunmi-printer
npx cap sync
Configuration
You can disable auto binding of the service by setting bindOnLoad
to false
in the plugin configuration in capacitor.config.ts
.
/// <reference types="@kduma-autoid/capacitor-sunmi-printer" />
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: "com.company.app",
...
plugins: {
SunmiPrinter: {
bindOnLoad: true
}
}
}
export default config;
Example Usage
You can interact with the printer in two ways:
- You can build the prints procedurally using method calls. It's ideal for smaller printouts and in new projects.
- Or you can print by sending commands from a subset of ESC/POS print language - it's ideal for larger documents, legacy applications or when receiving whole printouts from a remote server.
Example 1 - Printing using built-in methods
SunmiPrinter.enterPrinterBuffer();
SunmiPrinter.setFontSize({ size: 35 });
SunmiPrinter.setBold({ enable: true });
SunmiPrinter.setAlignment({ alignment: AlignmentModeEnum.LEFT });
SunmiPrinter.printText({ text: "This is an\n" });
SunmiPrinter.setFontSize({ size: 65 });
SunmiPrinter.setBold({ enable: false });
SunmiPrinter.setAlignment({ alignment: AlignmentModeEnum.CENTER });
SunmiPrinter.setAntiWhitePrintStyle({ enable: true });
SunmiPrinter.printText({ text: "EXAMPLE\n" });
SunmiPrinter.setFontSize({ size: 30 });
SunmiPrinter.setAlignment({ alignment: AlignmentModeEnum.RIGHT });
SunmiPrinter.setAntiWhitePrintStyle({ enable: false });
SunmiPrinter.printText({ text: "of a SunmiPrinter plugin\n" });
SunmiPrinter.setAlignment({ alignment: AlignmentModeEnum.CENTER });
SunmiPrinter.printBarCode({ content: "1234567890", symbology: BarcodeSymbologyEnum.CODE_128, height: 100, width: 2, text_position: BarcodeTextPositionEnum.BELOW });
SunmiPrinter.lineWrap({lines: 3});
SunmiPrinter.exitPrinterBuffer();
Example 2 - Printing already prepared ESC/POS commands
SunmiPrinter.enterPrinterBuffer();
const escpos = "\u001b@\u001ba\u0001\u001d!\u0011Hello\n\u001bE\u0001\u001d!\u0010SunmiPrinter\n\u001bE\u0000\u001d!\u0013EXAMPLE\n\u001d!\u0000\u001bE\u0001plugin\n\n\n\n\u001bE\u0000";
SunmiPrinter.sendRAWData({data: escpos});
SunmiPrinter.exitPrinterBuffer();
API
bindService()
unBindService()
getServiceStatus()
printerInit()
printerSelfChecking()
getPrinterSerialNo()
getPrinterModel()
getPrinterVersion()
getDeviceName()
updatePrinterState()
getServiceVersion()
getPrintedLength()
getPrinterPaper()
sendRAWData(...)
sendRAWBase64Data(...)
setPrinterStyle(...)
setDoubleWidthPrintStyle(...)
setDoubleHeightPrintStyle(...)
setBoldPrintStyle(...)
setUnderlinePrintStyle(...)
setAntiWhitePrintStyle(...)
setStrikethroughPrintStyle(...)
setItalicPrintStyle(...)
setInvertPrintStyle(...)
setTextRightSpacingPrintStyle(...)
setRelativePositionPrintStyle(...)
setAbsolutePositionPrintStyle(...)
setLineSpacingPrintStyle(...)
setLeftSpacingPrintStyle(...)
setStrikethroughStylePrintStyle(...)
getPrinterMode()
isLabelMode()
getPrinterBBMDistance()
setAlignment(...)
setFontName(...)
setFontSize(...)
setBold(...)
printText(...)
printTextWithFont(...)
printOriginalText(...)
printColumnsText(...)
printColumnsString(...)
printBitmap(...)
printBitmapCustom(...)
printBarCode(...)
printQRCode(...)
print2DCode(...)
enterPrinterBuffer(...)
exitPrinterBuffer(...)
exitPrinterBufferWithCallback(...)
commitPrinterBuffer()
commitPrinterBufferWithCallback()
lineWrap(...)
cutPaper()
getCutPaperTimes()
openDrawer()
getOpenDrawerTimes()
getDrawerStatus()
getForcedDouble()
isForcedAntiWhite()
isForcedBold()
isForcedUnderline()
getForcedRowHeight()
getFontName()
getPrinterDensity()
sendLCDCommand(...)
sendLCDInitializationCommand()
sendLCDWakeUpCommand()
sendLCDHibernateCommand()
sendLCDClearCommand()
sendLCDString(...)
sendLCDDoubleString(...)
sendLCDMultiString(...)
sendLCDFillString(...)
sendLCDBase64Bitmap(...)
sendLCDAsciiBitmap(...)
sendLCDBarcode(...)
labelLocate()
labelOutput()
addListener('onPrinterStatusUpdated', ...)
removeAllListeners()
- Interfaces
- Enums
bindService()
bindService() => Promise<void>
bind print service
unBindService()
unBindService() => Promise<void>
unbind print service
getServiceStatus()
getServiceStatus() => Promise<{ status: ServiceStatusEnum; }>
Get the print service current status
Returns: Promise<{ status: ServiceStatusEnum; }>
printerInit()
printerInit() => Promise<void>
Printer initialization
Note: reset the printer's logical program, such as typography, bold, etc., without emptying the cached data, then the unfinished print tasks will continue after resetting.
printerSelfChecking()
printerSelfChecking() => Promise<void>
Printer self-checking
getPrinterSerialNo()
getPrinterSerialNo() => Promise<{ serial_number: string; }>
Get the printer’s serial no.
Returns: Promise<{ serial_number: string; }>
getPrinterModel()
getPrinterModel() => Promise<{ model: string; }>
Get the interface of printer model
Returns: Promise<{ model: string; }>
getPrinterVersion()
getPrinterVersion() => Promise<{ version: string; }>
Get the printer’s firmware version no.
Returns: Promise<{ version: string; }>
getDeviceName()
getDeviceName() => Promise<{ name: string; }>
Device name
Returns: Promise<{ name: string; }>
updatePrinterState()
updatePrinterState() => Promise<{ status: PrinterStatusEnum; code: number; }>
Get the printer’s latest status
1 → Printer is under normal operation 2 → Printer is under preparation 3 → Communication is abnormal 4 → Out of paper 5 → Overheated 6 → Cover is open 7 → Cutter error 8 → Cutter recovered 9 → Black mark not detected 505 → Printer not detected 507 → Printer firmware update failed
Note 1: these return values are applicable to all SUNMI devices, but some status can’t be obtained due to hardware configuration. For example, cover open detection is not applicable to handheld devices.
Note 2: V1 devices currently can’t support this interface; you can also get it asynchronously by registering broadcast apart from getting status proactively
Returns: Promise<{ status: PrinterStatusEnum; code: number; }>
getServiceVersion()
getServiceVersion() => Promise<{ version: string; }>
Get the printing service version no.
Returns: Promise<{ version: string; }>
getPrintedLength()
getPrintedLength() => Promise<{ length: number; }>
Get the print length of the printhead
Note: currently you can get the printed length since powering on the device.
Due to the hardware differences between desktop devices and handheld devices, the returns of printing results may vary. In other words, you can get the printed length through ICallback callback interface for handheld devices, and get the printed length directly through the return values for desktop devices.
Returns: Promise<{ length: number; }>
getPrinterPaper()
getPrinterPaper() => Promise<{ paper: number; }>
Get the printer’s current paper specification
Note 1: by default, 58mm paper specification is adopted for handheld printers, and 80mm paper specification for desktop printers but you can add a fixator and set the printer to use a 58mm paper roll by configuration, and the interface will return the current paper specification set for the printer.
Note 2: currently, desktop device T1 model with versions above v2.4.0 supports this interface; T2 and S2 models with versions above v1.0.5 support this interface; for other device models with versions above v4.1.2, they all support this interface for getting paper specification.
Returns: Promise<{ paper: number; }>
sendRAWData(...)
sendRAWData(options: { data: string; }) => Promise<void>
Commands of printing ESC/POS format
| Param | Type |
| ------------- | ------------------------------ |
| options
| { data: string; } |
sendRAWBase64Data(...)
sendRAWBase64Data(options: { data: string; }) => Promise<void>
Commands of printing ESC/POS format encoded in Base64
| Param | Type |
| ------------- | ------------------------------ |
| options
| { data: string; } |
setPrinterStyle(...)
setPrinterStyle(options: { key: PrinterStyleKeysEnum; value: number | PrinterStyleValuesEnum; }) => Promise<void>
Set printer style
Parameter: set the const class by referring to WoyouConsts.java printer style.
key → set different attributes according to the definition in the const class interface, usually being ENABLE_XXX and SET_XXX.
value → set status or size corresponding to the attributes Select ENABLE or DISABLE for ENABLE XXX attribute. Set the detailed size for SET_XXX attribute.
Note: this interface is available for the printing service with versions above v4.2.22.
| Param | Type |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| options
| { key: PrinterStyleKeysEnum; value: number | PrinterStyleValuesEnum; } |
setDoubleWidthPrintStyle(...)
setDoubleWidthPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets double-width print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setDoubleHeightPrintStyle(...)
setDoubleHeightPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets double-height print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setBoldPrintStyle(...)
setBoldPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets bold print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setUnderlinePrintStyle(...)
setUnderlinePrintStyle(options: { enable: boolean; }) => Promise<void>
Sets underline print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setAntiWhitePrintStyle(...)
setAntiWhitePrintStyle(options: { enable: boolean; }) => Promise<void>
Sets anti-white print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setStrikethroughPrintStyle(...)
setStrikethroughPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets strikethrough print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setItalicPrintStyle(...)
setItalicPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets italic print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setInvertPrintStyle(...)
setInvertPrintStyle(options: { enable: boolean; }) => Promise<void>
Sets inverted print style
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
setTextRightSpacingPrintStyle(...)
setTextRightSpacingPrintStyle(options: { value: number; }) => Promise<void>
Sets text right spacing print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
setRelativePositionPrintStyle(...)
setRelativePositionPrintStyle(options: { value: number; }) => Promise<void>
Sets relative position print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
setAbsolutePositionPrintStyle(...)
setAbsolutePositionPrintStyle(options: { value: number; }) => Promise<void>
Sets absolute position print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
setLineSpacingPrintStyle(...)
setLineSpacingPrintStyle(options: { value: number; }) => Promise<void>
Sets line spacing print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
setLeftSpacingPrintStyle(...)
setLeftSpacingPrintStyle(options: { value: number; }) => Promise<void>
Sets left spacing print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
setStrikethroughStylePrintStyle(...)
setStrikethroughStylePrintStyle(options: { value: number; }) => Promise<void>
Sets strikethrough style print style
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: number; } |
getPrinterMode()
getPrinterMode() => Promise<{ mode: PrinterModeEnum; code: number; }>
Get printer mode
Return value:
0 → General mode 1 → Black mark mode 2 → Label mode
Note: black mark mode currently is available for SUNMI T1, T2 desktop terminals; Label mode currently is available for SUNMI V2, V2 Pro handheld terminals.
Returns: Promise<{ mode: PrinterModeEnum; code: number; }>
isLabelMode()
isLabelMode() => Promise<{ label_mode: boolean; }>
Checks whether the printer is in label mode
Returns: Promise<{ label_mode: boolean; }>
getPrinterBBMDistance()
getPrinterBBMDistance() => Promise<{ distance: number; }>
Get paper moving distance set under black mark mode
Return value: paper moving distance (number of pixels)
Note: only available for T1, T2 devices.
Returns: Promise<{ distance: number; }>
setAlignment(...)
setAlignment(options: { alignment: AlignmentModeEnum; }) => Promise<void>
Set alignment mode.
Note: global method may influence the subsequent print implementation, and you can cancel the related settings when initializing the printer.
| Param | Type |
| ------------- | ------------------------------------------------------------------------------- |
| options
| { alignment: AlignmentModeEnum; } |
setFontName(...)
setFontName(options: { typeface: string; }) => Promise<void>
Set custom print font.
typeface → specify the custom font name you’re about to use. Currently only vector font supported, and the font needs to be preset in the app assets directory.
Note 1: this interface can expand the default font type in the printer for you to use a custom font. However, you have to adjust the line spacing and line width due to the inconsistent inner width of each font.
Note 2: this interface is available for the printing service with versions above v4.14.0.
| Param | Type |
| ------------- | ---------------------------------- |
| options
| { typeface: string; } |
setFontSize(...)
setFontSize(options: { size: number; }) => Promise<void>
Set font size.
Note: global method may influence the subsequent printing, and you can cancel this setting using printer initialization. The font size adopts the printing method exceeding the standard international commands, and the adjustment of font size may affect the character width, which leads to the change to the number of each line’s characters. So typography of monospaced fonts can be confusing some time.
| Param | Type |
| ------------- | ------------------------------ |
| options
| { size: number; } |
setBold(...)
setBold(options: { enable: boolean; }) => Promise<void>
Set bold
| Param | Type |
| ------------- | --------------------------------- |
| options
| { enable: boolean; } |
printText(...)
printText(options: { text: string; }) => Promise<void>
Print text.
text → text to be printed; automatic linefeed will be implemented when the text width exceeds one line, and the forced newline character "\n" shall be added at the end of one line when the text width is less than one line or exceeds one line but not meeting one line before being printed, or it will be cached.
Note: if you need to change the style of print text, such as alignment mode, font size, bold, etc., please set it before calling printText method.
| Param | Type |
| ------------- | ------------------------------ |
| options
| { text: string; } |
printTextWithFont(...)
printTextWithFont(options: { text: string; typeface: string; size: number; }) => Promise<void>
Print text with designated font and size.
text → text to be printed; automatic linefeed will be implemented when the text width exceeds one line, and the forced newline character "\n" shall be added at the end of one line when the text width is less than one line or exceeds one line but not meeting one line before being printed, or it will be cached. Typeface → the custom font name. Currently only vector fonts are supported, and the font needs to be preset in the app assets directory. fontSize → font size; only available for this method.
Note: the font setting of this interface is available for the printing service with versions above v4.14.0.
| Param | Type |
| ------------- | -------------------------------------------------------------- |
| options
| { text: string; typeface: string; size: number; } |
printOriginalText(...)
printOriginalText(options: { text: string; }) => Promise<void>
Print vector font.
text → text to be printed; automatic linefeed will be implemented when the text width exceeds one line, and the forced newline character "\n" shall be added at the end of one line when the text width is less than one line or exceeds one line but not meeting one line before being printed, or it will be cached.
Note: the text is printed according to the vector text width, which means that each character is not monospaced.
| Param | Type |
| ------------- | ------------------------------ |
| options
| { text: string; } |
printColumnsText(...)
printColumnsText(options: { lines: { text: string; width: number; align: AlignmentModeEnum; }[]; }) => Promise<void>
Print a column of a table (Arabic characters are not supported)
colsTextArr → Array of column text strings. colsWidthArr → Array of each column width, calculated in English characters, and each Chinese character is equal to two English characters, with each width > 0. colsAlign → Alignment mode of each column: 0: left; 1: center; 2: right.
Note: the array length of the above three parameters should be consistent. If the width of colsText[i] is larger than that of colsWidth[i], the text will be changed to another line, and Arabic characters are not supported.
| Param | Type |
| ------------- | ---------------------------------------------------------------------------------------------------------------------- |
| options
| { lines: { text: string; width: number; align: AlignmentModeEnum; }[]; } |
printColumnsString(...)
printColumnsString(options: { lines: { text: string; proportion: number; align: AlignmentModeEnum; }[]; }) => Promise<void>
Print a column of a table, and you can specify the column width and alignment mode.
olsTextArr → Array of column text strings. colsWidthArr → The width weight of each column is the proportion of each column. colsAlign → Alignment mode of each column: 0: left; 1: center; 2: right.
Note: the array length of the above three parameters should be consistent. If the width of colsText[i] is larger than that of colsWidth[i], the text will be changed to another line.
| Param | Type |
| ------------- | --------------------------------------------------------------------------------------------------------------------------- |
| options
| { lines: { text: string; proportion: number; align: AlignmentModeEnum; }[]; } |
printBitmap(...)
printBitmap(options: { bitmap: string; }) => Promise<void>
Print an image
Note: the maximum pixel size of the image should be less than 2.5 million pixels of width x height, and the width should be set according to the size of paper specification (384 pixels for 58mm paper, and 576 pixels for 80mm paper). If it exceeds the width of the paper, it will not be displayed.
| Param | Type |
| ------------- | -------------------------------- |
| options
| { bitmap: string; } |
printBitmapCustom(...)
printBitmapCustom(options: { bitmap: string; type: BitmapPrintTypeEnum; }) => Promise<void>
Print an image (2)
bitmap → image: bitmap object; the biggest width is 384 pixels, and the image can’t be printed when exceeding 1M. type → currently two printing methods are available: 0 → the same as printBitmap(); 1 → black and white image with a threshold of 200 2 → grayscale image
Note: the image resolution is less than 2 million pixels, and the width should be set according to the size of paper specification (384 pixels for 58mm paper, and 576 pixels for 80mm paper). If it exceeds the width of the paper, it will not be displayed.
Versions supported: v3.2.0 above for P1; v1.2.0 above for P14g; v3.2.0 above for V1s; v1.0.0 above for V2; v2.4.0 above for T1; v1.0.5 above for T2, S2; v2.4.1 above for T1mini; v1.0.0 above for T2mini.
| Param | Type |
| ------------- | ---------------------------------------------------------------------------------------------- |
| options
| { bitmap: string; type: BitmapPrintTypeEnum; } |
printBarCode(...)
printBarCode(options: { content: string; symbology: BarcodeSymbologyEnum; height: number; width: number; text_position: BarcodeTextPositionEnum; }) => Promise<void>
Print a 1D barcode.
data → 1D barcode content symbology → barcode type (0 – 8): 0 → UPC-A 1 → UPC-E 2 → JAN13 (EAN13) 3 → JAN8 (EAN8) 4 → CODE39 5 → ITF 6 → CODABAR 7 → CODE 93 8 → CODE128 height → barcode height from 1 – 255, with default value of 162 width → barcode width from 2 – 6, with default value of 2 textPosition → text position (0 -3) 0 → not to print text 1 → text is above barcode 2 → text is below barcode 3 → print text above and below the barcode
Note: different barcode types have the following differences:
code39 A maximum of 13 digits can be printed code93 A maximum of 17 digits can be printed ean8 8 digits required, with the last one as a check digit, and the valid length of 8 digits ean13 The valid length consists of 13 digits, the last of which is a check digit ITF Require to enter number, with valid length less than 14 digits, and must be an even number Codebar Require to enter numbers from 0 – 9, with 6 special characters, and a maximum of 18 digits can be printed UPC-E 8 digits required, with the last one as a check digit UPC-A 12 digits required, with the last one as a check digit code128 Three types for Code128:
- Type A: including uppercase letters, numbers, and punctuation marks;
- Type B: uppercase letters, lowercase letters, and numbers;
- Type C: pure digits, plural characters, and the last digit is ignored if it is a singular digit; The interface adopts type B code by default. To use type A and C codes, you need to add“{A” and “{C” before the content, for example, “{A2344A”,”{C123123”,”{A1A{B13B{C12”.
| Param | Type |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| options
| { content: string; symbology: BarcodeSymbologyEnum; height: number; width: number; text_position: BarcodeTextPositionEnum; } |
printQRCode(...)
printQRCode(options: { content: string; size: number; error_correction?: number; }) => Promise<void>
Print a QR code.
data → QR barcode content modulesize → the size of QR barcode; unit: pixel; value from 4 to 16; errorlevel → barcode 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%)
Note: the printing content will be directly output after calling this method under normal printing status, and each barcode has 4 pixels (if the pixels are less than 4, the barcode scanning may fail). A maximum version19 (93*93) mode is supported.
| Param | Type |
| ------------- | -------------------------------------------------------------------------- |
| options
| { content: string; size: number; error_correction?: number; } |
print2DCode(...)
print2DCode(options: { content: string; symbology: Barcode2DSymbologyEnum; size: number; error_correction: number; }) => Promise<void>
Print a 2D barcode.
data → 2D barcode content symbology → 2D barcode type 1 Qr (same as printQRCode interface) 2 PDF417 3 DataMatrix modulesize → the size of effective 2D barcode; the supported optimum barcode size varies according to different barcode types. Qr barcode: 4 – 16 (the same as printQRCode interface) PDF417: 1 – 4 DataMatrix: 4 – 16 errorlevel → 2D barcode error correction level; the supported level varies according to different barcode types. Qr barcode: 0 – 3 (same as printQRCode interface) PDF417: 0 – 8 DataMatrix: ECC200 auto error correction is adopted by default, and it cannot be modified.
Note: the printing content will be directly output after calling this method under normal printing status; this interface is available for versions above v4.1.2.
| Param | Type |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| options
| { content: string; symbology: Barcode2DSymbologyEnum; size: number; error_correction: number; } |
enterPrinterBuffer(...)
enterPrinterBuffer(options?: { clean?: boolean | undefined; } | undefined) => Promise<void>
Enable transaction printing mode
clear → whether to clear the content in the buffer area
- true → clear the content unsubmitted in the last transaction printing
- false → not clear the content unsubmitted in the last transaction printing, which will be included in the next submission
Note:
- After enabling transaction printing mode, the printer won’t print the data immediately under this mode, until you submit transaction or disable submitting transaction;
- Transaction printing mode is available for all devices except for V1 model.
| Param | Type |
| ------------- | --------------------------------- |
| options
| { clean?: boolean; } |
exitPrinterBuffer(...)
exitPrinterBuffer(options?: { commit?: boolean | undefined; } | undefined) => Promise<void>
Disable transaction printing mode
commit → whether to print the content in the buffer area;
- true → the printer will print all the contents in the transaction queue;
- false → the printer will not print all the contents in the transaction queue, which will be saved for the next submission
Note: transaction printing mode is available for all devices except for V1 model.
| Param | Type |
| ------------- | ---------------------------------- |
| options
| { commit?: boolean; } |
exitPrinterBufferWithCallback(...)
exitPrinterBufferWithCallback(options?: { commit?: boolean | undefined; } | undefined) => Promise<void>
Disable transaction printing mode and call back result
commit → whether to print the content in the buffer area;
- true → the printer will print all the contents in the transaction queue;
- false → the printer will not print all the contents in the transaction queue, which will be saved for the next submission
Note: transaction printing mode is available for all devices except for V1 model.
| Param | Type |
| ------------- | ---------------------------------- |
| options
| { commit?: boolean; } |
commitPrinterBuffer()
commitPrinterBuffer() => Promise<void>
Submit transaction printing
Note:
- Submit all the contents in the transaction queue and print all. The printer remains in the transaction printing mode;
- Transaction printing mode is available for all devices except for V1 model.
commitPrinterBufferWithCallback()
commitPrinterBufferWithCallback() => Promise<void>
Submit transaction printing and call back result
Note: transaction printing mode is available for all devices except for V1 model.
lineWrap(...)
lineWrap(options?: { lines?: number | undefined; } | undefined) => Promise<void>
The printer moves the paper for n lines
Note: forced linefeed is adopted, and the printer will move the paper for n lines after completing the previous printing.
| Param | Type |
| ------------- | -------------------------------- |
| options
| { lines?: number; } |
cutPaper()
cutPaper() => Promise<void>
Paper cutting
Note: there’s some distance between printhead and cutter, which will be automatically complemented by calling the interface.
Note: Only available for desktop terminals with cutter function.
getCutPaperTimes()
getCutPaperTimes() => Promise<{ times: number; }>
Get the cutter’s cumulative cutting times
Note: Only available for desktop terminals with cutter function.
Returns: Promise<{ times: number; }>
openDrawer()
openDrawer() => Promise<void>
Open the cash drawer
Note: Only available for desktop terminals with cash drawer function.
getOpenDrawerTimes()
getOpenDrawerTimes() => Promise<{ times: number; }>
Get the cumulative open times of the cash drawer
Note: Only available for desktop terminals with cash drawer function.
Returns: Promise<{ times: number; }>
getDrawerStatus()
getDrawerStatus() => Promise<{ opened: boolean; }>
Get the current status of the cash drawer
Note 1: you can get the cash drawer status of some models with cash drawer function by calling this interface.
Note 2: this interface is only available for device models of S2, T2, and T2mini with versions above v4.0.0.
Returns: Promise<{ opened: boolean; }>
getForcedDouble()
getForcedDouble() => Promise<{ status: number; }>
Get global font height and width status
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ status: number; }>
isForcedAntiWhite()
isForcedAntiWhite() => Promise<{ status: boolean; }>
Get global font anti-white style enabled
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ status: boolean; }>
isForcedBold()
isForcedBold() => Promise<{ status: boolean; }>
Get global font bold style enabled
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ status: boolean; }>
isForcedUnderline()
isForcedUnderline() => Promise<{ status: boolean; }>
Get global font underline style enabled
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ status: boolean; }>
getForcedRowHeight()
getForcedRowHeight() => Promise<{ height: number; }>
Get global line height set value
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ height: number; }>
getFontName()
getFontName() => Promise<{ font: number; }>
Get current font used
Note: currently, these interfaces, except ‘get print density’ interface, are only available for handheld terminals of models V1, V1s, and P1 with versions above v3.2.0, and model P14g with versions above v1.2.0.
Returns: Promise<{ font: number; }>
getPrinterDensity()
getPrinterDensity() => Promise<{ density: number; }>
Get print density
Returns: Promise<{ density: number; }>
sendLCDCommand(...)
sendLCDCommand(options: { command: LcdCommandEnum; }) => Promise<void>
Send control commands
parameter: flag → 1. Initialization; 2. Wake up LCD; 3. LCD hibernation; 4. Clear screen
Note: only available for desktop terminals of mini series with customer display function.
| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| options
| { command: LcdCommandEnum; } |
sendLCDInitializationCommand()
sendLCDInitializationCommand() => Promise<void>
Send initialization command
sendLCDWakeUpCommand()
sendLCDWakeUpCommand() => Promise<void>
Send wake up command
sendLCDHibernateCommand()
sendLCDHibernateCommand() => Promise<void>
Send hibernation command
sendLCDClearCommand()
sendLCDClearCommand() => Promise<void>
Send clear command
sendLCDString(...)
sendLCDString(options: { text: string; }) => Promise<void>
Send single line text
string → the text to be displayed
Note: only available for desktop terminals of mini series with customer display function, and it won’t be displayed if the text is too long.
| Param | Type |
| ------------- | ------------------------------ |
| options
| { text: string; } |
sendLCDDoubleString(...)
sendLCDDoubleString(options: { top: string; bottom: string; }) => Promise<void>
Send double lines text
topText → display the top text bottomText → display the bottom text
Note: only available for desktop terminals of mini series with customer display function, and it won’t be displayed if the text is too long.
| Param | Type |
| ------------- | --------------------------------------------- |
| options
| { top: string; bottom: string; } |
sendLCDMultiString(...)
sendLCDMultiString(options: { lines: { text: string; proportion: number; }[]; }) => Promise<void>
Send multiple lines text, and each line’s content will be automatically sized based on its weight
text → arrays displaying the text of each line. You need to confirm the line number according to array element. If a line is empty, no text will be displayed align → The weight ratio of the area occupied by each line of text, and the size of array elements must be the same size as the text array
Note: only available for desktop terminals of mini series with customer display function, with versions above v4.0.0. It won’t be displayed if the text is too long.
| Param | Type |
| ------------- | ---------------------------------------------------------------- |
| options
| { lines: { text: string; proportion: number; }[]; } |
sendLCDFillString(...)
sendLCDFillString(options: { text: string; size: number; fill: boolean; }) => Promise<void>
Send single line text (font size and filling method can be customized for the text)
string → text to be displayed size → the font size of the text to be displayed, center by default fill → whether to magnify the font to fill the display area
Note: only available for desktop terminals of mini series with customer display function, with versions above v4.0.0. It won’t be displayed if the text is too long.
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options
| { text: string; size: number; fill: boolean; } |
sendLCDBase64Bitmap(...)
sendLCDBase64Bitmap(options: { bitmap: string; }) => Promise<void>
Send bitmap image
bitmap → the image to be displayed
Note: only available for desktop terminals of mini series with customer display function, and the customer display can only display the image with the maximum pixel of 128*40.
| Param | Type |
| ------------- | -------------------------------- |
| options
| { bitmap: string; } |
sendLCDAsciiBitmap(...)
sendLCDAsciiBitmap(options: { bitmap: string; }) => Promise<void>
Send ascii bitmap image
| Param | Type |
| ------------- | -------------------------------- |
| options
| { bitmap: string; } |
sendLCDBarcode(...)
sendLCDBarcode(options: { content: string; format?: LcdBarcodeFormatEnum; }) => Promise<void>
Prints barcode on the customer display
| Param | Type |
| ------------- | ---------------------------------------------------------------------------------------------------- |
| options
| { content: string; format?: LcdBarcodeFormatEnum; } |
labelLocate()
labelLocate() => Promise<void>
Locate the next label
You can only implement the location output operation specific to the label by calling the label interfaces, while the label content needs to be customized by yourself according to your own needs, like the operation of thermal printing.
Please note that the height of printing content shall be within the label paper, or the printing content may exceed the label paper, which can result in printing to the next label or inaccurate location of the next label.
If you use a label paper with 30mm height, you can print the content with 240 pixels (30mm x 8 pixels), and the printer defaults to 32 pixels of line spacing, which allows you to print about 8 lines of text or a 384x240 image.
After printing the content, you can choose to implement labelLocate and print the content circularly according to your own needs.
If you don’t need to print any more, you can implement labelOutput(), which can output the label to the paper cutting position, facilitating you to add other APIs according to needs to design your own label content.
Note: You need to locate the label position every time before sending the printing content
labelOutput()
labelOutput() => Promise<void>
Output the label to the paper cutting position
addListener('onPrinterStatusUpdated', ...)
addListener(eventName: 'onPrinterStatusUpdated', listenerFunc: (event: { status: PrinterStatusEventEnum; broadcast?: string; }) => void) => Promise<PluginListenerHandle>
Listens for printer status changed events.
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| eventName
| 'onPrinterStatusUpdated' |
| listenerFunc
| (event: { status: PrinterStatusEventEnum; broadcast?: string; }) => void |
Returns: Promise<PluginListenerHandle>
removeAllListeners()
removeAllListeners() => Promise<void>
Removes all listeners
Interfaces
PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |
Enums
ServiceStatusEnum
| Members | Value |
| ------------------- | --------------------------- |
| NO_PRINTER
| "NoPrinter" |
| CHECK_PRINTER
| "CheckPrinter" |
| FOUND_PRINTER
| "FoundPrinter" |
| LOST_PRINTER
| "LostPrinter" |
PrinterStatusEnum
| Members | Value |
| ----------------------------- | ------------------------------------ |
| NORMAL_OPERATION
| 'NormalOperation' |
| UNDER_PREPARATION
| 'UnderPreparation' |
| ABNORMAL_COMMUNICATION
| 'AbnormalCommunication' |
| OUT_OF_PAPER
| 'OutOfPaper' |
| OVERHEATED
| 'Overheated' |
| COVER_IS_OPEN
| 'CoverIsOpen' |
| CUTTER_ERROR
| 'CutterError' |
| CUTTER_RECOVERED
| 'CutterRecovered' |
| BLACK_MARK_NOT_DETECTED
| 'BlackMarkNotDetected' |
| PRINTER_NOT_DETECTED
| 'PrinterNotDetected' |
| FIRMWARE_UPDATE_FAILED
| 'FirmwareUpdateFailed' |
| UNKNOWN
| 'Unknown' |
PrinterStyleKeysEnum
| Members | Value |
| ----------------------------- | ------------------------------------ |
| ENABLE_DOUBLE_WIDTH
| "EnableDoubleWidth" |
| ENABLE_DOUBLE_HEIGHT
| "EnableDoubleHeight" |
| ENABLE_BOLD
| "EnableBold" |
| ENABLE_UNDERLINE
| "EnableUnderline" |
| ENABLE_ANTI_WHITE
| "EnableAntiWhite" |
| ENABLE_STRIKETHROUGH
| "EnableStrikethrough" |
| ENABLE_ITALIC
| "EnableItalic" |
| ENABLE_INVERT
| "EnableInvert" |
| SET_TEXT_RIGHT_SPACING
| "SetTextRightSpacing" |
| SET_RELATIVE_POSITION
| "SetRelativePosition" |
| SET_ABSOLUTE_POSITION
| "SetAbsolutePosition" |
| SET_LINE_SPACING
| "SetLineSpacing" |
| SET_LEFT_SPACING
| "SetLeftSpacing" |
| SET_STRIKETHROUGH_STYLE
| "SetStrikethroughStyle" |
PrinterStyleValuesEnum
| Members | Value |
| ------------- | ---------------------- |
| ENABLE
| "Enable" |
| DISABLE
| "Disable" |
PrinterModeEnum
| Members | Value |
| ---------------- | ------------------------ |
| GENERAL
| "General" |
| BLACK_MARK
| "BlackMark" |
| LABEL
| "Label" |
| UNKNOWN
| "Unknown" |
AlignmentModeEnum
| Members | Value |
| ------------ | --------------------- |
| LEFT
| "left" |
| CENTER
| "center" |
| RIGHT
| "right" |
BitmapPrintTypeEnum
| Members | Value |
| --------------------- | ---------------------------- |
| DEFAULT
| "Default" |
| BLACK_AND_WHITE
| "blackAndWhite" |
| GRAYSCALE
| "Grayscale" |
BarcodeSymbologyEnum
| Members | Value |
| -------------- | ----------------------- |
| UPC_A
| "UPC_A" |
| UPC_E
| "UPC_E" |
| EAN_13
| "EAN_13" |
| EAN_8
| "EAN_8" |
| CODE_39
| "CODE_39" |
| ITF
| "ITF" |
| CODABAR
| "CODABAR" |
| CODE_93
| "CODE_93" |
| CODE_128
| "CODE_128" |
BarcodeTextPositionEnum
| Members | Value |
| --------------------- | ---------------------------- |
| NO_TEXT
| "NoText" |
| ABOVE
| "Above" |
| BELOW
| "Below" |
| ABOVE_AND_BELOW
| "AboveAndBelow" |
Barcode2DSymbologyEnum
| Members | Value |
| ---------------- | -------------------------- |
| QR_CODE
| "QR_CODE" |
| PDF417
| "PDF417" |
| DataMatrix
| "DATA_MATRIX" |
LcdCommandEnum
| Members | Value |
| -------------------- | ----------------------------- |
| INITIALIZATION
| "Initialization" |
| WAKE_UP
| "WakeUp" |
| HIBERNATE
| "Hibernate" |
| CLEAR
| "Clear" |
LcdBarcodeFormatEnum
| Members | Value |
| -------------- | ----------------------- |
| UPC_A
| "UPC_A" |
| UPC_E
| "UPC_E" |
| EAN_13
| "EAN_13" |
| EAN_8
| "EAN_8" |
| CODE_39
| "CODE_39" |
| ITF
| "ITF" |
| CODABAR
| "CODABAR" |
| CODE_93
| "CODE_93" |
| CODE_128
| "CODE_128" |
| QR_CODE
| "QR_CODE" |
PrinterStatusEventEnum
| Members | Value | Description |
| ----------------------------- | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| UNDER_PREPARATION
| "UnderPreparation" | Printer is under preparation. see woyou.aidlservice.jiuv5.INIT_ACTION
in documentation. |
| NORMAL_OPERATION
| "NormalOperation" | Printing is ready. see woyou.aidlservice.jiuv5.NORMAL_ACTION
in documentation. |
| PRINTING_ERROR
| "PrintingError" | Printing error. see woyou.aidlservice.jiuv5.ERROR_ACTION
in documentation. |
| OUT_OF_PAPER
| "OutOfPaper" | Out of paper. see woyou.aidlservice.jiuv5.OUT_OF_PAPER_ACTION
in documentation. |
| OVERHEATED
| "Overheated" | Printhead is overheated. see woyou.aidlservice.jiuv5.OVER_HEATING_ACITON
in documentation. |
| NORMAL_HEAT
| "NormalHeat" | Printhead temperature back to normal. see woyou.aidlservice.jiuv5.NORMAL_HEATING_ACITON
in documentation. |
| COVER_IS_OPEN
| "CoverIsOpen" | Cover open. see woyou.aidlservice.jiuv5.COVER_OPEN_ACTION
in documentation. |
| COVER_ERROR
| "CoverError" | Cover closing exception. see woyou.aidlservice.jiuv5.COVER_ERROR_ACTION
in documentation. |
| CUTTER_ERROR
| "CutterError" | Cutter exception 1 – cutter stuck. see woyou.aidlservice.jiuv5.KNIFE_ERROR_ACTION_1
in documentation. |
| CUTTER_RECOVERED
| "CutterRecovered" | Cutter exception 2 – cutter back to normal. see woyou.aidlservice.jiuv5.KNIFE_ERROR_ACTION_2
in documentation. |
| FIRMWARE_UPDATING
| "FirmwareUpdating" | Printer firmware updating. see woyou.aidlservice.jiuv5.FIRMWARE_UPDATING_ACITON
in documentation. |
| FIRMWARE_UPDATE_FAILED
| "FirmwareUpdateFailed" | Printer firmware updating failed. see woyou.aidlservice.jiuv5.FIRMWARE_FAILURE_ACITON
in documentation. |
| PRINTER_NOT_DETECTED
| "PrinterNotDetected" | Printer not detected. see woyou.aidlservice.jiuv5.PRINTER_NON_EXISTENT_ACITON
in documentation. |
| BLACK_MARK_NOT_DETECTED
| "BlackMarkNotDetected" | Black mark not detected. see woyou.aidlservice.jiuv5.BLACKLABEL_NON_EXISTENT_ACITON
in documentation. |