更新记录

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

1. Reference Mode

const port = uni.requireNativePlugin('UNIPHIZ-API-Port-PortManager')

2. Interface Catalog

// Get instance

init()

// Release resource

destroy()

// Check whether the send buffer of the specified communication port is empty or contains no pending data for transmission.

checkSendBufferByChannel(channel)

// Close a specific communication port

closePortByChannel(channel)

// List all available port numbers

getAvailablePorts()

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

getDataLengthOfPortsBuffer(channel)

// Open the specified communication port and set communication parameters

openPort(channel, attr)

// Listening for data from the communication port

peepPort(channel, bufferLength)

// Reset the communication port and clear all data received in the serial buffer

resetPortByChannel(channel)

// Send a certain number of bytes of data through a specified communication port

sendDataByChannel(channel, str)

// The maximum expected data length to be received within a given time limit

setMaxDataLength(channel, dataLength)

// Switch the USB interface to a port.

switchUSBInterface(isSwitchToSP)

3. Interface Specification

init()

Function Description

Function Type Description
function get instance

Example

port.init()

destroy()

Function Description

Function Type Description
function release resource

Example

port.destroy()

checkSendBufferByChannel(channel)

Function Description

Function Type Description
json result of checking buffer
Parameter Type Description
channel number channel of port

Example

const result = port.checkSendBufferByChannel(0)

closePortByChannel(channel)

Function Description

Function Type Description
json result of execution
Parameter Type Description
channel number channel of port

Example

const result = port.closePortByChannel(0)

getAvailablePorts()

Function Description

Function Type Description
json list of ports number

Example

const numList = port.getAvailablePorts()

getDataLengthOfPortsBuffer(channel)

Function Description

Function Type Description
json length of port's buffer
Parameter Type Description
channel number channel of port

Example

const length = port.getDataLengthOfPortsBuffer(0)

openPort(channel, attr)

Function Description

Function Type Description
json result of execution
Parameter Type Description
channel number channel of port
attr string communication speed and format

Example

const result = port.openPort(0, "9600,8,n,1")

peepPort(channel, bufferLength)

Function Description

Function Type Description
json data listened from the communication port
Parameter Type Description
channel number channel of port
bufferLength number length of the application buffer

Example

const data = port.peepPort(0, 512)

resetPortByChannel(channel)

Function Description

Function Type Description
json result of execution
Parameter Type Description
channel number channel of port

Example

const result = port.resetPortByChannel(0)

sendDataByChannel(channel, str)

Function Description

Function Type Description
json result of execution
Parameter Type Description
channel number channel of port
str string bytes to send encoded in base64

Example

const result = port.sendDataByChannel(0, "Data to send encoded in base64...")

setMaxDataLength(channel, dataLength)

Function Description

Function Type Description
json result of execution
Parameter Type Description
channel number channel of port
dataLength number the max data length expected to be received

Example

const result = port.setMaxDataLength(0,512)

switchUSBInterface(isSwitchToSP)

Function Description

Function Type Description
json result of execution
Parameter Type Description
isSwitchToSP boolean whether switch the USB interface

Example

const result = port.switchUSBInterface(false)

隐私、权限声明

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

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

插件不采集任何数据

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

许可协议

作者未提供license.md

暂无用户评论。

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