更新记录
1.0.0(2024-08-18)
初始化发布
平台兼容性
uni-app
Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
---|---|---|---|---|---|---|---|---|
√ | √ | - | - | - | - | 4.4 | × | - |
微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 快应用-华为 | 快应用-联盟 |
---|---|---|---|---|---|---|---|---|---|---|
× | × | × | × | × | × | - | × | × | × | × |
uni-app x
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
- | - | 5.0 | × | - | × |
概述
XF-serialPort封装了安卓串口通信的能力,支持多串口操作
插件接口
getAllDevices
获取所有串口信息
uni-app项目中(nvue)调用示例:
import { getAllDevices } from "@/uni_modules/XF-serialPort"
let res = getAllDevices(0);
console.log(res)
uni-app x项目(uvue)中调用示例:
import { getAllDevices } from "@/uni_modules/XF-serialPort";
let res = getAllDevices(0);
console.log(res)
可用性
Android系统
可提供的1.0.0及更高版本
getAllDeicesPath
查询串口设备地址列表
uni-app项目中(nvue)调用示例:
import { getAllDeicesPath } from "@/uni_modules/XF-serialPort"
let res = getAllDeicesPath(0);
console.log(res)
uni-app x项目(uvue)中调用示例:
import { getAllDeicesPath } from "@/uni_modules/XF-serialPort";
let res = getAllDeicesPath(0);
console.log(res)
可用性
Android系统
可提供的1.0.0及更高版本
addEventListener
串口接收数据监听
uni-app项目中(nvue)调用示例:
import { addEventListener } from "@/uni_modules/XF-serialPort"
addEventListener({
index: 0,
revType: 'text',
complete: (res) => {
console.log(res)
}
});
uni-app x项目(uvue)中调用示例:
import { addEventListener } from "@/uni_modules/XF-serialPort";
import { EventListenerOptions } from "@/uni_modules/XF-serialPort/utssdk/interface.uts";
let options = {
index: 0,
revType: 'text',
complete: (res : any) => {
console.log(res)
}
} as EventListenerOptions;
addEventListener(options);
可用性
Android系统
可提供的1.0.0及更高版本
open
打开串口
uni-app项目中(nvue)调用示例:
import { open } from "@/uni_modules/XF-serialPort"
open({
index: 0,
port: '/dev/ttyS2',
baudRate: 115200,
stopBits: 2,
dataBits: 8,
parity: 0,
flowCon: 0,
complete: (res) => {
console.log(res)
}
});
uni-app x项目(uvue)中调用示例:
import { open } from "@/uni_modules/XF-serialPort";
import { OpenOptions } from "@/uni_modules/XF-serialPort/utssdk/interface.uts";
let options = {
index: 0,
port: '/dev/ttyS2',
baudRate: 115200,
stopBits: 2,
dataBits: 8,
parity: 0,
flowCon: 0,
complete: (res : any) => {
console.log(res)
}
} as OpenOptions;
open(options);
可用性
Android系统
可提供的1.0.0及更高版本
send
发送数据
uni-app项目中(nvue)调用示例:
import { send } from "@/uni_modules/XF-serialPort"
send(0,'12344',text);
uni-app x项目(uvue)中调用示例:
import { send } from "@/uni_modules/XF-serialPort";
send(0,'12344',text);
可用性
Android系统
可提供的1.0.0及更高版本
close
关闭串口
uni-app项目中(nvue)调用示例:
import { close } from "@/uni_modules/XF-serialPort"
close(0);
uni-app x项目(uvue)中调用示例:
import { close } from "@/uni_modules/XF-serialPort";
close(0);
可用性
Android系统
可提供的1.0.0及更高版本