更新记录

v1.0.1(2024-09-19) 下载此版本

  • 插件兼容性升级 根据平台要求,插件更新到Android 14 (API 34)版本,现已支持HBuidlerX 4.26-alpha平台云端打包。

v1.0.0(2024-07-05) 下载此版本

UNIPHIZ系统打印机设备控制插件


平台兼容性

Android Android CPU类型 iOS
适用版本区间:5.0 - 14.0 armeabi-v7a:支持,arm64-v8a:支持,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


UNIPHIZ-API-Printer Specification

To use this plugin, you also need to install the UNIPHIZ-API-Common plugin, otherwise some functions may not work properly.

UNIPHIZ-API-Printer provides users with functions such as printer management, status query, font indent setting, text picture printing, etc.

Environment

CompileSdkVersion 34

MinSdkVersion 21

TargetSdkVersion 34

Build Gradle JDK Version JDK-21.0.2

Source Compatibility JDK-1.8

Gradle Version gradle-8.7-bin

Android Gradle Plugin Version

Getting started

Open the sample project using HBuilderX 4.26-alpha.

How to use the plugins

  1. Recognize the name of the plugin's module.

Open the file pathed in ./nativeplugins/<plugin_name>/package.json, the plugin is described by the value of _dp_nativeplugin -> android -> plugins.

  1. Get instance of the plugin's module in the page files.

Use uni.requireNativePlugin(<module_name>) to get instance of the module.

  1. Add permissions

Add permission com.pax.permission.PRINTER in the manifest.json field app-plus -> distribute -> android -> permissions of the file.

  1. Call the function of module.

Project structure

  1. /nativeplugins

The folder named nativeplugins contains native plugins and their specification files. Each native plugin has one folder.

  1. /pages

The folder named pages contains page files in vue format.

  1. /unpackage

The folder named unpackage contains files generated by HBuilderX.

  1. manifest.json

The file named manifest.json contains the application configuration.

Custom Plugins

  1. Plugin description

Create folder ./nativeplugins/<plugin_name>/android in the root path firstly, and move the plugin file in AAR format to ./nativeplugins/<plugin_name>/android.

Then create the description file ./nativeplugins/<plugin_name>/package.json in the project root path, and fill in the content according to the sample project.

  1. Select local plugins

Each value of the key named of _dp_nativeplugin -> android -> plugins -> name must start with <plugin_name> firstly, then make sure value of the key named of version corresponds to the file in AAR format.

If the files in the nativeplugins directory are configured correctly, they will be listed in the app-plus -> nativePlugins section of the manifest.json file.

Finally open the manifest.json file in the project root path, and check the native plugins -> local plugins.

  1. Genarate Custom Playground

Modify versionCode to make it larger than the current value, change versionName to make it matches versionCode, and make sure to modify versionCode and versionName before each packaging.

Then click Run -> Mobile App Playground -> Generate Custom Playground, choose Customize playground native runner -> Standard Mode(upload code and certificate, DCloud promises not to keep).

Wait for packaging to complete.

  1. Run the program

Use USB cable to connect your device, then click Run -> Mobile App Playground -> Android Run.

Choose the connected device and then click Operating with custom playground -> run.

Interface Specification

Import

const printer = uni.requireNativePlugin("UNIPHIZ-API-Printer-PrintManager")

Usage

1. init()

Initializes the PrintManager instance.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

2. initByContext()

Initializes the PrintManager instance using the provided Context.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

3. enumFontsSupported(maxFontNum: number)

Enumerates the fonts supported by the current device.

Parameters:

  • maxFontNum (number) - The maximum number of fonts that the Fonts buffer can hold. Not exceeding 64.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - fonts list

4. getPrintMode()

Gets the printing mode.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data :
    • 0 - Normal thermal paper (continuous paper) printing mode
    • 1 - Label thermal paper (gap/black mark paper) printing mode (supported by M9200)
    • 2 - Eco-friendly paper printing mode

5. setReversePrint(reverse: number)

Sets reverse printing.

Parameters:

  • reverse (number) - 0 - Normal printing, 1 - Reverse printing

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

6. printImageByPath(pathString: string)

Prints an image by the file's path.

Parameters:

  • pathString (string) - The path of the image's file. Bitmap to be printed. Size limit: Maximum width of 384 pixels, no height limit. If the bitmap width exceeds the printer's limit, the right side of the image will be cropped.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

7. printImageByData(imageData: string)

Prints an image by the file's data encoded in Base64.

Parameters:

  • imageData (string) - The bytes encoded in Base64 of the image's file. Bitmap to be printed. Size limit: Maximum width of 384 pixels, no height limit. If the bitmap width exceeds the printer's limit, the right side of the image will be cropped.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

8. printImageByPathAtGrayThreshold(pathString: string, grayThreshold: number)

Prints an image by the file's path with a specified gray threshold.

Parameters:

  • pathString (string) - The path of the image's file. Bitmap to be printed. Size limit: Maximum width of 384 pixels, no height limit. If the bitmap width exceeds the printer's limit, the right side of the image will be cropped.
  • grayThreshold (number) - Gray threshold for printing. The value should be within the range of 1 to 4, inclusive.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

9. printImageByDataAtGrayThreshold(imageData: string, grayThreshold: number)

Prints an image by the file's data encoded in Base64 with a specified gray threshold.

Parameters:

  • imageData (string) - The bytes encoded in Base64 of the image's file. Bitmap to be printed. Size limit: Maximum width of 384 pixels, no height limit. If the bitmap width exceeds the printer's limit, the right side of the image will be cropped.
  • grayThreshold (number) - Gray threshold for printing. The value should be within the range of 1 to 4, inclusive.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

10. cutPaper(mode: number)

Cuts a paper with a specified mode.

Parameters:

  • mode (number) - The mode of paper cutting. The value should be either 0 or 1.
    • 0 - Full paper cutting
    • 1 - Partial paper cutting

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - result of paper cutting:
    • 0 - success
    • 1 - failure

11. setDoubleHeight(redoubleHalfHeightChar: number, redoubleFullHeightChar: number)

Sets the printing font height, enabling double-height printing on the basic font.

Parameters:

  • redoubleHalfHeightChar (number) - Font height for half-width character font. The value should be either 1 (double-height) or 0 (normal height).
  • redoubleFullHeightChar (number) - Font height for full-width character font. The value should be either 1 (double-height) or 0 (normal height).

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

12. setDoubleWidth(redoubleHalfWidthChar: number, redoubleFullWidthChar: number)

Sets the printing font width, enabling double-width printing on the basic font.

Parameters:

  • redoubleHalfWidthChar (number) - Font width for half-width character font. The value should be either 1 (double-width) or 0 (normal width).
  • redoubleFullWidthChar (number) - Font width for full-width character font. The value should be either 1 (double-width) or 0 (normal width).

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

13. setFontSize(halfWidthCharCode: number, fullWidthCharCode: number)

Sets the font for printing.

Parameters:

  • halfWidthCharCode (number) - Font setting for half-width character code:
    • 0 - 8x16 font (normal)
    • 1 - 12x24 font (normal)
    • 2 - 8x16 font (vertically enlarged)
    • 3 - 8x16 font (horizontally enlarged)
    • 4 - 8x16 font (horizontally enlarged)
    • 5 - 12x24 font (horizontally enlarged)
    • 6 - 8x16 font (overall enlarged)
    • 7 - 12x24 font (overall enlarged)
    • Others - No change to the initial value
  • fullWidthCharCode (number) - Font setting for full-width character code:
    • 0 - 16x16 font (normal)
    • 1 - 24x24 font (normal)
    • 2 - 16x16 font (vertically enlarged)
    • 3 - 24x24 font (vertically enlarged)
    • 4 - 16x16 font (horizontally enlarged)
    • 5 - 24x24 font (horizontally enlarged)
    • 6 - 16x16 font (overall enlarged)
    • 7 - 24x24 font (overall enlarged)
    • Others - No change to the initial value (no changes will be made if any parameter is set incorrectly).

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - data of result

14. getCutMode()

Get the paper cutting modes supported by the machine.

Return:

  • JSON object of result
    • code - code of result
    • message - message of result
    • data - the mode supported:
    • 0 - Supports full cutting
    • 1 - Supports partial cutting
    • 2 - Supports both partial and full cutting
    • -1 - Does not support paper cutting

15. getDotLine()

Retrieves the current number of dot matrix lines printed.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (number) - The current number of dot matrix lines printed.

16. getFontDot(fontSize: number, str: string)

Reads the print matrix of the specified character.

Parameters:

  • fontSize (number) - The size of the font. 0 represents small font (8x16 or 16x16), and 1 represents large font (12x24 or 24x24).
  • str (string) - The specified character.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (string) - The read matrix information encoded in Base64.

17. getTemperature()

Retrieves the printer temperature.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (number) - The printer temperature.

18. setLeftIndent(indent: number)

Sets the left margin for character printing.

Parameters:

  • indent (number) - The left margin in blank pixels. The value should be between 0 and 300.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (any) - Return data. In this case, this property can be empty.

19. detectPaper()

Performs label gap paper learning.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (any) - Return data. In this case, this property can be empty.

20. setCutPaperMode(mode: number)

Sets the paper cutting mode to cut the paper immediately after printing.

Note: Please call this function before calling prnStart().

Parameters:

  • mode (number) - The paper cutting mode. The value should be one of the following:
    • -1 - No paper cutting.
    • 0 - Full paper cutting.
    • 1 - Partial paper cutting.

Return:

  • JSON object of result
    • code (number) - Result code. 0 indicates success, non-zero indicates failure.
    • message (string) - Result message.
    • data (any) - Return data. In this case, this property can be empty.

21. selectFont(singleFont: json, multiFont: json)

Selects the printer font.

Parameters:

  • singleFont (json) - Font attributes for half-width character font.

    • charSet (number) - Character set of singleFont.
    • width (number) - Width of singleFont.
    • height (number) - Height of singleFont.
    • bold (number) - Bold attribute of singleFont.
    • italic (number) - Italic attribute of singleFont.
  • multiFont (json) - Font attributes for full-width character font.

    • charSet (number) - Character set of multiFont.
    • width (number) - Width of multiFont.
    • height (number) - Height of multiFont.
    • bold (number) - Bold attribute of multiFont.
    • italic (number) - Italic attribute of multiFont.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

22. setFontName(name: string)

Sets the printer font name.

Parameters:

  • name (string) - Font name.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

23. setGrayscale(level: number)

Sets the printing grayscale level.

Parameters:

  • level (number) - Grayscale level.
    • 1 - Default grayscale.
    • 3 - Double-layer thermal printing.
    • 4 - Double-layer thermal printing higher darkness than 3.
    • 50~500 - Set darkness as a percentage of the default darkness.
    • Others - Reserved and invalid changes.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

24. setSpacing(charSpace: number, lineSpace: number)

Sets the printing character spacing and line spacing.

Parameters:

  • charSpace (number) - Character spacing in pixels.
  • lineSpace (number) - Line spacing in pixels.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

25. startPrint()

Opens the printer and prints the data from the buffer.

Note:

For proper usage, follow the formula: Dots per line = Character height + Line spacing Total dots = Dots per line * Number of lines [Total dots should be less than 3000, Default character height is 24]

This formula is used to calculate the total number of dots required for printing based on the character height, line spacing, and number of lines. The total dots should be less than 3000, and the default character height is 24.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

26. getPrintStatus()

Queries the current printing status.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (number) - Exception message or status.
    • 0 - Printing successful.
    • 1 - Printer is busy.
    • 2 - Printer is out of paper.
    • 3 - Data packet format error.
    • 4 - Printer malfunction.
    • 8 - Printer is overheated.
    • 9 - Low printer voltage.
    • 240 - Printing is incomplete.
    • 250 - Cutter error (supported by E500, E800).
    • 251 - Cover open error (supported by E500, E800).
    • 252 - Printer font library is not loaded.
    • 254 - Data packet is too long.

27. movePaper(pixel: number)

Moves the printer forward or backward by the specified number of pixels.

Note:

If the specified number of pixels is greater than Short.MAX_VALUE or less than Short.MIN_VALUE, the method returns an error result with the code ResultEnum.PARAMETER_OUT_OF_RANGE.

Parameters:

  • pixel (number) - Number of pixels.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

28. printStr(string: string, charset: string)

Prints a string using the specified character encoding.

Parameters:

  • string (string) - The string to be printed.
  • charset (string) - The character encoding of the string.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (object) - Data of result.

29. setLabelBoundary(height: number, width: number)

Sets the label paper size using the specified height and width in millimeters.

Parameters:

  • height (number) - Height of the label paper in millimeters.
  • width (number) - Width of the label paper in millimeters. The size cannot exceed the print paper size.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (boolean) - Indicates whether the paper size is set successfully.

30. setPrintMode(mode: number)

Sets the printing mode using the specified mode.

Parameters:

  • mode (number) - The printing mode.
    • 0 - Normal thermal paper (continuous paper) printing mode.
    • 1 - Label thermal paper (gap/black mark paper) printing mode (supported by M9200).
    • 2 - Eco-friendly paper printing mode.

Return:

  • JSON object of result
    • code (number) - Code of result.
    • message (string) - Message of result.
    • data (boolean) - Indicates whether the print mode is set successfully.

31. destroy()

Closes the printer and releases the PrintManager resources.

Return:

  • None

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

作者未提供license.md

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问