搜索设备
已经连接的设备无法被搜索到。如目标蓝牙已被其他设备连接、目标蓝牙已经通过手机系统的蓝牙连接(而非APP内调用API连接)。
import { MEngineerKit } from "@yl/super-jssdk"
MEngineerKit.searchDevice(optional)
| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
| optional | Object | 否 | 选填参数 |
optional
| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
| scanPeriod | number | 否 | 蓝牙扫描时间,单位ms,默认10000 |
| onStart | function | 否 | 搜索开始回调 |
| onNewDevice(deviceInfo) | function | 否 | 搜索到设备回调, deviceInfo:设备信息,例:{"name" : "T7","address":"设备地址"} |
| 参数 | 类型 | 作用 |
|---|---|---|
| resolve(array) | Function | 成功回调,array为搜索到的设备列表,例:[{"name" : "T7","address":"设备地址"},...] |
| reject(err) | Function | 失败回调,err为详细错误信息,是一个json对象,例如:{"errCode":-1,"errMsg":"出错啦"} |
MEngineerKit.searchDevice()
.then((res) => {
console.log(res);
})
.catch(err => {
console.log('插件调用失败:', err)
})