更新记录

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

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

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

UNIPHIZ-API-Port 设备端口通信插件


平台兼容性

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-Port Specification

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

UNIPHIZ-API-Port provides users with functions such as port sending, listening, and setting, 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. Call the function of the instance.

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 port = uni.requireNativePlugin("UNIPHIZ-API-Port-PortManager")

Usage

1. init()

Initialize PortManager

Returns:

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

2. getDataLengthOfPortsBuffer(channel: number)

Get the data length in the specified serial port's buffer

Parameters:

  • channel: logical number of the communication port.(only supports 0, 10, 11, 30)

Returns:

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

3. closePortByChannel(channel: number)

Close a specific communication port

Parameters:

  • channel: An integer representing the channel number of the communication port. The possible values are:
    • 0: COM1
    • 1: COM2 (Normally for system internal use, SP30 does not have such a port)
    • 2: MDL (Normally for system internal use, SP30 does not have such a port. Application can not use this function to operate this port directly, but call the specific wireless module functions)
    • 3: PINPAD (SP30 does not have such a port)
    • 4: MODEM (Normally for system internal use)
    • 5: Wi-Fi (Normally for system internal use, SP30 does not have such a port)
    • 10: USB (Convert USB to Serial Port)
    • 11: USBDEV (USB device mode port)
    • 19: Used for communication between Android application layer on E series and SK series devices, and the Q20 application
    • 30: USB (Convert USB to Serial Port)

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An object containing any additional data related to the result. In this case, it is not used, so it can be null.

4. getAvailablePorts()

List all available port numbers.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An array containing the list of available port numbers.

5. openPort(channel: number, attr: string)

The openPort method is used to open the specified communication port and set the communication parameters.

Parameters:

  • channel: An integer representing the channel number of the communication port. The possible values are:
    • 0: COM1
    • 1: COM2 (Normally for system internal use, SP30 does not have such a port)
    • 2: MDL (Normally for system internal use, SP30 does not have such a port. Application can not use this function to operate this port directly, but call the specific wireless module functions)
    • 3: PINPAD (SP30 does not have such a port)
    • 4: MODEM (Normally for system internal use)
    • 5: Wi-Fi (Normally for system internal use, SP30 does not have such a port)
    • 10: USB (Convert USB to Serial Port)
    • 11: USBDEV (USB device mode port)
    • 19: Used for communication between Android application layer on E series and SK series devices, and the Q20 application
    • 30: USB (Convert USB to Serial Port)
    • 50: USBDEV (USB device mode port, can only be used when the authorization function is disabled)
  • attr: A string representing the communication speed and format. The format is "baud rate,data bits,parity,stop bits". For example, "9600,8,n,1" represents: baud rate is 9600bps, 8 data bits, no parity, 1 stop bit. Separated by "," in the string.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An object containing any additional data related to the result. In this case, it is not used, so it can be null.

6. peepPort(channel: number, bufferLength: number)

The peepPort method is used to listen for data from the communication port.

Parameters:

  • channel: An integer representing the channel number of the communication port. In this case, only serial ports are supported.
  • bufferLength: An integer representing the length of the application buffer.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: A string containing the buffer used for storing communication data, encoded in Base64.

7. setMaxDataLength(channel: number, dataLength: number, timeOutInt: number)

The setMaxDataLength method is used to set the maximum expected data length to be received within a given time limit.

Parameters:

  • channel: An integer representing the communication port number.
  • dataLength: An integer representing the expected number of data bytes to receive.
  • timeOutInt: An integer representing the receive timeout duration in milliseconds. A value of 0 indicates that the method should immediately exit regardless of whether data is received or not, and return the number of received bytes.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: A string containing the actual number of received bytes, encoded in Base64. The length of the received data will not exceed the expected length.

8. resetPortByChannel(channel: number)

The resetPortByChannel method is used to reset the communication port and clear all data received in the serial buffer.

Parameters:

  • channel: An integer representing the channel number of the communication port. The possible values are:
    • 0: COM1
    • 1: COM2 (Normally for system internal use, SP30 does not have such a port)
    • 2: MDL (Normally for system internal use, SP30 does not have such a port. Application can not use this functional to operate this port directly, but call the specific wireless module functions)
    • 3: PINPAD (SP30 does not have such a port)
    • 4: MODEM (Normally for system internal use)
    • 5: Wi-Fi (Normally for system internal use, SP30 does not have such a port)
    • 10: USB (Convert USB to Serial Port)
    • 11: USBDEV (USB device mode port)
    • 19: Used for communication between Android application layer on E series and SK series devices, and the Q20 application
    • 30: USB (Convert USB to Serial Port)

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An object containing any additional data related to the result. In this case, it is not used, so it can be null.

9. sendDataByChannel(channel: number, str: string)

The sendDataByChannel method is used to send a certain number of bytes of data through a specified communication port.

Parameters:

  • channel: An integer representing the channel number of the communication port. The possible values are:
    • 0: COM1
    • 1: COM2 (Normally for system internal use, SP30 does not have such a port)
    • 2: MDL (Normally for system internal use, SP30 does not have such a port. Application can not use this functional to operate this port directly, but call the specific wireless module functions)
    • 3: PINPAD (SP30 does not have such a port)
    • 4: MODEM (Normally for system internal use)
    • 5: Wi-Fi (Normally for system internal use, SP30 does not have such a port)
    • 10: USB (Convert USB to Serial Port)
    • 11: USBDEV (USB device mode port)
    • 19: Used for communication between Android application layer on E series and SK series devices, and the Q20 application
    • 30: USB (Convert USB to Serial Port)
  • str: A string representing the data encoded in Base64 to be sent. The length of the data cannot exceed 8K.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An object containing any additional data related to the result. In this case, it is not used, so it can be null.

10. checkSendBufferByChannel(channel: number)

The checkSendBufferByChannel method is used to check whether the send buffer of the specified communication port is empty or contains no pending data for transmission.

Parameters:

  • channel: An integer representing the channel number of the communication port. The possible values are:
    • 0: COM1
    • 1: COM2 (Normally for system internal use, SP30 does not have such a port)
    • 2: MDL (Normally for system internal use, SP30 does not have such a port. Application can not use this functional to operate this port directly, but call the specific wireless module functions)
    • 3: PINPAD (SP30 does not have such a port)
    • 4: MODEM (Normally for system internal use)
    • 5: Wi-Fi (Normally for system internal use, SP30 does not have such a port)
    • 10: USB (Convert USB to Serial Port)
    • 11: USBDEV (USB device mode port)
    • 19: Used for communication between Android application layer on E series and SK series devices, and the Q20 application
    • 30: USB (Convert USB to Serial Port)

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An integer representing the status of the send buffer. A value of 0 indicates that the send buffer is empty.

11. switchUSBInterface(isSwitchToSP: boolean)

The switchUSBInterface method is used to switch the USB interface to a specific port.

Parameters:

  • isSwitchToSP: A boolean value indicating whether to switch to SP (true) or AP (false). This parameter is only supported on A920 devices.

Returns:

  • A JSON object containing the result of the operation. The object has the following properties:
    • code: An integer representing the code of the result. A value of 0 indicates success, while any other value indicates an error.
    • message: A string providing a message describing the result.
    • data: An object containing any additional data related to the result. In this case, it is not used, so it can be null.

12. destroy()

Close the RPC and release the PortManager

Returns:

  • None

隐私、权限声明

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

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

插件不采集任何数据

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

许可协议

作者未提供license.md

暂无用户评论。

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