# 蓝牙
# Api域:
const native = kreator.native;
# native.isSupportBle()
是否支持蓝牙模块。
该方法为同步方法。
# 返回值:
boolean 是否支持。
const status = native.isSupportBle();
# native.isBlueEnable(options)
获取当前蓝牙模块开启状态。
参数名 | 类型 | 描述 |
---|---|---|
options | NativeApiBaseRequest | 入参类型 |
# 返回值
string 开启状态
native.isBlueEnable().then(res=>{
console.warn(res)
})
# native.enableBluetooth(options);
开启设备蓝牙模块。
参数名 | 类型 | 描述 |
---|---|---|
options | NativeApiBaseRequest | 入参类型 |
# 返回值
无
native.enableBluetooth().then(res=>{
// ....
})
# native.disableBluetooth(options)
关闭蓝牙模块。
参数名 | 类型 | 描述 |
---|---|---|
options | NativeApiBaseRequest | 入参类型 |
# 返回值
无
native.disableBluetooth().then(res=>{
// ....
})
# native.isConnected(options)
异步判断蓝牙是否连接指定设备。
参数名 | 类型 | 描述 |
---|---|---|
options | IsConnectedRequestInterface | 入参类型 |
# IsConnectedRequestInterface类型:
参数名 | 类型 | 描述 |
---|---|---|
mac | string | 设备mac地址 |
# 返回值
boolean 设备是否已连接
native.isConnected({
mac: ''
}).then(res=>{
// ....
})
# native.connect(options)
连接蓝牙设备。
参数名 | 类型 | 描述 |
---|---|---|
options | ConnectDataRequestInterface | 入参类型 |
# ConnectDataRequestInterface类型:
参数名 | 类型 | 描述 |
---|---|---|
mac | string | 设备MAC地址 |
BLEServerUUID | string | 设备网关UUID |
BLEReadDataUUID | string | 设备读数据端口UUID |
BLEWriteDataUUID | string | 设备写数据端口UUID |
# 返回值
string 是否连接完成
native.connect({
mac: '',
BLEServerUUID: '',
BLEReadDataUUID: '',
BLEWriteDataUUID: '',
}).then(res=>{
//
})
# native.disconnectAllDevice()
强制中断全部蓝牙设备的连接状态。
参数名 | 类型 | 描述 |
---|---|---|
options | NativeApiBaseRequest | 入参类型 |
# 返回值
无
native.disconnectAllDevice();
# native.sendCommandData()
传输蓝牙设备指令数据。
参数名 | 类型 | 描述 |
---|---|---|
options | SendCommandData | 入参类型 |
# SendCommandData类型:
参数名 | 类型 | 描述 |
---|---|---|
command | string | 指令字符 |
# 返回值
无
native.sendCommandData({
command: 'test'
});