连接设备
若蓝牙正处于搜索设备状态,此时禁止连接设备。
import { MEngineerKit } from "@yl/super-jssdk"
MEngineerKit.connectDevice(optional)
| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
| optional | Object | 是 | 必填参数 |
optional
| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
| device | object | 是 | 要连接的设备 |
| onReceiveData(data, options) | function | 否 | 数据接收回调 |
| onDisconnect(options) | function | 否 | 与设备蓝牙的连接中断(如信号干扰,距离问题等)时回调,断开后会自动重连 |
| onClose(options) | function | 否 | 闭指定蓝牙连接的回调,关闭后,两台设备间的蓝牙,不再有断开重连功能 |
device参数说明
| 参数 | 类型 | 必填 | 作用 |
|---|---|---|---|
| name | string | 是 | 设备名称 |
| timeout | number | 否 | 连接设备超时时间,单位ms,默认10000,连接发起时有效,传0表示持续搜索 |
| 参数 | 类型 | 作用 |
|---|---|---|
| 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)
})